fix: canvas again gets opportunity to react to footnote being closed
[fnpeditor.git] / src / editor / modules / documentCanvas / canvas / canvas.js
index 0ec22a1..a43799c 100644 (file)
@@ -233,7 +233,7 @@ $.extend(Canvas.prototype, Backbone.Events, {
 
         this.eventBus.on('elementToggled', function(toggle, element) {
             if(!toggle) {
-                canvas.setCurrentElement(element.getPreviousTextElement());
+                canvas.setCurrentElement(canvas.getPreviousTextElement(element));
             }
         });
     },
@@ -270,6 +270,20 @@ $.extend(Canvas.prototype, Backbone.Events, {
         }
     },
 
+    getPreviousTextElement: function(relativeToElement, includeInvisible) {
+        return this.getNearestTextElement('above', relativeToElement, includeInvisible);
+    },
+
+    getNextTextElement: function(relativeToElement, includeInvisible) {
+        return this.getNearestTextElement('below', relativeToElement, includeInvisible);
+    },
+
+    getNearestTextElement: function(direction, relativeToElement, includeInvisible) {
+        includeInvisible = includeInvisible !== undefined ? includeInvisible : false;
+        var selector = '[document-text-element]' + (includeInvisible ? '' : ':visible');
+        return this.getDocumentElement(utils.nearestInDocumentOrder(selector, direction, relativeToElement.dom()[0]));
+    },
+
     contains: function(element) {
         return element.dom().parents().index(this.wrapper) !== -1;
     },