Repository navigation
fix(editor): Alt+Shift+Up/Down right after a Backspace join moves the joined block - #13600
yuxi-liu-wired wants to merge 1 commit into
Conversation
… joined block Backspace at the start of a block joins it into the block above in several steps that wait on the db worker; only the last one moves the editor to the joined block. A move pressed before that (Backspace, then Alt+Shift+Down within ~40 ms) took the deleted block as the edited one, sent a move for it, and nothing moved. A running Backspace or Delete join is now recorded until it has moved the editor, and a move waits for it before it takes the edited block.
… joined block (logseq#13600) The fork carries logseq#13600: a running Backspace or Delete join is recorded until it has moved the editor; a move waits for it. The move log notes when a move waited for a join.
| (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) |
There was a problem hiding this comment.
🔴 Immediate moves still miss early joins
When Alt+Shift+Up/Down follows Backspace or Delete before delete-block-inner! starts, <pending-block-delete resolves immediately. Both key handlers await earlier worker reads, so the move can still target the deleted block and do nothing.
Learn more
The promise is registered only after delete-block-inner-aux! begins. Backspace first awaits <left-sibling-or-parent in delete-block-when-zero-pos!, and Delete first awaits two block loads in delete-concat. During those waits, <pending-block-delete resolves immediately. A move launched then reads the old edit block and can race the pending deletion.
Example: At the start of block d, press Backspace and immediately Alt+Shift+Down while the left-sibling lookup is pending. The move sees no registered join and attempts to move d instead of the eventual merged block c.
Recommended fix: Register the entire eligible join operation before the first asynchronous preflight in delete-block-when-zero-pos! and delete-concat, then clear its tracking promise after the editor callback completes. Keep non-join key paths outside that gate.
Was this helpful? React with 👍 or 👎 to provide feedback.
| (reset! *pending-block-delete settled) | ||
| (p/then settled (fn [_] | ||
| (when (identical? @*pending-block-delete settled) | ||
| (reset! *pending-block-delete nil)))) |
There was a problem hiding this comment.
🟡 Overlapping joins release moves too early
If two joins overlap, delete-block-inner! replaces the first pending promise with the second. A move after the second finishes can race the first join and target its outdated edit block.
Learn more
The atom stores one join, not the set or chain of in-flight joins. Overlapping Backspace/ Delete handlers can both call delete-block-inner! before either finishes. The most recent join's cleanup leaves the atom empty even when an earlier join remains outstanding. The earlier join can still delete a block or set editor focus while a new move is running.
Example: Start a slow Backspace join on one block, then a faster Delete join on another before the first finishes. Once the Delete join finishes, Alt+Shift+Down stops waiting although the Backspace join is still in flight.
Recommended fix: Track all outstanding joins, or serialize them in a promise chain; let <pending-block-delete wait for every join that was started before the move. Account for the preflight operations as well.
Was this helpful? React with 👍 or 👎 to provide feedback.
…ogseq#13601) The fork carries logseq#13601: the pending Enter carries a promise that settles when it has moved the editor; a move waits for it (and for a running Backspace/Delete join, logseq#13600). The move log notes either wait.
… joined block (logseq#13600) The fork carries logseq#13600: a running Backspace or Delete join is recorded until it has moved the editor; a move waits for it. The move log notes when a move waited for a join.
…ogseq#13601) The fork carries logseq#13601: the pending Enter carries a promise that settles when it has moved the editor; a move waits for it (and for a running Backspace/Delete join, logseq#13600). The move log notes either wait.
… joined block (logseq#13600) The fork carries logseq#13600: a running Backspace or Delete join is recorded until it has moved the editor; a move waits for it. The move log notes when a move waited for a join.
…ogseq#13601) The fork carries logseq#13601: the pending Enter carries a promise that settles when it has moved the editor; a move waits for it (and for a running Backspace/Delete join, logseq#13600). The move log notes either wait.
… joined block (logseq#13600) The fork carries logseq#13600: a running Backspace or Delete join is recorded until it has moved the editor; a move waits for it. The move log notes when a move waited for a join.
…ogseq#13601) The fork carries logseq#13601: the pending Enter carries a promise that settles when it has moved the editor; a move waits for it (and for a running Backspace/Delete join, logseq#13600). The move log notes either wait.
… joined block (logseq#13600) The fork carries logseq#13600: a running Backspace or Delete join is recorded until it has moved the editor; a move waits for it. The move log notes when a move waited for a join.
…ogseq#13601) The fork carries logseq#13601: the pending Enter carries a promise that settles when it has moved the editor; a move waits for it (and for a running Backspace/Delete join, logseq#13600). The move log notes either wait.
On a page with blocks a, b, c, d, e: put the cursor at the start of d, press Backspace (d joins c, the cursor is in "cd"), then press Alt+Shift+Down right away. Nothing moves: the page stays a, b, cd, e. Alt+Shift+Up does the same. A second press moves the block.
Backspace at the start of a block joins it into the block above in several steps that each wait on the db worker; only the last one moves the editor to the joined block. Until then the edit state still names the deleted block. A move pressed in between loads that block (gone by then), sends a move for it, and the worker moves nothing.
A running Backspace or Delete join (
delete-block-inner!) is now recorded until it has moved the editor, andmove-up-downwaits for it before it takes the edited block. Without a join running, the move starts as before.Measured with real key events, 12 tries per direction, the move key a fixed time after Backspace: before, 24 of 24 presses moved nothing at 20 ms, 2 of 24 at 40 ms. After, 0 of 24 at 0 ms, 20 ms and 40 ms each.
frontend.handler.editor-test,frontend.handler.editor-async-testandfrontend.handler.editor-lifecycle-testpass.