From: Aleksander Ɓukasz Date: Mon, 28 Jul 2014 13:26:33 +0000 (+0200) Subject: editor: canvas fix - restore deleting selected text X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/f0c9be9018a20f7325bdd5efbbf951f1a0fd5699 editor: canvas fix - restore deleting selected text - Canvas.rootWrapper is no longer a contenteditable so key events need to be listened to on the document body in case there is no caret on a canvas (e.g. when selection is made). - During selection, even inside a single text element, contenteditable is not used, meaning that during even for such a selection we need to handle delete/backspace ourselves. --- diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index 2f25cb3..c964779 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -148,8 +148,12 @@ $.extend(Canvas.prototype, Backbone.Events, { setupEventHandling: function() { var canvas = this; - this.rootWrapper.on('keyup keydown keypress', function(e) { - keyboard.handleKey(e, canvas); + /* globals document */ + $(document.body).on('keydown', function(e) { + var cursor = canvas.getCursor(); + if(cursor.isSelecting() || Object.keys(cursor.getPosition()).length) { + keyboard.handleKey(e, canvas); + } }); this.rootWrapper.on('mouseup', function() { diff --git a/src/editor/modules/documentCanvas/canvas/keyboard.js b/src/editor/modules/documentCanvas/canvas/keyboard.js index eafd091..9f58066 100644 --- a/src/editor/modules/documentCanvas/canvas/keyboard.js +++ b/src/editor/modules/documentCanvas/canvas/keyboard.js @@ -306,7 +306,7 @@ handlers.push({keys: [KEYS.BACKSPACE, KEYS.DELETE], caretTo = 'start'; } - if(cursor.isSelecting() && !cursor.isSelectingWithinElement()) { + if(cursor.isSelecting()) { event.preventDefault(); var start = cursor.getSelectionStart(), end = cursor.getSelectionEnd();