-
Notifications
You must be signed in to change notification settings - Fork 58
Closed
Description
Lexical has an implementation of undo/redo, in History.swift. (Arguably this should have been in a Plugin, but there's some historical cruft here.)
Currently, to integrate history into a surface, you need to:
- register handlers for the commands
undo,redo, andclearEditor, and in the handlers, proxy those commands tolexicalView.editorHistory - create toolbar buttons to dispatch the commands
undoandredo - register handlers for
canUndoandcanRedo, and use these handlers to trigger updating the toolbar to enable/disable the undo/redo buttons - register an update listener, that calls
applyChange()on theEditorHistoryinstance, passing the active and previous editor states
I would like to see this improved. We should have a new EditorHistoryPlugin class, in its own package, which will:
- own and expose the EditorHistory object
- creates and keeps a reference to
externalHistoryState, which is passed in toEditorHistoryon init - register the handlers for
undo,redo, andclearEditor- In fact, you could move the declarations of the constants for the
.undoand.redocommands intoEditorHistoryPluginas well
- In fact, you could move the declarations of the constants for the
- registers the update listener that calls
applyChange()on theEditorHistoryobject - expose getters for
canUndoandcanRedo, which just check ifexternalHistoryState.undoStack > 0(and same forredoStack). Note that this doesn't obviate the need for thecanUndoandcanRedocommands -- those are still useful to know when these values change. - move
History.swiftinto this package
Then, to integrate it into the playground:
- It should be enough to make the toolbar buttons just dispatch the
undoandredocommands, now that theEditorHistoryPluginis listening for them. - Still register
canUndoandcanRedo, and use them to trigger a toolbar update.
Note, I've tagged this task good first issue, although there are quite a lot of moving parts. If you need any more context or help, let me know!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomers