From: Aleksander Ɓukasz Date: Mon, 30 Jun 2014 12:49:15 +0000 (+0200) Subject: smartxml: fix for Document.deleteText X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/a0ea5d8b3f8045f428a032df8cacde0ed54172ab?ds=inline smartxml: fix for Document.deleteText --- diff --git a/src/smartxml/core.js b/src/smartxml/core.js index b40e9c3..f907a20 100644 --- a/src/smartxml/core.js +++ b/src/smartxml/core.js @@ -474,7 +474,7 @@ var documentTransformations = { return insertion.ofNode; }, deleteText: function(params) { - var ptr, next, toDetach, middle, text; + var ptr, next, nextNext, toDetach, middle, text; if(params.from.node.sameNode(params.to.node)) { ptr = params.from.node; @@ -502,7 +502,11 @@ var documentTransformations = { } else { toDetach = next; next = next.next(); - toDetach.detach(); + nextNext = next ? next.next() : null; + toDetach.detach({normalizeStrategy: (next && next.sameNode(params.to.node)) ? 'merge' : 'detach-right'}); + if(next && !next.isInDocument()) { + next = nextNext; + } } } else { ptr = ptr.parent(); diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index b50da7f..ce0d98a 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -942,6 +942,28 @@ describe('smartxml', function() { expect(contents[1].contents().length).to.equal(1); expect(contents[1].contents()[0].getText()).to.equal('b'); }); + it('removes across elements - 6', function() { + var doc = getDocumentFromXML('
aaabbbccc
ddd
'); + doc.deleteText({ + from: { + node: getTextNode('aaa', doc), + offset: 1 + }, + to: { + node: getTextNode('ddd', doc), + offset: 1 + } + }, { + error: function(e) {throw e;} + }); + + var contents = doc.root.contents(); + expect(contents.length).to.equal(2); + expect(contents[0].contents().length).to.equal(1); + expect(contents[0].contents()[0].getText()).to.equal('a'); + expect(contents[1].contents().length).to.equal(1); + expect(contents[1].contents()[0].getText()).to.equal('dd'); + }); }); describe('Splitting text', function() {