From: Aleksander Ɓukasz Date: Mon, 24 Jun 2013 15:03:39 +0000 (+0200) Subject: bringing back wrapping text with nodes X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/f21a91b10cced1d0fd3be6b183bc64303e7f4f94 bringing back wrapping text with nodes --- diff --git a/modules/documentCanvas/canvas.js b/modules/documentCanvas/canvas.js index 80d3915..a6becf4 100644 --- a/modules/documentCanvas/canvas.js +++ b/modules/documentCanvas/canvas.js @@ -76,6 +76,7 @@ Canvas.prototype.insertNode = function(options) { $(textElement).replaceWith(newNode); newNode.before(prefix); newNode.after(suffix); + return newNode; } } diff --git a/modules/documentCanvas/canvasManager.js b/modules/documentCanvas/canvasManager.js index 3ced49a..5d17ec0 100644 --- a/modules/documentCanvas/canvasManager.js +++ b/modules/documentCanvas/canvasManager.js @@ -96,6 +96,27 @@ Manager.prototype.selectNode = function(wlxmlNode, options) { this.sandbox.publish('nodeSelected', wlxmlNode); }; +Manager.prototype.insertNewNode = function(wlxmlTag, wlxmlClass) { + var selection = window.getSelection(); + + if(selection.getRangeAt(0).collapsed) { + + } else { + var offsetStart = selection.anchorOffset; + var offsetEnd = selection.focusOffset; + if(offsetStart > offsetEnd) { + var tmp = offsetStart; + offsetStart = offsetEnd; + offsetEnd = tmp; + } + var node = new wlxmlNode.Node($(selection.anchorNode).parent()); + var newNode = this.canvas.insertNode({place: 'wrapText', context: node, tag: wlxmlTag, klass: wlxmlClass, offsetStart: offsetStart, offsetEnd: offsetEnd}); + this.selectNode(new wlxmlNode.Node(newNode), {movecaret: 'end'}); + } + + +} + Manager.prototype.getNodeElement = function(wlxmlNode) { return this.canvas.dom.find('#'+wlxmlNode.id); }; diff --git a/modules/documentCanvas/documentCanvas.js b/modules/documentCanvas/documentCanvas.js index cc4964b..bec74fc 100644 --- a/modules/documentCanvas/documentCanvas.js +++ b/modules/documentCanvas/documentCanvas.js @@ -50,9 +50,6 @@ return function(sandbox) { insertNewNode: function(wlxmlTag, wlxmlClass) { manager.insertNewNode(wlxmlTag, wlxmlClass); }, - wrapSelectionWithNewNode: function(wlxmlTag, wlxmlClass) { - manager.wrapSelectionWithNewNode(wlxmlTag, wlxmlClass); - }, command: function(command, meta) { manager.command(command, meta); } diff --git a/modules/rng/rng.js b/modules/rng/rng.js index 7c39d0f..a1fe65e 100644 --- a/modules/rng/rng.js +++ b/modules/rng/rng.js @@ -254,11 +254,7 @@ return function(sandbox) { sandbox.getModule('documentCanvas').toggleGrid(toggle); }, newNodeRequested: function(wlxmlTag, wlxmlClass) { - if(window.getSelection().isCollapsed) { sandbox.getModule('documentCanvas').insertNewNode(wlxmlTag, wlxmlClass); - } else { - sandbox.getModule('documentCanvas').wrapSelectionWithNewNode(wlxmlTag, wlxmlClass); - } }, command: function(cmd, meta) { sandbox.getModule('documentCanvas').command(cmd, meta);