From: Aleksander Ɓukasz Date: Thu, 20 Jun 2013 10:34:39 +0000 (+0200) Subject: canvas manager wip - splitting node X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/8e6255bf612a7d33e1f1c97dd293db6f34949ef9 canvas manager wip - splitting node --- diff --git a/modules/documentCanvas/canvas.js b/modules/documentCanvas/canvas.js index a15bb2c..20c286a 100644 --- a/modules/documentCanvas/canvas.js +++ b/modules/documentCanvas/canvas.js @@ -103,6 +103,7 @@ Canvas.prototype.splitNode = function(options) { newNode.append(node) }); nodeToSplit.after(newNode); + return newNode; } Canvas.prototype.createList = function(options) { diff --git a/modules/documentCanvas/canvasManager.js b/modules/documentCanvas/canvasManager.js index fcf2659..de085ce 100644 --- a/modules/documentCanvas/canvasManager.js +++ b/modules/documentCanvas/canvasManager.js @@ -44,7 +44,7 @@ var Manager = function(canvas, sandbox) { canvas.dom.on('keydown', '#rng-module-documentCanvas-contentWrapper', function(e) { if(e.which === 13) { e.preventDefault(); - //view.insertNewNode(null, null); + manager.insertNewNode(null, null); } if(e.which === 8) { var anchor = window.getSelection().anchorNode; @@ -139,6 +139,24 @@ Manager.prototype.toggleGrid = function(toggle) { this.gridToggled = toggle; }; +Manager.prototype.insertNewNode = function(wlxmlTag, wlxmlClass) { + //TODO: Insert inline + var anchor = $(window.getSelection().anchorNode); + var anchorOffset = window.getSelection().anchorOffset; + + var parent = anchor.parent(); + var idx = parent.contents().index(anchor); + + if(anchorOffset < anchor.text().length) { + var newNode = this.canvas.splitNode({node: {id: parent.attr('id')}, textNodeIdx: idx, offset: anchorOffset}); + this.selectNode(new wlxmlNode.Node(newNode), {movecaret: true}); + } + + + + this.sandbox.publish('contentChanged'); +}; + return Manager; }); \ No newline at end of file