Skip to content

fix: isolate undo history for unsaved documents - #251

Open
Amandot wants to merge 1 commit into
petertzy:mainfrom
Amandot:fix/unsaved-document-undo
Open

fix: isolate undo history for unsaved documents#251
Amandot wants to merge 1 commit into
petertzy:mainfrom
Amandot:fix/unsaved-document-undo

Conversation

@Amandot

@Amandot Amandot commented Sep 13, 2026

Copy link
Copy Markdown

Description

Fixes the issue where Cmd+Z could unexpectedly clear content in newly created unsaved documents.

Root Cause

MonacoEditor was rendered without a path prop, causing different tabs to reuse the same Monaco text model and Undo/Redo history.

When switching between tabs, content synchronization could create synthetic edits in the shared Undo stack. As a result, pressing Cmd+Z could undo beyond the user's actual edits and unexpectedly clear or restore content from another document.

Fix

  • Give each editor tab a stable Monaco model identity using activeTab.id.
  • Pass the stable ID through EditorPane to Monaco as the path.
  • Keep the Monaco model identity unchanged when an unsaved document is saved.
  • Isolate Undo/Redo history between tabs.
  • Add Ctrl+Shift+Z support for Redo on non-Mac platforms.

Tests

Added regression tests covering:

  • Unsaved document Undo
  • Multiple Undo operations
  • Large content deletion and Undo
  • Edit → Undo → Save
  • Saved document Undo
  • Multiple tab/document isolation
  • Redo
  • Original root-cause reproduction

Verification

The following checks pass:

  • npm test
  • npm run lint
  • npx tsc --noEmit
  • npm run build

Fixes #247

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.

Fix Cmd+Z clearing content for unsaved documents in the editor

1 participant