- From: Gabriel Aubut-Lussier <notifications@github.com>
- Date: Mon, 02 Dec 2019 13:49:52 -0800
- To: w3c/editing <editing@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Monday, 2 December 2019 21:49:56 UTC
The proposal seems to enforce a model where `undo` and `redo` are two seperate actions as evidenced by the distinct `UndoItemCallback`s on every `UndoItem`.
I usually consider both `undo` and `redo` actions as being the same generic function that defaults to a different stack and where every `UndoItem` is invertible. Here is some code to make this easier to understand:
```
const undoStack = Array();
const redoStack = Array();
function applyAction(originalStack, oppositeStack)
{
const item = originalStack.pop();
oppositeStack.push(invertAction(item));
item.apply();
}
function undo()
{
applyAction(undoStack, redoStack);
}
function redo()
{
applyAction(redoStack, undoStack);
}
```
In my experience, it is easier to manage complexity when reasoning about invertible actions as opposed to implementing undo and redo as two separate actions. Should the `UndoManager` really push developers toward this direction?
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/editing/issues/209#issuecomment-560658613
Received on Monday, 2 December 2019 21:49:56 UTC