Skip to content

fix: prevent Ctrl+Z from reverting to default content after note load#74

Merged
j4rviscmd merged 1 commit intomainfrom
fix/suppress-undo-on-load
Mar 27, 2026
Merged

fix: prevent Ctrl+Z from reverting to default content after note load#74
j4rviscmd merged 1 commit intomainfrom
fix/suppress-undo-on-load

Conversation

@j4rviscmd
Copy link
Copy Markdown
Owner

Summary

  • Suppress undo history recording during programmatic note content loading (replaceBlocks / backfillImageCaptions)
  • Extract duplicated image-caption fallback logic into a shared getImageCaptionFallback helper

Problem

After opening a note, pressing Ctrl+Z would revert the editor content back to the default "Welcome to Scripta" blocks. This happened because replaceBlocks dispatched a ProseMirror transaction that prosemirror-history recorded as an undoable step.

Solution

Added withSuppressedHistory(view, fn) which temporarily patches view.dispatch to attach addToHistory: false metadata on every transaction during the callback. The original dispatch is always restored via try/finally.

Test plan

  • Open an existing note and press Ctrl+Z — should not revert to default content
  • Open an existing note, type text, then press Ctrl+Z — typed text should be undone
  • Create a new note (no noteId) and verify undo works normally

🤖 Generated with Claude Code

When a note is loaded from the database, `replaceBlocks` dispatches a
ProseMirror transaction that prosemirror-history records as an undoable
step. Pressing Ctrl+Z after loading would revert the editor back to the
default "Welcome to Scripta" content.

This change wraps all content-loading transactions (replaceBlocks and
backfillImageCaptions) with `withSuppressedHistory`, which temporarily
patches `view.dispatch` to add `addToHistory: false` metadata. The
original dispatch is restored via try/finally.

Also extracts the duplicated image-caption fallback logic into a shared
`getImageCaptionFallback` helper.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@j4rviscmd j4rviscmd added the bug Something isn't working label Mar 27, 2026
@j4rviscmd j4rviscmd merged commit 48ddeea into main Mar 27, 2026
2 checks passed
@j4rviscmd j4rviscmd deleted the fix/suppress-undo-on-load branch March 27, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant