-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Implement basic undo history #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
youknowriad
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm personally satisfied with this implementation for now. We could revisit later.
editor/state.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm personally fine with this
editor/state.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did the same simplification in #407 (We'll have some conflicts)
editor/state.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's time to start splitting those reducers into separate files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep in mind the cognitive overload nd perceived complexity for people whenever we split files. (Part of why redux is perceived as more complex than what it is.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's time to start splitting those reducers into separate files
Is this feeling compounded by the addition of the utilities to the file? I'd like to have those moved first before anything else.
editor/state.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the thinking behind this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the thinking behind this?
Memory, but in hindsight it might be a bit premature. We can remove it.
Arguably a premature optimization, we can reconsider later
|
youknowriad
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Later, we'll probably need to keep track of the focus config in the state. This would allow the undo/redo to move the cursor to the right position
This pull request seeks to introduce an undo history for blocks state.
Implementation notes:
The undo implementation is roughly based on the one explored in official Redux documentation.
redux-undois a popular alternative module which exists to implement this behavior, but also includes a number of features we don't need.To the previous point, the changes include a proposed
combineUndoableReducerswhich defines getters for transparent property access on the original reducer object (allow access bystate.blocks.byUiddirectly rather thanstate.blocks.present.byUid). I feel ever-so-slightly uncomfortable including enhanced objects like this in state.We may want to move these utilities to a separate file or, more likely, a separate module, but they're included here for initial discussion before being referenced more formally.
Testing instructions:
Verify that unit tests pass:
Confirm that upon changing a text block†, the undo buttons become activated in the editor header and behave as expected upon toggling.
† The text block's change behavior is currently only triggered when blurring the
contenteditable, meaning you'll need to click elsewhere on the screen first before the buttons become active.