X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/5c99e408dd09e416fbec9c3535803e7d17bdaf44..45bebc5c454ced236db27631004cc2628260f3c9:/src/editor/modules/documentCanvas/canvas/canvas.js diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index 6f648ec..0259452 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -12,8 +12,9 @@ define([ 'modules/documentCanvas/canvas/nullElement', 'modules/documentCanvas/canvas/gutter', 'modules/documentCanvas/canvas/selection', +'modules/documentCanvas/canvas/keyEvent', 'libs/text!./canvas.html' -], function($, _, Backbone, logging, documentElement, keyboard, utils, wlxmlListener, ElementsRegister, genericElement, nullElement, gutter, selection, canvasTemplate) { +], function($, _, Backbone, logging, documentElement, keyboard, utils, wlxmlListener, ElementsRegister, genericElement, nullElement, gutter, selection, keyEvent, canvasTemplate) { 'use strict'; /* global document:false, window:false, Node:false, gettext */ @@ -146,15 +147,20 @@ $.extend(Canvas.prototype, Backbone.Events, { this.rootWrapper.append(this.rootElement.dom); }, + + triggerKeyEvent: function(keyEvent, selection) { + selection = selection || this.getSelection(); + if(selection && (selection.type === 'caret' || selection.type === 'textSelection') && selection.toDocumentFragment().isValid()) { + keyboard.handleKeyEvent(keyEvent, selection); + } + }, + setupEventHandling: function() { var canvas = this; /* globals document */ $(document.body).on('keydown', function(e) { - var cursor = canvas.getCursor(); - if(cursor.isSelecting() || Object.keys(cursor.getPosition()).length) { - keyboard.handleKey(e, canvas); - } + canvas.triggerKeyEvent(keyEvent.fromNativeEvent(e)); }); this.rootWrapper.on('mouseup', function() { @@ -350,6 +356,13 @@ $.extend(Canvas.prototype, Backbone.Events, { } }, + setSelection: function(selection) { + this.select(this, selection.toDocumentFragment()); + }, + + createSelection: function(params) { + return selection.fromParams(this, params); + }, setCurrentElement: function(element, params) { if(!element) { logger.debug('Invalid element passed to setCurrentElement: ' + element);