editor: canvas fix - restore deleting selected text
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 28 Jul 2014 13:26:33 +0000 (15:26 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 14 Aug 2014 14:01:45 +0000 (16:01 +0200)
- 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
src/editor/modules/documentCanvas/canvas/keyboard.js

index 2f25cb3..c964779 100644 (file)
@@ -148,8 +148,12 @@ $.extend(Canvas.prototype, Backbone.Events, {
     setupEventHandling: function() {
         var canvas = this;
 
     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() {
         });
 
         this.rootWrapper.on('mouseup', function() {
index eafd091..9f58066 100644 (file)
@@ -306,7 +306,7 @@ handlers.push({keys: [KEYS.BACKSPACE, KEYS.DELETE],
             caretTo = 'start';
         }
 
             caretTo = 'start';
         }
 
-        if(cursor.isSelecting() && !cursor.isSelectingWithinElement()) {
+        if(cursor.isSelecting()) {
             event.preventDefault();
             var start = cursor.getSelectionStart(),
                 end = cursor.getSelectionEnd();
             event.preventDefault();
             var start = cursor.getSelectionStart(),
                 end = cursor.getSelectionEnd();