From: Aleksander Ɓukasz Date: Wed, 14 Aug 2013 07:54:49 +0000 (+0200) Subject: Refactoring X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/fe38f435c3602a2259e36b11f6faf1f99272e52b?ds=inline Refactoring --- diff --git a/modules/documentCanvas/canvas/canvas.js b/modules/documentCanvas/canvas/canvas.js index c7e2781..1efd687 100644 --- a/modules/documentCanvas/canvas/canvas.js +++ b/modules/documentCanvas/canvas/canvas.js @@ -191,8 +191,7 @@ $.extend(Canvas.prototype, { 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()); } }) diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 0558a3e..b7e8352 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -101,6 +101,20 @@ $.extend(DocumentElement.prototype, { 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'; }, diff --git a/modules/documentCanvas/canvas/keyboard.js b/modules/documentCanvas/canvas/keyboard.js index 3ce1871..1830017 100644 --- a/modules/documentCanvas/canvas/keyboard.js +++ b/modules/documentCanvas/canvas/keyboard.js @@ -173,11 +173,11 @@ handlers.push({keys: [KEYS.BACKSPACE, KEYS.DELETE], 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});