From: Aleksander Ɓukasz Date: Wed, 12 Mar 2014 16:00:30 +0000 (+0100) Subject: editor: fix selecting text spanning multiple nodes in Chrome X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/41bcc758201d42b62e7a6fdd9b85c8294e14d482?hp=49906096d20853e8ce794225e7ce14147bf112ec editor: fix selecting text spanning multiple nodes in Chrome 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. --- diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index 428cedc..d8d81b8 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -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}); + } } });