Skip to content

Return a snapshot from GetCommandsToUndo instead of a live query [patch] - #115

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/undoredo-95-snapshot-commands-to-undo
Sep 28, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/undoredo-95-snapshot-commands-to-undo

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #95

What was wrong

SaveBoundaryManager.GetCommandsToUndo returned a deferred Skip/Take over the live command list. It captured the count when it was called but read the list when the result was enumerated. So a caller that held the result while the stack changed got a mix of old and new state. After Undo() followed by a new Execute, the result listed the new command in place of the one it had replaced.

GetChangeVisualizations, the other method named in the issue, is already materialized on main ([.. commands.Skip(...)...]), so it needed no code change.

Change

  • SaveBoundaryManager.GetCommandsToUndo materializes its result ([.. query]). This also covers UndoRedoService.GetCommandsToUndo, which delegates to it.
  • New tests, one per method, that take the result, change the stack, and only then enumerate:
    • GetCommandsToUndo_EnumeratedAfterBranching_ReflectsStateAtCall fails on main (Expected:<A,B>. Actual:<A,C>) and passes with the fix.
    • GetChangeVisualizations_EnumeratedAfterExecute_ReflectsStateAtCall guards the existing snapshot behavior against a regression.

A note on the issue's third bullet: after a plain Undo(), a lazy result still reports [A, B], which is also the correct snapshot answer. The two only diverge when the underlying list changes, for example through a branch or a trim, so the test uses a branch.

Testing

  • dotnet test UndoRedo.Test: 102/102 pass.
  • Reverted the fix and re-ran the new test to confirm it fails without the change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TXZMdofSRgS8oXS9RgTRhM


Generated by Claude Code

GetCommandsToUndo returned a deferred Skip/Take over the live command
list, so a result enumerated after the stack branched listed the new
command in place of the one that was due to be undone. Materialize it,
as GetChangeVisualizations already does, and cover both with a test
that changes the stack between the call and the enumeration.

Fixes #95

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TXZMdofSRgS8oXS9RgTRhM
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 5938d1d into main Sep 28, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the claude/undoredo-95-snapshot-commands-to-undo branch September 28, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants