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