X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/1fdf24331346d3b0765cdf9061199aa8bd905bc5..72dfc92f908add69b4d862e9b6c3107e2a8acd21:/modules/documentCanvas/canvas/documentElement.js diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 8a50d23..82a85c7 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -19,7 +19,10 @@ $.extend(DocumentElement.prototype, { return this.$element; }, parent: function() { - return documentElementFromHTMLElement(this.$element.parent()[0], this.canvas); + var parents = this.$element.parents('[wlxml-tag]'); + if(parents.length) + return documentElementFromHTMLElement(parents[0], this.canvas); + return null; }, sameNode: function(other) { @@ -196,9 +199,26 @@ $.extend(DocumentTextElement.prototype, { } }, unwrap: function() { - if(this.parent().children().length === 1) { - var parent = this.parent(); - parent.after(this); + var parent = this.parent(); + if(parent.children().length === 1) { + var grandParent = parent.parent(); + if(grandParent) { + var grandParentChildren = grandParent.children(), + idx = grandParent.childIndex(parent), + prev = idx - 1 > -1 ? grandParentChildren[idx-1] : null, + next = idx + 1 < grandParentChildren.length ? grandParentChildren[idx+1] : null; + if(prev && next) { + prev.setText(prev.getText() + this.getText() + next.getText()); + next.detach(); + } else if (prev || next) { + var target = prev ? prev : next; + target.setText(target.getText() + this.getText()); + } else { + parent.after(this); + } + } else { + parent.after(this); + } parent.detach(); } },