summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js/editor/summernote.js
diff options
context:
space:
mode:
authorNicolas Lempereur <nle@odoo.com>2020-03-23 12:48:32 +0000
committerNicolas Lempereur <nle@odoo.com>2020-04-28 18:46:14 +0000
commitec37d417037cb44a4fdbe2623bbf5d1432845eb9 (patch)
tree5f73b510365bd13d92be148c2c5da7e6d26963d0 /addons/web_editor/static/src/js/editor/summernote.js
parenteae51e5fa8ef1480b83dfedb7fbc5ad4a479a6e2 (diff)
[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>
Diffstat (limited to 'addons/web_editor/static/src/js/editor/summernote.js')
-rw-r--r--addons/web_editor/static/src/js/editor/summernote.js34
1 files 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