From: Aleksander Ɓukasz Date: Fri, 9 May 2014 14:12:27 +0000 (+0200) Subject: editor: canvas - stop using thrown away nodeMoved event, use 'move' flag instead X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/edaa08a1858371fbdd9665a0220cb1b9732dd2dc?ds=inline editor: canvas - stop using thrown away nodeMoved event, use 'move' flag instead This approach always rerenders text nodes... --- diff --git a/src/editor/modules/documentCanvas/canvas/genericElement.js b/src/editor/modules/documentCanvas/canvas/genericElement.js index a2601f8..44615f5 100644 --- a/src/editor/modules/documentCanvas/canvas/genericElement.js +++ b/src/editor/modules/documentCanvas/canvas/genericElement.js @@ -103,20 +103,19 @@ $.extend(generic, { referenceAction = 'after'; } - if(event.type === 'nodeMoved') { - actionArg = utils.getElementForNode(event.meta.node, event.meta.parent); - if(actionArg.sameNode(referenceElement)) { + if(event.meta.move) { + /* Let's check if this node had its own canvas element and it's accessible. */ + actionArg = utils.getElementForElementRootNode(event.meta.node); + if(actionArg && actionArg.sameNode(referenceElement)) { referenceElement = this.children()[nodeIndex]; } - } else { + } + if(!actionArg) { actionArg = event.meta.node; } referenceElement[referenceAction](actionArg); }, - onNodeMoved: function(event) { - return this.onNodeAdded.call(this, event); - }, onNodeDetached: function(event) { if(event.meta.node.sameNode(this)) { this.detach(); diff --git a/src/editor/modules/documentCanvas/canvas/utils.js b/src/editor/modules/documentCanvas/canvas/utils.js index 130d51c..1df3f82 100644 --- a/src/editor/modules/documentCanvas/canvas/utils.js +++ b/src/editor/modules/documentCanvas/canvas/utils.js @@ -20,6 +20,24 @@ var nearestInDocumentOrder = function(selector, direction, element) { return null; }; +var getElementForElementRootNode = function(node, withParent) { + if(node.nodeType === Node.TEXT_NODE) { + return _getElementForRootTextNode(node, withParent); + } + return node.getData('canvasElement'); +}; + +var _getElementForRootTextNode = function(textNode, withParent) { + var parentElement = getElementForNode(withParent || textNode.parent()), + toret; + parentElement.children().some(function(child) { + if(child.wlxmlNode.sameNode(textNode)) { + toret = child; + return true; + } + }); + return toret; +}; var getElementForNode = function(node, withParent) { if(node.nodeType === Node.TEXT_NODE) { @@ -62,7 +80,8 @@ return { ZWS: '\u200B' }, getElementForNode: getElementForNode, - getElementForDetachedNode: getElementForDetachedNode + getElementForDetachedNode: getElementForDetachedNode, + getElementForElementRootNode: getElementForElementRootNode }; }); diff --git a/src/editor/modules/documentCanvas/canvas/wlxmlListener.js b/src/editor/modules/documentCanvas/canvas/wlxmlListener.js index 760208f..02dc657 100644 --- a/src/editor/modules/documentCanvas/canvas/wlxmlListener.js +++ b/src/editor/modules/documentCanvas/canvas/wlxmlListener.js @@ -69,10 +69,6 @@ var handlers = { containingElement.handle(event); }, - nodeMoved: function(event) { - return handlers.nodeAdded.call(this, event); // - // - }, nodeDetached: function(event) { var element = utils.getElementForDetachedNode(event.meta.node, event.meta.parent); element.handle(event);