X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/f7c97ef38dc00ec9b5358ae0bf959a5e6f99271c..49d0411a1353ff5289f5b2021f7f439e4b8f1487:/modules/documentCanvas/canvasManager.js?ds=inline diff --git a/modules/documentCanvas/canvasManager.js b/modules/documentCanvas/canvasManager.js index 71c9342..b7e7212 100644 --- a/modules/documentCanvas/canvasManager.js +++ b/modules/documentCanvas/canvasManager.js @@ -109,11 +109,20 @@ Manager.prototype.insertNewNode = function(wlxmlTag, wlxmlClass) { offsetStart = offsetEnd; offsetEnd = tmp; } + + var wrapper = canvasNode.create({tag: wlxmlTag, klass: wlxmlClass}); - this.canvas.nodeWrap({inside: canvasNode.create($(selection.anchorNode).parent()), + var parent = $(selection.anchorNode).parent(); + + var textNodeIdx = parent.contents().index($(selection.anchorNode)); + if(selection.anchorNode != selection.focusNode) { + textNodeIdx = [textNodeIdx, parent.contents().index($(selection.focusNode))]; + } + this.canvas.nodeWrap({inside: canvasNode.create(parent), _with: wrapper, offsetStart: offsetStart, - offsetEnd: offsetEnd + offsetEnd: offsetEnd, + textNodeIdx: textNodeIdx }); this.selectNode(wrapper, {movecaret: 'end'}); } @@ -159,6 +168,8 @@ Manager.prototype.selectFirstNode = function() { }; Manager.prototype.movecaretToNode = function(nodeElement, where) { + if(!nodeElement.length) + return; var range = document.createRange(); range.selectNodeContents(nodeElement[0]); @@ -184,7 +195,7 @@ Manager.prototype.onEnterKey = function(e) { if(pos.isAtEnd) { newNode = canvasNode.create({tag: pos.parentNode.attr('wlxml-tag'), klass: pos.parentNode.attr('wlxml-class')}); - this.canvas.nodeInsertAfter({node: newNode, after: canvas.getNodeById(pos.parentNode.attr('id'))}); + this.canvas.nodeInsertAfter({node: newNode, after: this.canvas.getNodeById(pos.parentNode.attr('id'))}); } else { newNode = this.canvas.nodeSplit({node: contextNode, textNodeIdx: pos.textNodeIndex, offset: pos.textNodeOffset}); } @@ -215,17 +226,17 @@ Manager.prototype.command = function(command, meta) { if(command === 'createList') { var node = canvasNode.create(pos.parentNode); - if(window.getSelection().getRangeAt().collapsed && this.canvas.nodeInsideList({node: node})) { + if(window.getSelection().getRangeAt(0).collapsed && this.canvas.nodeInsideList({node: node})) { this.canvas.listRemove({pointer: node}); this.selectNode(node, {movecaret: 'end'}); this.sandbox.publish('contentChanged'); } else { - if(!this.canvas.nodeInsideList({node: node})) { - this.canvas.listCreate({start: node, end: canvasNode.create(pos.focusNode)}); + //if(!this.canvas.nodeInsideList({node: node})) { + this.canvas.listCreate({start: node, end: canvasNode.create(pos.focusNode), type: meta}); this.selectNode(node, {movecaret: 'end'}); this.sandbox.publish('contentChanged'); - } + //} } }