Repository navigation
RichText: own undo signalling - #10650
Conversation
|
TinyMCE's logic for undo levels, for reference: |
bfc721d to
7c9ffa8
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
b1b60d4 to
0233a47
Compare
7cf30f6 to
aa4740d
Compare
|
|
||
| await pressWithModifier( META_KEY, 'z' ); | ||
|
|
||
| expect( await getEditedPostContent() ).toMatchSnapshot(); |
There was a problem hiding this comment.
We should ideally test caret position here too. Because it resets to the beginning of the field unexpectedly. Apparently this also occurs in the latest plugin release, so not strictly a regression.
There was a problem hiding this comment.
It's always been like this. We'll probably need to save selection to the editor state. Seems like material for a separate PR.
|
The Undo behavior feels particularly heavy-handed (destroying all of a paragraph I've written if I don't move my mouse), but I guess this aligns with the previous behavior as well. |
It should behave roughly the same as before. With this change we can also fine tune it ourselves. Ideas for other triggers are welcome. Not sure what else we can do, maybe a typing pause could trigger an undo level? I don't think we can rely on punctuation as that's not universal. |
41ed725 to
1cfd664
Compare
|
@aduth I went for adding an undo level after a one second pause in input. We can adjust this value if it's too high or low. |
77da162 to
78c1a1c
Compare
| // The input event does not fire when the whole field is selected and | ||
| // BACKSPACE is pressed. | ||
| if ( keyCode === BACKSPACE ) { | ||
| this.onChange( this.createRecord(), true ); |
There was a problem hiding this comment.
I don't understand why this change has been made.
There was a problem hiding this comment.
We used to skip applying changes back to the live DOM, and so did we here. Since #11595 we no longer do that, but it hasn't been updated here. I've removed it here while revising the parameters for this.onChange.
| await clickBlockAppender(); | ||
|
|
||
| await page.keyboard.type( 'before pause' ); | ||
| await new Promise( ( resolve ) => setTimeout( resolve, 1000 ) ); |
There was a problem hiding this comment.
I wish we could emulate this without actually slowing our test run by one full second.
| bindGlobal | ||
| shortcuts={ { | ||
| [ rawShortcut.primary( 's' ) ]: this.save, | ||
| [ rawShortcut.primary( 'z' ) ]: flow( preventDefault, onUndo ), |
There was a problem hiding this comment.
By moving this into bindGlobal, we're now preventing default behavior for all inputs in the page, not just RichText, right? We'd then rely on all of those inputs to be fully controlled by state values governed by history? I'm not sure I feel particularly confident we can trust that.
There was a problem hiding this comment.
Example:
- Navigate to Posts > Add New
- Insert a reusable block
- Click Edit in the Reusable Block's heading
- Make some changes to the title
- Press Cmd+Z
In 4.3: Input undoes changes
In this branch: The block is removed (presumably undo'ing the block addition to the editor)
There was a problem hiding this comment.
Which input fields on the page would not be included in our history? Maybe it would be better then for those to opt-in vs opt-out? Currently undoing any changes with the browser actually adds to the history, not removes.
There was a problem hiding this comment.
Why is the title not part of the history?
There was a problem hiding this comment.
Non-exhaustive set of others:
- Embed placeholder URL input
- Table placeholder columns / rows inputs
- Media placeholders URL input
- Post permalink
- Categories search
(Discovered via onSubmit= Find in Files search)
There was a problem hiding this comment.
Okay, I'm unsure atm then how to prevent default behaviour for RichText only. Restore https://github.com/WordPress/gutenberg/blob/72e51c692108ce52021564352a6d2661466fc231/packages/editor/src/components/rich-text/remove-browser-shortcuts.js?
There was a problem hiding this comment.
Yeah, for now I think we might just need to have two KeyboardShortcuts for handling these keys, one top-level but not applied to inputs, the other specific to when a RichText is selected.
tl;dr I think that's what we had in the prior revision you're referring to?
There was a problem hiding this comment.
Right, I just restored your revision :)
04430fc to
dc4f688
Compare
There was a problem hiding this comment.
Not necessary here, but if we're going to support Cmd+Y , we should probably do so consistently between RichText and the top-level handler.
There was a problem hiding this comment.
We're only removing the browser shortcut here, not adding any support. But maybe we should add support everywhere?
There was a problem hiding this comment.
Hmm, in that case, is the line even necessary if we're not handling it anyways?
dc4f688 to
9dba9e5
Compare
|
Thanks a lot @aduth for the review! |
Description
This is a proposal for the
RichTextcomponent to handle undo signalling in favour of listening to the TinyMCEchangeevent.RichTextwill signal that an undo level should be created:inputevent (typing).Why?
It's not always clear when the
changeevent exactly triggers and we do not always want it to create an undo level. Thechangeevent also no longer accounts for formatting changes, as these are no longer done by TinyMCE. It's easier to just do it ourselves so we can fine-tune and not rely on the TinyMCE event.How has this been tested?
Test undoing and redoing changes from
RichTextcomponents.Screenshots
Types of changes
Checklist: