X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/21cd91531dd9c6e88d00da03f6b2f3ad88fb0da0..d5f4c1bb0dc3a9ff8845d209c75d00cc733b3360:/src/smartxml/core.js diff --git a/src/smartxml/core.js b/src/smartxml/core.js index 40fd9b8..4d3c2c1 100644 --- a/src/smartxml/core.js +++ b/src/smartxml/core.js @@ -99,6 +99,8 @@ var elementNodeTransformations = { if(this.sameNode(this.document.root)) { this.document._defineDocumentProperties(node._$); } + + /* TODO: This invalidates old references to this node. Caching instances on nodes would fix this. */ this._$.replaceWith(node._$); this._setNativeNode(node._$[0]); this._$.append(myContents); @@ -186,9 +188,15 @@ var elementNodeTransformations = { }; var textNodeTransformations = { - setText: function(text) { - this.nativeNode.data = text; - this.triggerTextChangeEvent(); + setText: { + impl: function(t, text) { + t.oldText = this.getText(); + this.nativeNode.data = text; + this.triggerTextChangeEvent(); + }, + undo: function(t) { + this.setText(t.oldText); + } }, appendText: function(text) { @@ -251,6 +259,27 @@ var textNodeTransformations = { }); return {first: parentElement, second: newElement}; + }, + + divideWithElementNode: function(node, params) { + var insertion = this.getNodeInsertion(node), + myText = this.getText(); + + if(params.offset === myText.length) { + return this.after(node); + } + if(params.offset === 0) { + return this.before(node); + } + + var lhsText = myText.substr(0, params.offset), + rhsText = myText.substr(params.offset), + rhsTextNode = this.document.createDocumentNode({text: rhsText}); + + this.setText(lhsText); + this.after(insertion.ofNode); + insertion.ofNode.after(rhsTextNode); + return insertion.ofNode; } };