Refactor: generalize CanvasHistory into BoundedHistory<T> for image undo#7
Merged
Merged
Conversation
…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 (#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
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
Follow-up to #6. The annotation undo/redo now lives in
CanvasHistory, but the image-level undo/redo was still two loose@State [NSImage]arrays (imageUndoStack/imageRedoStack) with inline push / cap-at-20 / pop logic inEditorView— duplicating the exact rules #6 just extracted.This generalizes
CanvasHistoryintoBoundedHistory<Snapshot>and uses it for both:EditorView's image stack handling collapses from inline array bookkeeping to:Scope / safety
undo()/redo()— image is best-effort (if let), canvas keeps its guarded return — matching the prior ordering exactly.CanvasHistoryis now a typealias, so Refactor: extract annotation undo/redo into CanvasHistory #6's call sites andCanvasHistoryTestsare untouched.Tests
BoundedHistoryTests(4 cases) pins the generic behavior withInt(mirroring theNSImageuse): record/undo/redo round-trip, record-clears-redo, nil-on-empty, and cap-drops-oldest at limit 20.CanvasHistoryTests(7) continues to cover theCanvasStateinstantiation.🤖 Generated with Claude Code
Generated by Claude Code