mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
[Editor] Avoid to add unexpected commands in the undo/redo queue when undoing/redoing (bug 1781790)
We can undo/redo a command which will at some point add a command in the queue: typically it can happening when redoing an addition. So the idea is to lock the queue when undoing/redoing.
This commit is contained in:
parent
89d1892959
commit
759116f4c5
2 changed files with 43 additions and 6 deletions
|
@ -66,6 +66,8 @@ class IdManager {
|
|||
class CommandManager {
|
||||
#commands = [];
|
||||
|
||||
#locked = false;
|
||||
|
||||
#maxSize;
|
||||
|
||||
#position = -1;
|
||||
|
@ -100,6 +102,10 @@ class CommandManager {
|
|||
cmd();
|
||||
}
|
||||
|
||||
if (this.#locked) {
|
||||
return;
|
||||
}
|
||||
|
||||
const save = { cmd, undo, type };
|
||||
if (this.#position === -1) {
|
||||
this.#position = 0;
|
||||
|
@ -139,7 +145,12 @@ class CommandManager {
|
|||
// Nothing to undo.
|
||||
return;
|
||||
}
|
||||
|
||||
// Avoid to insert something during the undo execution.
|
||||
this.#locked = true;
|
||||
this.#commands[this.#position].undo();
|
||||
this.#locked = false;
|
||||
|
||||
this.#position -= 1;
|
||||
}
|
||||
|
||||
|
@ -149,7 +160,11 @@ class CommandManager {
|
|||
redo() {
|
||||
if (this.#position < this.#commands.length - 1) {
|
||||
this.#position += 1;
|
||||
|
||||
// Avoid to insert something during the redo execution.
|
||||
this.#locked = true;
|
||||
this.#commands[this.#position].cmd();
|
||||
this.#locked = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue