Refactor: extract annotation undo/redo into CanvasHistory#6
Merged
Conversation
EditorView held the annotation undo/redo as two loose @State arrays plus inline push/cap/clear-redo and pop/apply logic. Move the stack ownership and rules into a testable CanvasHistory value type; the view records snapshots and applies the state CanvasHistory returns. Behavior-preserving (image-level undo stacks are unchanged). Adds CanvasHistoryTests (7 cases).
GamalAnwar
added a commit
that referenced
this pull request
Jun 17, 2026
…ndo (#7) Generalize CanvasHistory into BoundedHistory<Snapshot> and back the image-undo stack with it (BoundedHistory<NSImage>, limit 20) instead of inline @State arrays. CanvasHistory becomes a typealias, so #6's usage/tests are unchanged. Behavior- preserving: image and canvas histories pop independently. Adds BoundedHistoryTests (4 cases). CI green.
GamalAnwar
pushed a commit
that referenced
this pull request
Jun 18, 2026
…ndo too The image-level undo/redo was still two loose @State [NSImage] arrays with inline push/cap-at-20/pop logic in EditorView, duplicating the rules just extracted for the annotation canvas. Generalize CanvasHistory into BoundedHistory<Snapshot> (CanvasHistory becomes a typealias, so #6's usage and tests are unchanged) and back the image stack with BoundedHistory<NSImage>(limit: 20). Behavior-preserving: image and canvas histories are still popped independently in undo()/redo() (image best-effort, canvas guarded). Adds BoundedHistoryTests (4 cases) pinning the generic behavior with a non-CanvasState type.
GamalAnwar
added a commit
that referenced
this pull request
Jun 18, 2026
Move EditorView's annotation undo/redo (two loose @State arrays + inline push/cap/pop/apply) into a testable CanvasHistory value type. Behavior-preserving; image-level undo stacks unchanged. Adds CanvasHistoryTests (7 cases). CI green.
GamalAnwar
added a commit
that referenced
this pull request
Jun 18, 2026
…ndo (#7) Generalize CanvasHistory into BoundedHistory<Snapshot> and back the image-undo stack with it (BoundedHistory<NSImage>, limit 20) instead of inline @State arrays. CanvasHistory becomes a typealias, so #6's usage/tests are unchanged. Behavior- preserving: image and canvas histories pop independently. Adds BoundedHistoryTests (4 cases). CI green.
GamalAnwar
pushed a commit
that referenced
this pull request
Jun 18, 2026
…ndo too The image-level undo/redo was still two loose @State [NSImage] arrays with inline push/cap-at-20/pop logic in EditorView, duplicating the rules just extracted for the annotation canvas. Generalize CanvasHistory into BoundedHistory<Snapshot> (CanvasHistory becomes a typealias, so #6's usage and tests are unchanged) and back the image stack with BoundedHistory<NSImage>(limit: 20). Behavior-preserving: image and canvas histories are still popped independently in undo()/redo() (image best-effort, canvas guarded). Adds BoundedHistoryTests (4 cases) pinning the generic behavior with a non-CanvasState type.
GamalAnwar
added a commit
that referenced
this pull request
Jun 18, 2026
…ndo too The image-level undo/redo was still two loose @State [NSImage] arrays with inline push/cap-at-20/pop logic in EditorView, duplicating the rules just extracted for the annotation canvas. Generalize CanvasHistory into BoundedHistory<Snapshot> (CanvasHistory becomes a typealias, so #6's usage and tests are unchanged) and back the image stack with BoundedHistory<NSImage>(limit: 20). Behavior-preserving: image and canvas histories are still popped independently in undo()/redo() (image best-effort, canvas guarded). Adds BoundedHistoryTests (4 cases) pinning the generic behavior with a non-CanvasState type.
GamalAnwar
added a commit
that referenced
this pull request
Jun 18, 2026
Move EditorView's annotation undo/redo (two loose @State arrays + inline push/cap/pop/apply) into a testable CanvasHistory value type. Behavior-preserving; image-level undo stacks unchanged. Adds CanvasHistoryTests (7 cases). CI green.
GamalAnwar
added a commit
that referenced
this pull request
Jun 18, 2026
…ndo (#7) Generalize CanvasHistory into BoundedHistory<Snapshot> and back the image-undo stack with it (BoundedHistory<NSImage>, limit 20) instead of inline @State arrays. CanvasHistory becomes a typealias, so #6's usage/tests are unchanged. Behavior- preserving: image and canvas histories pop independently. Adds BoundedHistoryTests (4 cases). CI green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First substantive
EditorViewdecomposition slice (behavior-preserving).EditorViewheld the annotation undo/redo as two loose@Statearrays (undoStack/redoStack) plus inline push/cap-at-100/clear-redo and pop-and-apply logic. This moves the stack ownership and the rules into a dedicated, testableCanvasHistoryvalue type:The view now records snapshots and applies whatever state
CanvasHistoryreturns.Scope / safety
imageUndoStack/imageRedoStack) are intentionally left untouched — this slice is just the annotation history.undo()/redo()keep the exact same ordering (image pop first, then canvas state), and the empty-guard semantics are preserved via the optional return.Tests
CanvasHistoryTests(7 cases): empty state, record enables undo, undo returns previous + enables redo, redo swap, record clears redo, nil on empty, and cap-drops-oldest.🤖 Generated with Claude Code
Generated by Claude Code