From: Aleksander Ɓukasz Date: Mon, 30 Jun 2014 12:47:57 +0000 (+0200) Subject: smartxml: additional text nodes merge strategies for ElementNode.detach X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/cef69fff5322bdc7766d7063809694f6ee0e9e47 smartxml: additional text nodes merge strategies for ElementNode.detach --- diff --git a/src/smartxml/core.js b/src/smartxml/core.js index 7118584..b40e9c3 100644 --- a/src/smartxml/core.js +++ b/src/smartxml/core.js @@ -120,12 +120,24 @@ var documentNodeTransformations = { var elementNodeTransformations = { - detach: function() { + detach: function(params) { var next; + params = _.extend({ + normalizeStrategy: 'merge' + }, params); + if(this.parent() && this.isSurroundedByTextNodes()) { - next = this.next(); - this.prev().appendText(next.getText()); - next.detach(); + if(params.normalizeStrategy === 'detach-left') { + this.prev().detach(); + } else if(params.normalizeStrategy === 'detach-right') { + this.next().detach(); + } else if(params.normalizeStrategy === 'merge') { + next = this.next(); + this.prev().appendText(next.getText()); + next.detach(); + } else { + throw new Error('unknown normalize strategy for detach'); + } } return this.__super__.detach(); },