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());
}
})
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';
},
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 {
- goto = canvas.getDocumentElement(utils.nearestInDocumentOrder('[document-text-element]:visible', direction, element.dom()[0]));
+ goto = element.getNearestTextElement(direction);
element.detach();
}
canvas.setCurrentElement(goto, {caretTo: caretTo});