Skip to content

fix(editor): Escape or Shift+Up/Down keeps the editor a click opens during its save - #13636

Merged
tiensonqin merged 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/deferred-exit-keeps-new-edit
Oct 7, 2026
Merged

tiensonqin merged 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/deferred-exit-keeps-new-edit

Conversation

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor

Problem

A click on a block sometimes opens no editor: the block flashes into edit mode and is back to plain text at once. It happens when the click comes right after Escape or Shift+Up/Down at the first or last line of a block, before that key's save has finished.

Cause

escape-editing and select-block-up-down (the Shift+Up/Down exit at a block's edge) save the block first and wait for the save, which goes to the worker. Then they leave editing: clear-edit!, or exit-editing-and-set-selected-blocks!. A click on another block during the save opens that block's editor (pointerdown -> set-editing!); when the save settles, the exit clears the editing state again, now the new block's, and its editor unmounts.

In a run of the steps Escape or Shift+Up then a click, the events in order: pointerdown on the clicked block; focusin on its textarea; the previous editor removed; focusout on the clicked block's textarea; that textarea removed. Nothing is being edited afterwards.

Fix

Both exits note the editor they start from, and after the save leave editing only if that editor is still the open one. A click during the save keeps the editor it opened.

Test

frontend.handler.exit-editing-race-test, with the save held until the click has opened another editor:

  • Escape during the save: the clicked block's editor stays open. Fails on master.
  • Shift+Up at a block's edge during the save: the same. Fails on master.
  • Without a click, Escape still exits and Shift+Up still selects the block.

frontend.handler.editor-test passes (110 tests).

yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 6, 2026
…uring its save

## Problem

A click on a block sometimes opens no editor: the block flashes into edit mode and is back to plain text at once. It happens when the click comes right after Escape or Shift+Up/Down at the first or last line of a block, before that key's save has finished.

## Cause

`escape-editing` and `select-block-up-down` (the Shift+Up/Down exit at a block's edge) save the block first and wait for the save, which goes to the worker. Then they leave editing: `clear-edit!`, or `exit-editing-and-set-selected-blocks!`. A click on another block during the save opens that block's editor (pointerdown -> `set-editing!`); when the save settles, the exit clears the editing state again, now the new block's, and its editor unmounts.

In a run of the steps Escape or Shift+Up then a click, the events in order: pointerdown on the clicked block; focusin on its textarea; the previous editor removed; focusout on the clicked block's textarea; that textarea removed. Nothing is being edited afterwards.

## Fix

Both exits note the editor they start from, and after the save leave editing only if that editor is still the open one. A click during the save keeps the editor it opened.

## Test

`frontend.handler.exit-editing-race-test`, with the save held until the click has opened another editor:

- Escape during the save: the clicked block's editor stays open. Fails on master.
- Shift+Up at a block's edge during the save: the same. Fails on master.
- Without a click, Escape still exits and Shift+Up still selects the block.

`frontend.handler.editor-test` passes (110 tests).
@tiensonqin
tiensonqin force-pushed the fix/deferred-exit-keeps-new-edit branch from 7dd21d1 to c1b7094 Compare October 7, 2026 11:32
@tiensonqin
tiensonqin merged commit 1f5a4f1 into logseq:master Oct 7, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 8, 2026
devin-ai-integration Bot pushed a commit that referenced this pull request Oct 8, 2026
…uring its save (#13636)

## Problem

A click on a block sometimes opens no editor: the block flashes into edit mode and is back to plain text at once. It happens when the click comes right after Escape or Shift+Up/Down at the first or last line of a block, before that key's save has finished.

## Cause

`escape-editing` and `select-block-up-down` (the Shift+Up/Down exit at a block's edge) save the block first and wait for the save, which goes to the worker. Then they leave editing: `clear-edit!`, or `exit-editing-and-set-selected-blocks!`. A click on another block during the save opens that block's editor (pointerdown -> `set-editing!`); when the save settles, the exit clears the editing state again, now the new block's, and its editor unmounts.

In a run of the steps Escape or Shift+Up then a click, the events in order: pointerdown on the clicked block; focusin on its textarea; the previous editor removed; focusout on the clicked block's textarea; that textarea removed. Nothing is being edited afterwards.

## Fix

Both exits note the editor they start from, and after the save leave editing only if that editor is still the open one. A click during the save keeps the editor it opened.

## Test

`frontend.handler.exit-editing-race-test`, with the save held until the click has opened another editor:

- Escape during the save: the clicked block's editor stays open. Fails on master.
- Shift+Up at a block's edge during the save: the same. Fails on master.
- Without a click, Escape still exits and Shift+Up still selects the block.

`frontend.handler.editor-test` passes (110 tests).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 11, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 13, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
@yuxi-liu-wired
yuxi-liu-wired deleted the fix/deferred-exit-keeps-new-edit branch October 21, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants