Skip to content

fix(editor): cursor shortcuts do nothing when the editor is gone - #13856

Closed
yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/cursor-without-editor
Closed

yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/cursor-without-editor

Conversation

@yuxi-liu-wired

@yuxi-liu-wired yuxi-liu-wired commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

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 / -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 just deleted, the editor closed), so get-input returns nil and the page gets an uncaught

TypeError: Cannot read properties of null (reading 'setSelectionRange')
    at frontend.util.cursor/move-cursor-to
    at frontend.util.cursor/move-cursor-to-end
    at (shortcut :editor/end-of-block)
    at goog.ui.KeyboardShortcutHandler ...

Found 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-end and move-cursor-to-start with 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.


Devin Review

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.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Devin Review

(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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

move-cursor-to-end doesn't throw on a nil input before the guard: goog.object/get returns undefined for a null object ((gobj/get nil "value") → nil, so the position is (count nil) = 0), and the call reaches move-cursor-to, which now returns early. The uncaught error's stack confirms the throw was in move-cursor-to's .setSelectionRange, called from move-cursor-to-end. Locally move-cursor-without-an-editor-is-a-no-op errors 3 times on master (the setSelectionRange TypeError) and passes with this change.

@yuxi-liu-wired

Copy link
Copy Markdown
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 editing? (escape-editing exempt), so every shortcut of the group, including ones added later, does nothing once the textarea is gone. Closing to keep the fix for this class in one place.

@yuxi-liu-wired
yuxi-liu-wired deleted the fix/cursor-without-editor branch November 17, 2026 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant