Re: [w3c/editing] Removal of browser built-in Undo stack functionality from contenteditable (#150)

> > @whsieh and I are experimenting with something simpler where you can just register a function for undo / redo.
> 
> Sounds interesting! Could you share some more details?
> 

Sure! Here's a high-level overview; however, please note that the UndoManager prototype is currently only enabled in some first party Apple applications, and is not available in Safari quite yet.

There's a couple of main parts to this API: `UndoManager` and `UndoItem`. The `UndoManager` is exposed as a readonly attribute on `Document`, and has a method, `addItem`, that can be used to add an undoable action to the platform undo stack. This undoable action is backed by an `UndoItem`, which may be constructed using a label string and callbacks that are invoked when the user triggers undo or redo.

```
interface UndoManager {
    void addItem(UndoItem item)
};
```

...and `UndoItem` is defined as such:

```
interface UndoItem {
    Constructor(UndoItemInit initDict);
    readonly attribute DOMString label;
};

dictionary UndoItemInit {
    required DOMString label; // Determines the string to display in platform undo UI (for instance, the menu bar on macOS).
    required VoidCallback undo; // Invoked when the user triggers undo.
    required VoidCallback redo; // Invoked when the user triggers redo.
};
```

The hope is to make it easier for web content to define custom undoable actions using DOM API, in a way that:

(1) doesn't require maintaining a custom notion of an undo stack in script, and...
(2) maintains better platform integration by influencing the undo label name in platform UI, as well as being agnostic to all platform-specific methods of triggering undo and redo (e.g. shaking the device on iOS, and selecting actions in the menu bar on macOS).

-- 
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/150#issuecomment-460108516

Received on Monday, 4 February 2019 01:31:49 UTC