From: Aleksander Ɓukasz Date: Tue, 19 Nov 2013 16:10:31 +0000 (+0100) Subject: smartxml: refactor X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/98b0bc99617ca0f8cc6354aa91306f6437e3eb4d?ds=inline;hp=7ceaca87e48317ad610b946192e0783885696f0d smartxml: refactor --- diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 1d9fdd0..637fda6 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -82,6 +82,12 @@ $.extend(DocumentNode.prototype, { return myIdx < parentContents.length - 1 ? parentContents[myIdx+1] : null; }, + isSurroundedByTextElements: function() { + var prev = this.prev(), + next = this.next(); + return prev && (prev.nodeType === Node.TEXT_NODE) && next && (next.nodeType === Node.TEXT_NODE); + }, + after: INSERTION(function(nativeNode) { return this._$.after(nativeNode); }), @@ -151,13 +157,11 @@ $.extend(ElementNode.prototype, { nodeType: Node.ELEMENT_NODE, detach: function() { - var prev = this.prev(), + var next; + if(parent && this.isSurroundedByTextElements()) { next = this.next(); - if(parent) { - if(prev && prev.nodeType === Node.TEXT_NODE && next && next.nodeType === Node.TEXT_NODE) { - prev.appendText(next.getText()); - next.detach(); - } + this.prev().appendText(next.getText()); + next.detach(); } return DocumentNode.prototype.detach.call(this); },