state/editing? outlives the editor's textarea

Open
#1,481 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Refactor
Clarity
Needs clarification
Activity status
Active
Domain
backend

Research direction

Read the :editor/editing? state and state/get-input callers, then trace the editor component lifecycle and the shortcut and CodeMirror paths described in the issue. Compare the two proposed meanings of editing? and identify which callers need each; done means maintainers have chosen a consistent state contract that prevents stale textarea access.

Written by the indexing model from the issue text.

Description

state/editing? outlives the editor's textarea

state/editing? (:editor/editing?) can stay true for a moment after the block editor's textarea has left the DOM: the block was just deleted, the editor closed, a re-render replaced it. In that window state/get-input returns nil while everything that asks editing? still treats the user as editing. Code that trusts editing? and then reads the textarea throws.

A local key fuzzer that records uncaught page errors found this through several entry points:

  • block-editing shortcuts (Alt+E, Alt+A, Alt+U, Alt+K, the word movement and word delete shortcuts): fixed for the whole shortcut group in #13865 by requiring a live input in the group's gate;
  • Up/Down at the edge of a code block (CodeMirror's own key handler, outside the shortcut gate): get-prev-block-non-collapsed got a nil block (also in #13865);
  • earlier, cursor helpers and paste handlers reached through other paths.

#13865 removes the crashes but leaves the state as it is: any new code that checks editing? and reads the textarea can hit the same thing.

The design question

Should editing? mean "a block editor textarea is mounted"? Options:

  • clear :editor/editing? when the editor component that set it unmounts without another taking over (care is needed for re-renders that unmount and remount the same editor);
  • or define editing? as (some? (get-input)) for callers that act on the textarea, and keep the current flag for callers that only need "a block is being edited".

This touches editing state everywhere, so it is a question for the maintainers rather than a patch.

Dominant language
No language data
Stars
29
Forks
2
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from logseq/db-test

All issues in logseq/db-test

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.