From: Aleksander Ɓukasz Date: Tue, 19 Nov 2013 16:07:56 +0000 (+0100) Subject: smartxml: refactoring X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/7ceaca87e48317ad610b946192e0783885696f0d?ds=sidebyside;hp=06ff71dcb6c913a66280ebf812481224ee461f8c smartxml: refactoring --- diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 05583c5..1d9fdd0 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -253,8 +253,7 @@ $.extend(ElementNode.prototype, { return; } - var parentContents = parent.contents(), - myContents = this.contents(), + var myContents = this.contents(), myIdx = parent.indexOf(this); @@ -262,10 +261,12 @@ $.extend(ElementNode.prototype, { return this.detach(); } - var moveLeftRange, moveRightRange, leftMerged; + var prev = this.prev(), + next = this.next(), + moveLeftRange, moveRightRange, leftMerged; - if(myIdx > 0 && (parentContents[myIdx-1].nodeType === TEXT_NODE) && (myContents[0].nodeType === TEXT_NODE)) { - parentContents[myIdx-1].appendText(myContents[0].getText()); + if(prev && (prev.nodeType === TEXT_NODE) && (myContents[0].nodeType === TEXT_NODE)) { + prev.appendText(myContents[0].getText()); myContents[0].detach(); moveLeftRange = true; leftMerged = true; @@ -274,9 +275,10 @@ $.extend(ElementNode.prototype, { } if(!(leftMerged && myContents.length === 1)) { - if(myIdx < parentContents.length - 1 && (parentContents[myIdx+1].nodeType === TEXT_NODE) && (myContents[myContents.length-1].nodeType === TEXT_NODE)) { - parentContents[myIdx+1].prependText(myContents[myContents.length-1].getText()); - myContents[myContents.length-1].detach(); + var lastContents = _.last(myContents); + if(next && (next.nodeType === TEXT_NODE) && (lastContents.nodeType === TEXT_NODE)) { + next.prependText(lastContents.getText()); + lastContents.detach(); moveRightRange = true; } }