Repository navigation
fix(shortcut): skip editing shortcuts when the editor input is gone - #13861
Closed
yuxi-liu-wired wants to merge 1 commit into
Closed
yuxi-liu-wired wants to merge 1 commit into
yuxi-liu-wired wants to merge 1 commit into
Conversation
Pressing alt+u (ctrl+u on mac) right as the block editor closed threw an uncaught "TypeError: Cannot read properties of null (reading 'value')". The same could happen with alt+k, alt+d/ctrl+w, alt+w and the forward and backward word shortcuts. These shortcuts run only while state/editing? is true, but that flag stays true for a moment after the textarea has left the DOM, so state/get-input returns nil. Their handlers (kill-line-before!, kill-line-after!, forward-kill-word, backward-kill-word, cursor-forward-word, cursor-backward-word) pass that nil straight to helpers that read (.-value input). The shortcut config now wraps these handlers in when-editing-input, which calls the handler only when state/get-input returns an element and otherwise does nothing. config-test calls each of these shortcut fns with state/get-input redefined to return nil and asserts that none of them throws.
Contributor
Author
|
Superseded by #13865, which fixes the cause for the whole group instead of each shortcut: the block-editing shortcut gate now requires a live editor input as well as |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Editing shortcuts do nothing when the editor input is gone
Pressing Alt+U (Ctrl+U on macOS, delete to the start of the line) right as the block editor closed threw an uncaught
Found by a local key fuzzer that records uncaught page errors. The same could happen with Alt+K (delete to the end of the line), Alt+D / Ctrl+W, Alt+W (delete word forward / backward) and the forward and backward word movement shortcuts.
Cause
These shortcuts run only while
state/editing?is true, but that flag stays true for a moment after the textarea has left the DOM (the block was just deleted, the editor closed), sostate/get-inputreturns nil. Their handlers (kill-line-before!,kill-line-after!,forward-kill-word,backward-kill-word,cursor-forward-word,cursor-backward-word) pass that nil to helpers that read(.-value input).Change
src/main/frontend/modules/shortcut/config.cljswraps these handlers inwhen-editing-input, which calls the handler only whenstate/get-inputreturns an element and otherwise does nothing.Tests
src/test/frontend/modules/shortcut/config_test.cljs: calls each of these shortcut fns withstate/get-inputredefined to return nil and asserts none of them throws; the Alt+U one throws on master.CI's unit suite and lint pass locally.