Re: [w3c/editing] undo manager (#209)

> Unless I am misinterpreting something, I do not see how this model allows user code to manage the stacks.

@Dalzhim I think what the proposal describes is a model which works well in cases where you have a common undo history for one element and all its descendant elements in which some of these descendant elements let the browser's native implementation create undo items and others do this by means of JavaScript. Imagine for example a `<form>`-element with one common history which includes several `<input type="text'>` fields which let the browser handle it's history and one contenteditable element for which JavaScript creates undo/redo entries.

If you have an element that is to have its entirely own undo/redo stack that si JS controlled, the way you can achieve that is by means of a few tricks:

* If you need only the undo menu enabled, flush the stack, then add one item to the undo stack. Listen to the beforeinput event for undo and cancel it to undo something.

* If you need only the redo menu enabled, flush the stack, then add one item to the undo stack and then undo it. Listen to the beforeinput event for redo and cancel it to redo something.

* If you need both redo and undo enabled, flush the stack, add two items to the undo stack and then undo one of them. Listen for beforeinput event for both undo and redo and cancel both of them so that both menus stay activated.

* In Safari there are labels on what redo and undo actually do. If you want those to be correct, flush the stack after every edit action and repopulate as mentioned in the above three points with correct labels.

That should take care of your proposal 2, right?

As for your alternatives: currently the proposal doesn't actually register the undoitem itself nor needs to know what form that is stored in so and you could just register something generic like:

```js
document.undoManager.addItem(new UndoItem({
        label: "Edit",
        undo: () => myEditor.undo(),
        redo: () => myEditor.redo()
    }));
```

Or if you want to keep your stack and the browser's stack in sync and the label correct, etc. something like

```js
document.undoManager.addItem(new UndoItem({
        label: "Split paragraph",
        undo: () => myEditor.undo({historyItem: 123}),
        redo: () => myEditor.redo({historyItem: 123})
    }));
```

I don't think I get why you need to provide the undoitem to the undo/redo functions. Is it because you want the label? Or because you want to get to the undo function from the redo function? Or some entirely different thing?


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

Received on Monday, 2 December 2019 23:51:53 UTC