Skip to content

Keep the original file state an undo boundary - #625

Open
mika76 wants to merge 1 commit into
AvaloniaUI:masterfrom
mika76:undo-continue-after-save
Open

mika76 wants to merge 1 commit into
AvaloniaUI:masterfrom
mika76:undo-continue-after-save

Conversation

@mika76

@mika76 mika76 commented Nov 5, 2026 •

Copy link
Copy Markdown

UndoStack.MarkAsOriginalFile() doesn't stop the next StartContinuedUndoGroup() from joining the undo group before it. So changes made after a save merge into the saved undo step:

  • IsOriginalFile stays true although the document was changed;
  • one undo goes back past the saved state.
var doc = new TextDocument();
doc.Insert(0, "a");
doc.UndoStack.MarkAsOriginalFile();      // saved: "a"
doc.UndoStack.StartContinuedUndoGroup();
doc.Insert(1, "b");
doc.UndoStack.EndUndoGroup();
// doc.UndoStack.IsOriginalFile is true, the text is "ab"
doc.UndoStack.Undo();
// the text is "", not the saved "a"

The fix: MarkAsOriginalFile stops continuation, as Undo, Redo and ClearAll already do. Groups after the save still continue each other.

Tests in UndoStackTests: not original after continuing past a save, undo returns to the saved state, and later groups still continue.

625

MarkAsOriginalFile didn't stop the next StartContinuedUndoGroup from joining the group before it. Changes made after a save then merged into the saved undo step: IsOriginalFile stayed true while the document was modified, and one undo went back past the saved state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant