Skip to content

Rebuild a saved command whose SerializeData() returned an empty string - #103

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/undoredo-92-empty-command-data
Sep 27, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/undoredo-92-empty-command-data

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #92

What was wrong

JsonUndoRedoSerializer.ConvertFromSerializableCommand fell back to PlaceholderCommand whenever Data was null or empty. ConvertToSerializableCommand only uses null, and only for commands that are not ISerializableCommand. "" is a normal SerializeData() result for a command with no parameters, such as "Clear all". Such a command came back as a placeholder, LoadStateAsync still returned true, and the first Undo() threw NotSupportedException.

Change

  • The placeholder is now selected only when Data is null. An empty string goes through the normal Activator.CreateInstance + DeserializeData("") path, and inherits the error handling Report every unloadable saved command as a failed load #99 added to that path.
  • The null-forgiving Data! on the DeserializeData call is gone, because flow analysis now proves Data is non-null there.

Tests

  • UndoRedoService_SaveLoadState_ReconstructsCommandWithEmptyData saves a parameterless command whose SerializeData() returns "" and loads it into a fresh service. It then checks that the command comes back as its real type and that UndoAsync() succeeds.
  • With the library change reverted, this test fails: the command loads as a placeholder. With the change, it passes.
  • The full suite passes locally, 91 of 91.

🤖 Generated with Claude Code

https://claude.ai/code/session_018fKEEvMM2dQpZfMjTCXhRL


Generated by Claude Code

ConvertFromSerializableCommand treated an empty Data the same as a null
one and loaded a PlaceholderCommand, so a parameterless ISerializableCommand
came back un-undoable even though the load reported success. Only a null
Data, which ConvertToSerializableCommand writes for commands that are not
ISerializableCommand, now selects the placeholder.

Fixes #92

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

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit cf1dc78 into main Sep 27, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the claude/undoredo-92-empty-command-data branch September 27, 2026 15:11
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.

Loading a saved ISerializableCommand whose SerializeData() returned "" gives back an un-undoable PlaceholderCommand

2 participants