Repository navigation
fix(editor): Alt+Shift+Up/Down waits for a running Enter or Backspace/Delete join - #13603
yuxi-liu-wired wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Devin Review found 2 potential issues.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| (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)) |
There was a problem hiding this comment.
🔴 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
| (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) |
There was a problem hiding this comment.
🔴 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
…/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.
2b91ad0 to
e6663f9
Compare
|
Combined with the other PRs that change the same files into #13782. |
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:
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-downwaits 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-testandfrontend.handler.editor-lifecycle-testpass.A second commit closes 2 gaps found in review:
New tests in
frontend.handler.editor-test:enter-ends-when-its-insert-succeeds-without-the-editor-callback-testandbackspace-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-testandfrontend.handler.block-testpass.Replaces #13600 and #13601.