return;
}
+ // Both edge text nodes need to be edited before anything else happen in case that
+ // they get merged when detaching content between them.
+ params.from.node.setText(params.from.node.getText().substr(0, params.from.offset));
+ params.to.node.setText(params.to.node.getText().substr(params.to.offset));
+
ptr = params.from.node;
- ptr.setText(ptr.getText().substr(0, params.from.offset));
next = ptr.next();
+
while(next || ptr.parent()) {
if(next) {
if(next.sameNode(params.to.node) || (next.nodeType === Node.ELEMENT_NODE && next.containsNode(params.to.node))) {
}
ptr = params.to.node;
- ptr.setText(ptr.getText().substr(params.to.offset));
+
+ if(!this.containsNode(ptr)) {
+ // The end node was merged during detaching nodes above - there is nothing more left to do.
+ return;
+ }
prev = ptr.prev();
while(prev || ptr.parent()) {
if(ptr.sameNode(middle)) {
expect(bContents[0].contents().length).to.equal(1);
expect(bContents[0].contents()[0].getText()).to.equal('cc');
});
+ it('remove across elements - 3 (merged text nodes)', function() {
+ var doc = getDocumentFromXML('<div>Alice <span>has</span> a cat</div>');
+ doc.deleteText({
+ from: {
+ node: getTextNode('Alice ', doc),
+ offset: 1
+ },
+ to: {
+ node: getTextNode(' a cat', doc),
+ offset: 3
+ }
+ });
+ var contents = doc.root.contents();
+ expect(contents.length).to.equal(1);
+ expect(contents[0].getText()).to.equal('Acat');
+ });
it('removes nodes in between', function() {
var doc = getDocumentFromXML('<div><a>aaa<x>!</x></a>xxx<x></x><b><x>!</x>bbb</b></div>');
doc.deleteText({