X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/94e78db871e2d12a5698fced12f656dac563869f..af57fe565c8a5d6fc36ea5c3dc83065f69534b04:/src/smartxml/fragments.js?ds=inline diff --git a/src/smartxml/fragments.js b/src/smartxml/fragments.js index 62a7a4c..f15a9e8 100644 --- a/src/smartxml/fragments.js +++ b/src/smartxml/fragments.js @@ -19,7 +19,7 @@ $.extend(Fragment.prototype, { var NodeFragment = function(document, params) { Fragment.call(this, document); this.node = params.node; - this.nodePath = params.node.getPath(); + this.nodePath = this.isValid() ? params.node.getPath() : null; }; NodeFragment.prototype = Object.create(Fragment.prototype); $.extend(NodeFragment.prototype, { @@ -27,14 +27,16 @@ $.extend(NodeFragment.prototype, { return this.document.containsNode(this.node); }, restoreFromPaths: function() { - this.node = this.document.getNodeByPath(this.nodePath); + if(this.nodePath) { + this.node = this.document.getNodeByPath(this.nodePath); + } } }); var CaretFragment = function(document, params) { - NodeFragment.call(this, document, params); this.offset = params.offset; + NodeFragment.call(this, document, params); }; CaretFragment.prototype = Object.create(NodeFragment.prototype); @@ -74,17 +76,20 @@ $.extend(RangeFragment.prototype, { this.startNode = this.document.getNodeByPath(this.startNodePath); this.endNode = this.document.getNodeByPath(this.endNodePath); }, - hasSiblingBoundries: function() { + hasSiblingBoundaries: function() { return this.isValid() && this.startNode.isSiblingOf(this.endNode); }, - boundriesSiblingParents: function() { + hasSameBoundaries: function() { + return this.isValid() && this.startNode.sameNode(this.endNode); + }, + boundariesSiblingParents: function() { return this.startNode.document.getSiblingParents({ node1: this.startNode, node2: this.endNode }); }, getCommonParent: function() { - var siblingParents = this.boundriesSiblingParents(); + var siblingParents = this.boundariesSiblingParents(); if(siblingParents) { return siblingParents.node1.parent(); }