editor: fix selecting text spanning multiple nodes in Chrome
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 12 Mar 2014 16:00:30 +0000 (17:00 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 12 Mar 2014 16:00:30 +0000 (17:00 +0100)
Chrome 33 started triggering click events for a nearest common parent
when mousedown occurred on a different element than mouseup. This
was causing selecting single canvas node element when making text
selection across nodes and consequently removing that selection.

src/editor/modules/documentCanvas/canvas/canvas.js

index 428cedc..d8d81b8 100644 (file)
@@ -89,13 +89,20 @@ $.extend(Canvas.prototype, {
             keyboard.handleKey(e, this);
         }.bind(this));
 
+        var mouseDown;
+        this.wrapper.on('mousedown', '[document-node-element], [document-text-element]', function(e) {
+            mouseDown = e.target;
+        });
+
         this.wrapper.on('click', '[document-node-element], [document-text-element]', function(e) {
             e.stopPropagation();
             if(e.originalEvent.detail === 3) {
                 e.preventDefault();
                 canvas._moveCaretToTextElement(canvas.getDocumentElement(e.currentTarget), 'whole');
             } else {
-                canvas.setCurrentElement(canvas.getDocumentElement(e.currentTarget), {caretTo: false});
+                if(mouseDown === e.target) {
+                    canvas.setCurrentElement(canvas.getDocumentElement(e.currentTarget), {caretTo: false});
+                }
             }
         });