From: Aleksander Ɓukasz Date: Mon, 26 May 2014 14:20:20 +0000 (+0200) Subject: editor: fixing handling nodeTextChange on text nodes belonging to custom-rendered... X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/7c4c5ee807a9700c1b26e91f0d1720e3c6fd9ec3?ds=sidebyside;hp=a1337ec35d99fc246d98bc67b80d5bfad44282d4 editor: fixing handling nodeTextChange on text nodes belonging to custom-rendered parent --- diff --git a/src/editor/modules/documentCanvas/canvas/canvas.test.js b/src/editor/modules/documentCanvas/canvas/canvas.test.js index 0654170..be4a8b9 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.test.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.test.js @@ -293,7 +293,11 @@ describe('Custom elements based on wlxml class attribute', function() { onNodeAdded: function(event) { void(event); this.refresh2(); - } + }, + onNodeTextChange: function(event) { + this.header.text(event.meta.node.getText()); + }, + children: function() { return []; } }); var c = getCanvasFromXML('
', [ @@ -309,6 +313,14 @@ describe('Custom elements based on wlxml class attribute', function() { node.append({tagName: 'div'}); expect(header.text()).to.equal('2', 'added div'); + + var textNode = node.append({text: 'test'}); + + expect(header.text()).to.equal('3', 'added text node'); + + textNode.setText('test2'); + + expect(header.text()).to.equal('test2', 'text node change handled'); }); describe('Handling unknown class', function() { diff --git a/src/editor/modules/documentCanvas/canvas/documentElement.js b/src/editor/modules/documentCanvas/canvas/documentElement.js index 948e8df..99a12f5 100644 --- a/src/editor/modules/documentCanvas/canvas/documentElement.js +++ b/src/editor/modules/documentCanvas/canvas/documentElement.js @@ -226,6 +226,9 @@ $.extend(DocumentTextElement.prototype, { this.dom.contents()[0].data = text; } }, + handle: function(event) { + this.setText(event.meta.node.getText()); + }, getText: function(options) { options = _.extend({raw: false}, options || {}); var toret = this.dom.text(); diff --git a/src/editor/modules/documentCanvas/canvas/utils.js b/src/editor/modules/documentCanvas/canvas/utils.js index 1df3f82..4e262a0 100644 --- a/src/editor/modules/documentCanvas/canvas/utils.js +++ b/src/editor/modules/documentCanvas/canvas/utils.js @@ -58,7 +58,7 @@ var _getElementForTextNode = function(textNode, withParent) { return true; } }); - return toret; + return toret || parentElement; }; var getElementForDetachedNode = function(node, originalParent) { diff --git a/src/editor/modules/documentCanvas/canvas/wlxmlListener.js b/src/editor/modules/documentCanvas/canvas/wlxmlListener.js index 02dc657..d107612 100644 --- a/src/editor/modules/documentCanvas/canvas/wlxmlListener.js +++ b/src/editor/modules/documentCanvas/canvas/wlxmlListener.js @@ -75,7 +75,7 @@ var handlers = { }, nodeTextChange: function(event) { var element = utils.getElementForNode(event.meta.node); - element.setText(event.meta.node.getText()); + element.handle(event); }, metadataChanged: _metadataEventHandler,