Skip to content
Snippets Groups Projects
Commit 61b77125 authored by Nicolas Lempereur's avatar Nicolas Lempereur
Browse files

[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
parent 793988c7
Branches
Tags
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment