Refactoring
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 14 Aug 2013 07:54:49 +0000 (09:54 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 14 Aug 2013 07:54:49 +0000 (09:54 +0200)
modules/documentCanvas/canvas/canvas.js
modules/documentCanvas/canvas/documentElement.js
modules/documentCanvas/canvas/keyboard.js

index c7e2781..1efd687 100644 (file)
@@ -191,8 +191,7 @@ $.extend(Canvas.prototype, {
 
             this.eventBus.on('elementToggled', function(toggle, element) {
                 if(!toggle) {
 
             this.eventBus.on('elementToggled', function(toggle, element) {
                 if(!toggle) {
-                    element = canvas.getDocumentElement(utils.nearestInDocumentOrder('[document-text-element]:visible', 'above', element.dom()[0]));
-                    canvas.setCurrentElement(element);
+                    canvas.setCurrentElement(element.getPreviousTextElement());
                 }
             })
 
                 }
             })
 
index 0558a3e..b7e8352 100644 (file)
@@ -101,6 +101,20 @@ $.extend(DocumentElement.prototype, {
         return toret;
     },
 
         return toret;
     },
 
+    getPreviousTextElement: function(includeInvisible) {
+        return this.getNearestTextElement('above', includeInvisible);
+    },
+
+    getNextTextElement: function(includeInvisible) {
+        return this.getNearestTextElement('below', includeInvisible);
+    },
+
+    getNearestTextElement: function(direction, includeInvisible) {
+        includeInvisible = includeInvisible !== undefined ? includeInvisible : false;
+        var selector = '[document-text-element]' + (includeInvisible ? '' : ':visible');
+        return this.canvas.getDocumentElement(utils.nearestInDocumentOrder(selector, direction, this.dom()[0]));
+    },
+
     isVisible: function() {
         return this instanceof DocumentTextElement || this.getWlxmlTag() !== 'metadata';
     },
     isVisible: function() {
         return this instanceof DocumentTextElement || this.getWlxmlTag() !== 'metadata';
     },
index 3ce1871..1830017 100644 (file)
@@ -173,11 +173,11 @@ handlers.push({keys: [KEYS.BACKSPACE, KEYS.DELETE],
                 if(grandParent && grandParent.children().length === 1) {
                     goto = grandParent.append({text: ''});
                 } else {
                 if(grandParent && grandParent.children().length === 1) {
                     goto = grandParent.append({text: ''});
                 } else {
-                    goto = canvas.getDocumentElement(utils.nearestInDocumentOrder('[document-text-element]:visible', direction, element.dom()[0]));
+                    goto = element.getNearestTextElement(direction);
                 }
                 parent.detach();
             } else {
                 }
                 parent.detach();
             } else {
-                goto = canvas.getDocumentElement(utils.nearestInDocumentOrder('[document-text-element]:visible', direction, element.dom()[0]));
+                goto = element.getNearestTextElement(direction);
                 element.detach();
             }
             canvas.setCurrentElement(goto, {caretTo: caretTo});
                 element.detach();
             }
             canvas.setCurrentElement(goto, {caretTo: caretTo});