X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/9968c4c2c8e89849e3a52babde85709c9ef08ad2..cd106525cca6355309617b7a7092bd58cb9d8ce8:/src/smartxml/core.js?ds=inline diff --git a/src/smartxml/core.js b/src/smartxml/core.js index 4297c1a..44be8d6 100644 --- a/src/smartxml/core.js +++ b/src/smartxml/core.js @@ -240,6 +240,21 @@ var textNodeTransformations = { } }), + append: function(node) { + if(node.nodeType === Node.TEXT_NODE) { + this.appendText(node.getText()); + node.detach(); + return this; + } + }, + prepend: function(node) { + if(node.nodeType === Node.TEXT_NODE) { + this.prependText(node.getText()); + node.detach(); + return this; + } + }, + appendText: function(text) { this.nativeNode.data = this.nativeNode.data + text; this.triggerTextChangeEvent(); @@ -416,6 +431,52 @@ var documentTransformations = { this._defineDocumentProperties(insertion.ofNode._$); insertion.ofNode.triggerChangeEvent('nodeAdded'); return insertion.ofNode; + }, + deleteText: function(params) { + var ptr, prev, next, toDetach, middle, text; + + if(params.from.node.sameNode(params.to.node)) { + ptr = params.from.node; + text = ptr.getText(); + ptr.setText(text.substr(0, params.from.offset) + text.substr(params.to.offset)); + return; + } + + 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))) { + middle = next; + break; + } else { + toDetach = next; + next = next.next(); + toDetach.detach(); + } + } else { + ptr = ptr.parent(); + next = ptr.next(); + } + } + + ptr = params.to.node; + ptr.setText(ptr.getText().substr(params.to.offset)); + prev = ptr.prev(); + while(prev || ptr.parent()) { + if(ptr.sameNode(middle)) { + break; + } + if(prev) { + toDetach = prev; + prev = prev.prev(); + toDetach.detach(); + } else { + ptr = ptr.parent(); + prev = ptr.prev(); + } + } } };