+Manager.prototype.onEnterKey = function(e) {\r
+ e.preventDefault();\r
+ var pos = getCursorPosition();\r
+ var contextNode = this.canvas.getNodeById(pos.parentNode.attr('id'));\r
+ var newNode;\r
+\r
+ if(pos.isAtEnd) {\r
+ newNode = canvasNode.create({tag: pos.parentNode.attr('wlxml-tag'), klass: pos.parentNode.attr('wlxml-class')});\r
+ this.canvas.nodeInsertAfter({node: newNode, after: canvas.getNodeById(pos.parentNode.attr('id'))});\r
+ } else {\r
+ newNode = this.canvas.nodeSplit({node: contextNode, textNodeIdx: pos.textNodeIndex, offset: pos.textNodeOffset});\r
+ }\r
+ if(newNode)\r
+ this.selectNode(newNode, {movecaret: true});\r
+ this.sandbox.publish('contentChanged');\r
+};\r
+\r
+Manager.prototype.onBackspaceKey = function(e) {\r
+ var pos = getCursorPosition();\r
+ var len = pos.textNode.text().length;\r
+ if(len === 1) {\r
+ // Prevent deleting node by browser after last character removed;\r
+ e.preventDefault();\r
+ pos.parentNode.text('');\r
+ }\r
+ if(len === 0) {\r
+ e.preventDefault();\r
+ var toRemove = canvasNode.create(pos.textNode);\r
+ var prevNode = this.canvas.getPrecedingNode({node:toRemove});\r
+ this.canvas.nodeRemove({node: toRemove}); // jesli nie ma tekstu, to anchor nie jest tex nodem\r
+ this.selectNode(prevNode, {movecaret: 'end'});\r
+ }\r
+}\r
+\r
+Manager.prototype.command = function(command, meta) {\r
+ var pos = getCursorPosition();\r
+ \r
+ if(command === 'createList') {\r
+ var node = canvasNode.create(pos.parentNode);\r
+ if(window.getSelection().getRangeAt().collapsed && this.canvas.nodeInsideList({node: node})) {\r
+ this.canvas.listRemove({pointer: node});\r
+ this.selectNode(node, {movecaret: 'end'});\r
+ this.sandbox.publish('contentChanged');\r
+ }\r
+ else {\r
+ if(!this.canvas.nodeInsideList({node: node})) {\r
+ this.canvas.listCreate({start: node, end: canvasNode.create(pos.focusNode)});\r
+ this.selectNode(node, {movecaret: 'end'});\r
+ this.sandbox.publish('contentChanged');\r
+ }\r
+ }\r
+ }\r
+\r
+}\r
+\r
+\r