X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/b554451bd332b417a9304fd60fafe116220a9ca4..e64e37a2fbe6d64b2513133d34370f0d1a63f7b9:/modules/documentCanvas/canvasManager.js diff --git a/modules/documentCanvas/canvasManager.js b/modules/documentCanvas/canvasManager.js index 6a0fc5c..3ced49a 100644 --- a/modules/documentCanvas/canvasManager.js +++ b/modules/documentCanvas/canvasManager.js @@ -14,6 +14,7 @@ var getCursorPosition = function() { textNodeOffset: selection.anchorOffset, textNodeIndex: parent.contents().index(anchorNode), parentNode: parent, + focusNode: $(selection.focusNode).parent(), isAtEnd: selection.anchorOffset === anchorNode.text().length } }; @@ -181,6 +182,26 @@ Manager.prototype.onBackspaceKey = function(e) { } } +Manager.prototype.command = function(command, meta) { + var pos = getCursorPosition(); + + if(command === 'createList') { + var node = new wlxmlNode.Node(pos.parentNode); + if(window.getSelection().getRangeAt().collapsed && this.canvas.insideList({pointer: node})) { + this.canvas.removeList({pointer: node}); + this.selectNode(node, {movecaret: 'end'}); + this.sandbox.publish('contentChanged'); + } + else { + if(!this.canvas.insideList({pointer: node})) { + this.canvas.createList({start: new wlxmlNode.Node(pos.parentNode), end: new wlxmlNode.Node(pos.focusNode)}); + this.selectNode(new wlxmlNode.Node(pos.parentNode), {movecaret: 'end'}); + this.sandbox.publish('contentChanged'); + } + } + } + +} return Manager;