Hook up history undo/redo input type #16989
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes woocommerce/woocommerce-blocks#690.
When undoing through the right-click menu or main browser menu, the browser will undo a change and Gutenberg will create an extra undo level. This is not ideal.
This PR intercepts this behaviour for browsers that support the
beforeinput
event. Unfortunately, there's not much we can do for other browsers (Firefox and Edge)...What this PR does not do is update the internal browser history/undo stack so that the browser buttons reflect Gutenberg's history/undo stack. Unfortunately, this is not possible today in any browser, or at least not that I'm aware of. There might be some tricks to make sure that both buttons are always enabled, perhaps something to experiment with in a separate PR.
In the future when all browsers support this event, we could event stop binding cmd+z etc, because normally this also triggers theActually no, because the browser doesn't know if there's past or future records. Not sure if there's any any to "fool" the browser into thinking there is.beforeinput
event. :)Cc @nerrad.
How has this been tested?
Open the demo post. Make some changes.
Use either of these:
Ensure the history buttons in Gutenberg update correctly: the redo button should become active, and the undo button shouldn't reapply the change.
Screenshots
Types of changes
Checklist: