From 61b771256caad64815011a4eb5b68fe7f220f34e Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Fri, 31 Aug 2018 14:57:05 +0200 Subject: [PATCH] [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(-) 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)