From 793988c7ed99b1b6e9a73efb94e438c7d0c7b34e Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Thu, 30 Aug 2018 16:47:27 +0200 Subject: [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: ```

hello world

cruel

bingo

``` 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 `

` 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 --- addons/web_editor/static/src/js/summernote.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'addons/web_editor/static/src') 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(); -- cgit v1.2.3 From 61b771256caad64815011a4eb5b68fe7f220f34e Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Fri, 31 Aug 2018 14:57:05 +0200 Subject: [FIX] web_editor: back to first -> history stay ok If we do: - one change that will be saved in history - go back to the document before any change - do other change we can easily get in a state were the history is no longer recorded. The history is kept like this: - pos: our position in the history - aUndo: the snapshots of history - toSnap: the last history snapshop that is to be saved so for example if we start without change (at originalState): {pos: 0, aUndo=[], toSnap=null} Then we do two changes (change1, change2): {pos: 2, aUndo=[originalState, change1], toSnap=change2} If we make an undo, we will get to: {pos: 1, aUndo=[originalState,change1,change2], toSnap=null) If we make another change (change3): {pos: 2, aUndo=[originalState, change1], toSnap=change3} So the history after the position is removed. But when we get back to the original, the state would forever be: {pos: 0, aUndo=[originalState], toSnap=change85} because when doing a change, the code only removed history from the max(pos, 1) index. opw-1870119 closes #26701 --- addons/web_editor/static/src/js/rte.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_editor/static/src') diff --git a/addons/web_editor/static/src/js/rte.js b/addons/web_editor/static/src/js/rte.js index 2940fcfa44f..f950f4ccbab 100644 --- a/addons/web_editor/static/src/js/rte.js +++ b/addons/web_editor/static/src/js/rte.js @@ -159,7 +159,7 @@ var History = function History ($editable) { if (aUndo[pos]) { pos = Math.min(pos, aUndo.length); - aUndo.splice(Math.max(pos,1), aUndo.length); + aUndo.splice(pos, aUndo.length); } // => make a snap when the user change editable zone (because: don't make snap for each keydown) -- cgit v1.2.3