X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/8bf6c2bb6ef0a358a3591d19d6aff7a1f7f22b92..49d0411a1353ff5289f5b2021f7f439e4b8f1487:/modules/documentCanvas/canvasManager.js?ds=sidebyside diff --git a/modules/documentCanvas/canvasManager.js b/modules/documentCanvas/canvasManager.js index 5edd4be..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'}); }