X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/df1aaa5ae8434788bb67662782fe7e5324ac9786..898f8bf5c4bf5e553994ee7d7cf320fcc0d1bc12:/src/smartxml/smartxml.test.js diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index 140174e..7b42580 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -738,6 +738,58 @@ describe('smartxml', function() { 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('
Alice has a cat
'); + 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('remove across elements - 4', function() { + var doc = getDocumentFromXML('
Alice
has a cat
'); + doc.deleteText({ + from: { + node: getTextNode('Alice ', doc), + offset: 1 + }, + to: { + node: getTextNode(' cat', doc), + offset: 1 + } + }); + var contents = doc.root.contents(); + expect(contents.length).to.equal(2); + expect(contents[0].getText()).to.equal('A'); + expect(contents[1].getTagName()).to.equal('div'); + expect(contents[1].contents().length).to.equal(1); + expect(contents[1].contents()[0].getText()).to.equal('cat'); + }); + it('removes across elements - 5 (whole document)', function() { + var doc = getDocumentFromXML('
Alice
has a cat
!!!
'); + doc.deleteText({ + from: { + node: getTextNode('Alice ', doc), + offset: 0 + }, + to: { + node: getTextNode('!!!', doc), + offset: 3 + } + }); + + expect(doc.root.getTagName()).to.equal('div'); + expect(doc.root.contents().length).to.equal(1); + expect(doc.root.contents()[0].getText()).to.equal(''); + }); it('removes nodes in between', function() { var doc = getDocumentFromXML('
aaa!xxx!bbb
'); doc.deleteText({ @@ -1540,6 +1592,34 @@ describe('smartxml', function() { expect(doc.root.getAttr('unaware')).to.equal('1'); }); }); + + describe('Regression tests', function() { + it('redos correctly after running its own undo followed by unaware transformation undo', function() { + var doc = getDocumentFromXML('
'); + + doc.registerExtension({elementNode: {transformations: { + unaware: function() { + this.triggerChangeEvent(); + }, + test: { + impl: function() { + this._$.attr('t', 1); + this.triggerChangeEvent(); + }, + undo: function() { + this._$.attr('t', 0); + } + } + }}}); + doc.root.unaware(); + doc.root.test(); + doc.undo(); + doc.undo(); + doc.redo(); + doc.redo(); + expect(doc.root.getAttr('t')).to.equal('1'); + }); + }); }); });