Repository navigation
fix(editor): cursor shortcuts do nothing when the editor is gone - #13856
yuxi-liu-wired wants to merge 1 commit into
Conversation
Alt+E (end of block) and Alt+A (beginning of block) call cursor/move-cursor-to-end and -start on (state/get-input). Their shortcut group only checks state/editing?, which is still true for a moment after the textarea left the DOM (the block was deleted, the editor closed), so get-input is nil and move-cursor-to threw "Cannot read properties of null (reading 'setSelectionRange')" as an uncaught error. A local key fuzzer hit it with Alt+E right after Backspace/PageUp. move-cursor-to, which every cursor helper goes through, does nothing for a nil input. cursor_test: moving the cursor with a nil input (move-cursor-to, move-cursor-to-end, move-cursor-to-start) returns nil instead of throwing (all three throw without the change); moving to the end of a focused input sets the selection to its length.
| (when (number? n) | ||
| ;; input is nil when the editor left the DOM before the caller ran (a shortcut such as alt+e right after | ||
| ;; the block was deleted or the editor closed): nothing to move | ||
| (when (and input (number? n)) |
There was a problem hiding this comment.
🔴 End-of-block shortcut still crashes
When the editor is gone, move-cursor-to-end reads the nil input before reaching this guard. Alt+E still throws, and its new regression test fails.
Learn more
The end-of-block helper computes the cursor position before calling the guarded function. move-cursor-to-end calls gobj/get on its input, which throws when state/get-input returns nil. The new test invokes that exact path, so it cannot pass even though direct calls to move-cursor-to with nil return nil.
Example: Delete a block, then press Alt+E while editor state remains active but state/get-input returns nil. move-cursor-to-end reads value on nil and throws instead of ignoring the shortcut.
Recommended fix: Guard nil before reading the input value in move-cursor-to-end, then verify the nil-input test and the Alt+E path.
Was this helpful? React with 👍 or 👎 to provide feedback.
|
|
|
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 |
Cursor shortcuts do nothing when the editor is gone
Alt+E (end of block) and Alt+A (beginning of block, both not bound on macOS) run
cursor/move-cursor-to-end/-starton(state/get-input). Their shortcut group only checksstate/editing?, which is still true for a moment after the textarea left the DOM (the block was just deleted, the editor closed), soget-inputreturns nil and the page gets an uncaughtFound by a local key fuzzer that records uncaught page errors: Alt+E right after Backspace / PageUp, in 2 of 28 runs.
Change
move-cursor-to(frontend.util.cursor), which every cursor helper goes through, does nothing when the input is nil.Tests
New
src/test/frontend/util/cursor_test.cljs:move-cursor-without-an-editor-is-a-no-op:move-cursor-to,move-cursor-to-endandmove-cursor-to-startwith a nil input return nil; on master all three throw the error above.move-cursor-to-sets-the-selection: moving to the end of a focused input still sets the selection to the text's length.CI's unit suite and lint pass locally.