From f0c9be9018a20f7325bdd5efbbf951f1a0fd5699 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 28 Jul 2014 15:26:33 +0200 Subject: [PATCH] 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. --- src/editor/modules/documentCanvas/canvas/canvas.js | 8 ++++++-- src/editor/modules/documentCanvas/canvas/keyboard.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) 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(); -- 2.20.1