From: Jan Szejko Date: Thu, 23 Feb 2017 12:50:17 +0000 (+0100) Subject: save caret position when ending a list X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/14f922a448083db61e90b9f9da2b1bc5bc629d5e?ds=inline;hp=4e6bff06c0c36ef0e27846d6c628f503720c5b36 save caret position when ending a list (cherry picked from commit 42d1c68) --- diff --git a/src/editor/plugins/core/lists.js b/src/editor/plugins/core/lists.js index 1ff6ccd..750fb7e 100644 --- a/src/editor/plugins/core/lists.js +++ b/src/editor/plugins/core/lists.js @@ -92,14 +92,16 @@ var toggleListAction = function(type) { if(current.parent().is('item') && current.parent().parent().is('list') && current.parent().next() === null) { var item = current.parent(); var list = item.parent(); - current.document.transaction(function() { + var doc = current.document; + doc.transaction(function() { var p = list.after({tagName: 'div', attrs: {'class': 'p'}}); p.append({text: current.getText()}); item.detach(); if(list.contents().length === 0) { list.detach(); } - return current.document.createFragment(current.document.NodeFragment, {node: p}); + return doc.createFragment( + doc.CaretFragment, {node: p.contents()[0], offset: params.fragment.offset}); }, { metadata: { description: action.getState().description, @@ -113,14 +115,15 @@ var toggleListAction = function(type) { var toSearch = current.nodeType === Node.ELEMENT_NODE ? [current] : []; toSearch = toSearch.concat(current.parents()); toSearch.some(function(node) { + var doc = node.document; if(node.is('list')) { - node.document.transaction(function() { + doc.transaction(function() { var firstItem = node.object.extractListItems(), toret; if(params.fragment.isValid()) { toret = params.fragment; } else { - toret = node.document.createFragment(node.document.NodeFragment, {node: firstItem}); + toret = doc.createFragment(doc.NodeFragment, {node: firstItem}); } return toret; }, {