summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src
diff options
context:
space:
mode:
authorNicolas Lempereur <nle@odoo.com>2018-08-30 16:47:27 +0200
committerNicolas Lempereur <nle@odoo.com>2018-09-03 16:30:03 +0200
commit793988c7ed99b1b6e9a73efb94e438c7d0c7b34e (patch)
tree8573be2f8eb029c8d5eac65943f34d9996c1bf73 /addons/web_editor/static/src
parentb5471da2e0a5c8ef3b9fe35a933da25c97d8a6a2 (diff)
[FIX] web_editor: normal up/down in content in cell
In the editor in a table cell, when we press UP/DOWN keys: - we have default editor/browser behavior if there is content before (UP) or after (DOWN) the element we are currently on - else we go to the previous (UP) or next (DOWN) row if available - else we go to the next content if available - else we have the default editor/browser behavior But when checking if there is an element before/after the content, we did not take into account if there was an ancestor node inside the cell that had content after, so for example with this structure: ``` <table> <tr><td> <p>hello <b>world</b></p> <p>cruel</p> </td></tr> <tr><td> <p>bingo</p> </td></tr> </table> ``` if the current range was on 'world' text node, we would just check if there is content after this text node, not if there is content after its `<p/>` ancestor. Before the fix we would get on the next row, after we would have default editor/browser behavior: ie. if cruel is on another line, going to this line. opw-1870119 closes #26701
Diffstat (limited to 'addons/web_editor/static/src')
-rw-r--r--addons/web_editor/static/src/js/summernote.js18
1 files changed, 16 insertions, 2 deletions
diff --git a/addons/web_editor/static/src/js/summernote.js b/addons/web_editor/static/src/js/summernote.js
index 574836d0180..d89c1c55c55 100644
--- a/addons/web_editor/static/src/js/summernote.js
+++ b/addons/web_editor/static/src/js/summernote.js
@@ -1113,7 +1113,14 @@ $.summernote.pluginEvents.untab = function (event, editor, layoutInfo) {
$.summernote.pluginEvents.up = function (event, editor, layoutInfo) {
var r = range.create();
var node = dom.firstChild(r.sc.childNodes[r.so] || r.sc);
- if (!r.isOnCell() || (!dom.isCell(node) && dom.hasContentBefore(node) && (!dom.isBR(dom.hasContentBefore(node)) || !dom.isText(node) || dom.isVisibleText(node) || dom.hasContentBefore(dom.hasContentBefore(node))))) {
+ if (!r.isOnCell()) {
+ return;
+ }
+ // check if an ancestor between node and cell has content before
+ var ancestor = dom.ancestor(node, function (ancestorNode) {
+ return dom.hasContentBefore(ancestorNode) || dom.isCell(ancestorNode);
+ });
+ if (!dom.isCell(ancestor) && (!dom.isBR(dom.hasContentBefore(ancestor)) || !dom.isText(node) || dom.isVisibleText(node) || dom.hasContentBefore(dom.hasContentBefore(ancestor)))) {
return;
}
event.preventDefault();
@@ -1130,7 +1137,14 @@ $.summernote.pluginEvents.up = function (event, editor, layoutInfo) {
$.summernote.pluginEvents.down = function (event, editor, layoutInfo) {
var r = range.create();
var node = dom.firstChild(r.sc.childNodes[r.so] || r.sc);
- if (!r.isOnCell() || (!dom.isCell(node) && dom.hasContentAfter(node) && (!dom.isBR(dom.hasContentAfter(node)) || !dom.isText(node) || dom.isVisibleText(node) || dom.hasContentAfter(dom.hasContentAfter(node))))) {
+ if (!r.isOnCell()) {
+ return;
+ }
+ // check if an ancestor between node and cell has content after
+ var ancestor = dom.ancestor(node, function (ancestorNode) {
+ return dom.hasContentAfter(ancestorNode) || dom.isCell(ancestorNode);
+ });
+ if (!dom.isCell(ancestor) && (!dom.isBR(dom.hasContentAfter(ancestor)) || !dom.isText(node) || dom.isVisibleText(node) || dom.hasContentAfter(dom.hasContentAfter(ancestor)))) {
return;
}
event.preventDefault();