editor: fix - bring back ability to select elements without text
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 25 Jul 2014 09:16:10 +0000 (11:16 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 14 Aug 2014 14:01:45 +0000 (16:01 +0200)
src/editor/modules/documentCanvas/canvas/canvas.js

index 08df11f..2f25cb3 100644 (file)
@@ -163,13 +163,20 @@ $.extend(Canvas.prototype, Backbone.Events, {
         });
 
         this.rootWrapper.on('click', '[document-node-element], [document-text-element]', function(e) {
         });
 
         this.rootWrapper.on('click', '[document-node-element], [document-text-element]', function(e) {
-            var position;
+            var position, element;
             e.stopPropagation();
             if(e.originalEvent.detail === 3) {
                 e.preventDefault();
                 canvas._moveCaretToTextElement(canvas.getDocumentElement(e.currentTarget), 'whole');
             } else {
                 if(mouseDown === e.target) {
             e.stopPropagation();
             if(e.originalEvent.detail === 3) {
                 e.preventDefault();
                 canvas._moveCaretToTextElement(canvas.getDocumentElement(e.currentTarget), 'whole');
             } else {
                 if(mouseDown === e.target) {
+                    element = canvas.getDocumentElement(e.target);
+                    if(element && element.wlxmlNode.nodeType === Node.ELEMENT_NODE) {
+                        if(element.getVerticallyFirstTextElement && !element.getVerticallyFirstTextElement({considerChildren: false})) {
+                            canvas.setCurrentElement(element);
+                            return;
+                        }
+                    }
                     if(window.getSelection().isCollapsed) {
                         position = utils.caretPositionFromPoint(e.clientX, e.clientY);
                         canvas.setCurrentElement(canvas.getDocumentElement(position.textNode), {caretTo: position.offset});
                     if(window.getSelection().isCollapsed) {
                         position = utils.caretPositionFromPoint(e.clientX, e.clientY);
                         canvas.setCurrentElement(canvas.getDocumentElement(position.textNode), {caretTo: position.offset});