Format Library: Allow browser native undo/redo for link input #19488
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.
Blocked by (currently merges to): #19487
Fixes #18755
This pull request seeks to allow for keyboard shortcuts for undo and redo to use the browser native behavior whilst adding or editing a link in a RichText field.
Implementation Notes:
Based on the previous discussion in #18755, I tried a few ideas for how to resolve this. Initially, I had hoped to use the same named shortcuts as the editor ("core/editor/undo" and "core/editor/redo") to ensure a consistent behavior against which to prevent the default. However, this would cause an implicit circular dependency between the
format-library
andeditor
modules.The implementation here consolidates a bit of the key handling, where there is currently already handling to avoid
ObserveTyping
from taking effect in response to certain key events in the link editor.I still think there might be some opportunity to generalize the behavior here, considering that we also have a similar need for the inline image width control (amongst others as well).
It might be something where we can devise some consistent condition for how these key events are to be excluded: For example, treating inputs within a popover (or modal, or dropdown) within the editor area as being exempt to consideration by
ObserveTyping
and/or the global editor history state keyboard shortcuts. However, at least in the latter case, it's not always clear if this is the expected behavior, in case those inputs interact directly with editor state. It's more likely to be a sufficient solution to address the need forObserveTyping
ignored events.Testing Instructions:
Verify there is no regression in the behavior of viewing, adding, editing, or removing links.
Furthermore, verify that when editing a link and pressing Ctrl+Z or Ctrl+Shift+Z to undo or redo a change within the input, the change affects the input text and not the top-level editor.