From ec37d417037cb44a4fdbe2623bbf5d1432845eb9 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Mon, 23 Mar 2020 12:48:32 +0000 Subject: [PATCH] [FIX] web_editor: ol in ol no number skip In the case of an
    in an
      we would have something like: ``` 1. 1. 2. 3. ``` because the sublist itself in version of summernote.org we are using is a list item, so it takes one extraenous item. With this changeset we have something that makes more sense: ``` 1. 1. 2. 2. ``` Because there are tons of use case of different selection of list level and indent or outdent, this commit also simplify outdenting (eg. now we outdent all the element of the same level than the first indented). opw-2185406 closes #48194 closes odoo/odoo#50352 X-original-commit: bbf4ad7d84d7fa4651744359658a8fa70cf94b17 Signed-off-by: Nicolas Lempereur (nle) --- .../static/src/js/editor/summernote.js | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/summernote.js b/addons/web_editor/static/src/js/editor/summernote.js index 06a282d0076..80ccd3d0c82 100644 --- a/addons/web_editor/static/src/js/editor/summernote.js +++ b/addons/web_editor/static/src/js/editor/summernote.js @@ -1792,6 +1792,7 @@ $.summernote.pluginEvents.indent = function (event, editor, layoutInfo, outdent) var flag = false; function indentUL(UL, start, end) { var next; + var previous; var tagName = UL.tagName; var node = UL.firstChild; var ul = document.createElement(tagName); @@ -1808,7 +1809,15 @@ $.summernote.pluginEvents.indent = function (event, editor, layoutInfo, outdent) while (node) { if (flag === 1 || node === start || $.contains(node, start)) { flag = true; - node.parentNode.insertBefore(li, node); + if (previous) { + if (dom.isList(previous.lastChild)) { + ul = previous.lastChild; + } else { + previous.appendChild(ul); + } + } else { + node.parentNode.insertBefore(li, node); + } } next = dom.nextElementSibling(node); if (flag) { @@ -1818,6 +1827,7 @@ $.summernote.pluginEvents.indent = function (event, editor, layoutInfo, outdent) flag = false; break; } + previous = node; node = next; } @@ -1855,14 +1865,22 @@ $.summernote.pluginEvents.indent = function (event, editor, layoutInfo, outdent) } next = dom.nextElementSibling(node); if (flag) { + var $succeeding = $(node).nextAll(); ul = node.parentNode; - li.parentNode.insertBefore(node, li); + if (dom.previousElementSibling(ul)) { + dom.insertAfter(node, li); + } else { + li.parentNode.insertBefore(node, li); + } + $succeeding.insertAfter(node); if (!ul.children.length) { - if (ul.parentNode.tagName === "LI") { + if (ul.parentNode.tagName === "LI" && !dom.previousElementSibling(ul)) { ul = ul.parentNode; } ul.parentNode.removeChild(ul); } + flag = false; + break; } if (node === end || $.contains(node, end)) { @@ -1894,9 +1912,13 @@ $.summernote.pluginEvents.indent = function (event, editor, layoutInfo, outdent) var $dom = $(ancestor); if (!dom.isList(ancestor)) { - // to indent a selection, we indent the child nodes of the common - // ancestor that contains this selection - $dom = $(dom.node(ancestor)).children(); + if (dom.isList(ancestor.parentNode)) { + $dom = $(ancestor.parentNode); + } else { + // to indent a selection, we indent the child nodes of the common + // ancestor that contains this selection + $dom = $(dom.node(ancestor)).children(); + } } if (!$dom.not('br').length) { // if selection is inside a list, we indent its list items