Skip to content

fix(editor): preserve command order across block insertion, undo, and redo - #14006

Open
megayu wants to merge 2 commits into
masterfrom
fix/serialize-editor-history
Open

megayu wants to merge 2 commits into
masterfrom
fix/serialize-editor-history

Conversation

@megayu

@megayu megayu commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Pressing Enter starts an asynchronous block insertion. If Undo arrives while the editor is still preparing that insertion, the worker can receive Undo first and undo an earlier edit.

Queue insertion, undo, and redo in input order for each graph. Each command waits for the preceding command to settle, including its asynchronous preparation. This also preserves repeated history commands that the previous debounce could coalesce.

While an insertion is pending, keep buffering ordinary text and exclude Ctrl/Cmd shortcut letters so they do not change the block being edited.

Validation

  • Added regression coverage for an insertion held during preparation followed by Undo and Redo, and for ordinary text versus Ctrl/Cmd shortcut letters during a pending insertion.
  • Ran the editor, editor lifecycle, and history test namespaces: 121 tests, 334 assertions, all passed.
  • Verified in a visible Electron client using separate persisted blocks containing Alder and Cypress. With Cypress, held the insertion's worker read until Enter, Undo, and Redo had all been received. No history request reached the worker before release. After release, the worker received insertion, undo, and redo in order, and the final text was Cypress.

Devin Review

@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.

Devin Review

Comment thread src/main/frontend/handler/editor.cljs Resolved

Copilot AI 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.

🟡 Changes recommended

Two moderate active issues remain around queued command rejection leaving the pending insertion state uncleared across graph switches, so the new graph can continue intercepting editor input incorrectly.

2 open issues
What changed in this PR

This PR serializes asynchronous block insertion, undo, and redo commands per graph so history operations cannot overtake pending insertion work, while preserving text buffering and shortcut behavior during insertion.

Changes:

  • Added a per-graph asynchronous command queue shared by insertion and history operations.
  • Replaced debounced undo/redo handling with queued commands that preserve repeated input order.
  • Added regression tests for command ordering, buffered text, and Ctrl/Cmd shortcut handling.
  • Review findings: graph switches can leave pending insertion state uncleared when queued insertion is rejected, and A→B→A switches can allow stale queued commands to run in the restored session.
File Description
src/​test/​frontend/​handler/​history_test.cljs Adds regression tests covering insertion, undo, and redo ordering while insertion preparation is delayed.
src/​test/​frontend/​handler/​editor_test.cljs Adds tests for buffering ordinary text and excluding Ctrl/Cmd shortcut letters during pending insertion.
src/​main/​frontend/​handler/​history.cljs Routes undo and redo operations through the shared asynchronous command queue.
src/​main/​frontend/​handler/​editor.cljs Queues Enter-triggered block insertion and filters shortcut input while insertion is pending.
src/​main/​frontend/​handler/​common/​editor.cljs Implements the per-graph asynchronous command queue and graph-state validation.

Review effort: Lite

Comment thread src/main/frontend/handler/editor.cljs Resolved
@megayu
megayu force-pushed the fix/serialize-editor-history branch from 257eb0b to 0a1b67b Compare November 17, 2026 04:11

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants