Skip to content

fix(editor): Alt+Shift+Up/Down waits for a running Enter or Backspace/Delete join - #13603

Closed
yuxi-liu-wired wants to merge 3 commits into
logseq:masterfrom
yuxi-liu-wired:fix/move-waits-for-pending-edit
Closed

yuxi-liu-wired wants to merge 3 commits into
logseq:masterfrom
yuxi-liu-wired:fix/move-waits-for-pending-edit

Conversation

@yuxi-liu-wired

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

Copy link
Copy Markdown
Contributor

Alt+Shift+Up/Down pressed right after Enter, or right after a Backspace/Delete join, moves the wrong block or nothing.

On a page with blocks a, b, c, d, e:

  • Cursor at the start of d, Backspace (d joins c into "cd"), then Alt+Shift+Down right away: nothing moves.
  • Cursor at the end of c, Enter (a new empty block under c), then Alt+Shift+Down right away: c moves below the new empty block, which stays in place with the cursor in it. Alt+Shift+Up moves c above b.

Enter and the joins run in steps that each wait on the db worker; only the last step moves the editor to the new or joined block. A move pressed before that takes the block that was split or deleted.

The pending Enter now carries a promise that settles when it has moved the editor (or failed), a running join is recorded the same way, and move-up-down waits for both before it takes the edited block. With neither running, the move starts as before.

Measured with real key events, the move key a fixed time after Backspace or Enter: before, 24 of 24 presses missed 20 ms after Backspace and 16 of 16 moved the wrong block 20 ms after Enter (2 of 24 and 3 of 16 at 40 ms). After, 0 at 0, 20 and 40 ms. frontend.handler.editor-test, frontend.handler.editor-async-test and frontend.handler.editor-lifecycle-test pass.

A second commit closes 2 gaps found in review:

  • An Enter whose insert succeeds without its editor callback (the transaction skips it when the route or graph changed meanwhile) now ends anyway, once the transaction is done; before, Enter stayed blocked and moves waited for good. Each Enter carries a token, so finishing an earlier Enter never ends a later one.
  • A Backspace or Delete join counts as running from its keydown, including the lookup of the previous / next block that comes before the join itself; a move pressed during that lookup waited for nothing.

New tests in frontend.handler.editor-test: enter-ends-when-its-insert-succeeds-without-the-editor-callback-test and backspace-join-is-pending-during-its-sibling-lookup-test (both fail without the second commit). frontend.handler.editor-test, frontend.modules.outliner.core-test, frontend.handler.paste-test, frontend.components.editor-test and frontend.handler.block-test pass.

Replaces #13600 and #13601.

@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 2 potential issues.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment on lines +318 to +321
(defonce ^:private *pending-new-block-done
;; Resolves when the pending Enter (insert-new-block!) has moved the editor
;; to the new block, or failed
(atom nil))

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.

🔴 Enter and move shortcuts freeze after navigation

When navigation finishes before an Enter insertion, clear-pending-new-block! never runs. apply-outliner-ops skips the editor callback after a route change, leaving Enter blocked and moves waiting indefinitely.

Learn more

The pending Enter is registered before insertion starts and only resolves when clear-pending-new-block! runs. The insertion's successful path clears it in inserted-block-edit-fn, while failure clears it in insert-new-block!. apply-outliner-ops skips the callback when the route or repo changes, but still resolves the transaction successfully. The pending state and promise therefore remain forever on the new route.

Example: Press Enter on page A, navigate to page B while the worker is inserting, then press Enter or Alt+Shift+Down. The insertion on A succeeds without its editor callback; Enter on B is ignored and the move never starts.

Recommended fix: Ensure the pending state and promise settle on every successful transaction path where :editor/edit-block-fn does not run, including context changes. Avoid clearing state belonging to a later Enter when completing an earlier insertion.

Devin Review


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

Comment thread src/main/frontend/handler/editor.cljs Outdated
Comment on lines +997 to +1002
(defn delete-block-inner!
[repo editor-state]
(let [p (delete-block-inner-aux! repo editor-state)
;; settles when the join is done or failed, never rejects
settled (-> (p/resolved p) (p/catch (constantly nil)))]
(reset! *pending-block-delete settled)

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.

🔴 Moves race Backspace's sibling lookup

When Backspace starts a join, delete-block-inner! does not register it until the preceding sibling lookup finishes. delete-block-when-zero-pos! leaves moves free to target the block about to be deleted.

Learn more

Backspace at position zero calls delete-block-when-zero-pos!, which first awaits <left-sibling-or-parent to check whether the join is allowed. Only after that lookup does it call delete-block-inner!, where the new pending marker starts. A move during the lookup sees no pending delete and uses the still-edited source block. Delete-at-end similarly fetches the current and next blocks in delete-concat before registering the join.

Example: With blocks c and d, press Backspace at the start of d and Alt+Shift+Down while the sibling lookup is running. The move operates on d rather than waiting to move c after the join.

Recommended fix: Track the entire join operation from its initiating handler, including prerequisite lookups, and resolve the marker on completion or failure; keep the eligibility checks intact.

Devin Review


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

yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 8, 2026
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
…/Delete join

Enter inserts a block, and Backspace at the start of a block (or Delete
at the end of one) joins two blocks, in steps that each wait on the db
worker; only the last step moves the editor to the new or joined block.
Until then the edit state names the block that was split or deleted. A
move pressed in between took that block:

- right after a Backspace join, the move was for the deleted block and
  nothing moved;
- right after Enter at the end of c, the move moved c instead of the new
  empty block (Down: c below the new block; Up: c above b).

The pending Enter now carries a promise that settles when it has moved
the editor (or failed), a running join is recorded the same way, and
move-up-down waits for both before it takes the edited block. With
neither running, the move starts as before.
…ding from its keydown

- The insert's transaction skips the editor callback when the route or
  graph changed meanwhile; the Enter then never ended, Enter stayed
  blocked and moves waited for good. It now ends once the transaction is
  done when its callback did not run; a token keeps an earlier Enter from
  ending a later one.
- Backspace / Delete looked up the previous / next block before the join
  was registered, so a move during the lookup did not wait. The join is
  now tracked from its keydown.
@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Combined with the other PRs that change the same files into #13782.

@yuxi-liu-wired
yuxi-liu-wired deleted the fix/move-waits-for-pending-edit branch October 21, 2026 18:02
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.

1 participant