Skip to content

fix(editor): editing shortcuts need a live editor input - #13865

Open
yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/editing-shortcuts-need-an-input
Open

yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/editing-shortcuts-need-an-input

Conversation

@yuxi-liu-wired

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

Copy link
Copy Markdown
Contributor

Editing shortcuts need a live editor input

state/editing? can stay true for a moment after the editor's textarea has left the DOM (the block was just deleted, the editor closed). In that window state/get-input returns nil while the shortcut handler still treats the user as editing, and every block-editing shortcut that reads the textarea throws an uncaught TypeError. A local key fuzzer that records uncaught page errors hit:

TypeError: Cannot read properties of null (reading 'setSelectionRange')   Alt+E, end of block
TypeError: Cannot read properties of null (reading 'value')               Alt+U, delete to line start
TypeError: Cannot read properties of null (reading 'getAttribute')        Up at the top of a code block

and the same holds for Alt+A, Alt+K, the word movement and word delete shortcuts and the rest of the block-editing group.

Change

  • frontend.modules.shortcut.before/enable-when-editing-mode!, the gate of the :shortcut.handler/block-editing-only group, now requires a live input as well as editing?. This covers the whole group, including shortcuts added to it later, instead of a nil check in each handler. :editor/escape-editing is exempt (:allow-without-input? true in its config), since it is what clears a leftover editing state.
  • Up/Down at the edge of a code block calls util/get-prev-block-non-collapsed from CodeMirror's own key handler, outside the shortcut gate. With the block element gone it passed nil to skip-same-top-blocks; it now returns nil for a nil block, as get-next-block-non-collapsed already does.

Tests

  • src/test/frontend/modules/shortcut/before_test.cljs: the gate with a leftover editing state (does not run), with escape's exemption, with a live input, and while not editing; and every shortcut of the block-editing group, installed the way the shortcut handler installs them, pressed with editing? true and no input: none throws (14 failures on master).
  • src/test/frontend/util_block_nav_test.cljs: the previous and next block of nil are nil (throws on master).

CI's unit suite and lint pass locally.

This replaces #13856 (a nil check in cursor/move-cursor-to) and #13861 (nil checks in six shortcut fns): the gate covers both, and every other shortcut of the group.


Devin Review

@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: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

`state/editing?` can stay true for a moment after the editor's textarea
has left the DOM (the block was just deleted, the editor closed), so
`state/get-input` returns nil while the shortcut handler still treats
the user as editing. The block-editing shortcuts were gated on
`editing?` alone and then read the missing textarea, throwing uncaught
TypeErrors; a local key fuzzer hit Alt+E (end of block, setSelectionRange
of null) and Alt+U (delete to line start, reading 'value' of null), and
the same holds for Alt+A, Alt+K, the word movement and word delete
shortcuts and the rest of the group.

enable-when-editing-mode!, the gate of the block-editing shortcut
group, now also requires a live input. escape-editing is exempt
(:allow-without-input? in its config), since it is what clears such a
leftover editing state.

Up/Down at the edge of a code block calls
util/get-prev-block-non-collapsed from CodeMirror's own key handler,
outside the shortcut gate; with the block element gone it passed nil to
skip-same-top-blocks (getAttribute of null). It now returns nil for a
nil block, as get-next-block-non-collapsed already did.

Tests: before_test runs the gate with a leftover editing state, with
escape's exemption, with a live input and while not editing, and every
shortcut of the block-editing group with editing? true and no input
(14 failures without the change); util-block-nav-test asks for the
previous and next block of nil.
@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/editing-shortcuts-need-an-input branch from 85337ba to 71e5f47 Compare November 19, 2026 12:01

This branch has not been deployed

No deployments
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