From 8e6255bf612a7d33e1f1c97dd293db6f34949ef9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 20 Jun 2013 12:34:39 +0200 Subject: [PATCH 1/1] canvas manager wip - splitting node --- modules/documentCanvas/canvas.js | 1 + modules/documentCanvas/canvasManager.js | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) 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 -- 2.20.1