[FIX] web_editor: ol in ol no number skip

In the case of an <ol> in an <ol> 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) <nle@odoo.com>
This commit is contained in:
Nicolas Lempereur
2020-04-28 18:46:14 +00:00
parent eae51e5fa8
commit ec37d41703
@@ -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