Implement Advanced Undo/Redo with Visual History Timeline #113 #170
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.
This PR implements a comprehensive advanced undo/redo system with a visual history timeline, replacing the basic linear undo/redo functionality with a modern, tree-based history system that supports branching and visual navigation.
✨ Key Features Implemented
Replaced linear undo/redo lists with a tree structure supporting history branching
Each history node contains state diffs instead of full state snapshots for efficiency
Supports complex editing workflows with multiple branches
Expandable/collapsible timeline panel positioned on the right side of the canvas
Thumbnail previews of canvas states (200x150px at 0.5 pixel ratio)
Timestamps and descriptions for each history entry
Current state highlighting with visual indicators
Click any history item to instantly jump to that state
Maintains full history tree integrity during navigation
Supports both forward and backward navigation through complex editing paths
History size limited to 50 nodes to prevent memory issues
Asynchronous thumbnail generation using RepaintBoundary
State diffing reduces memory footprint significantly
Efficient tree traversal algorithms
Visual feedback for current position in history
Descriptive change summaries (e.g., "Added 2 text items", "Changed background color")
Seamless integration with existing undo/redo keyboard shortcuts
Drawing mode compatibility
🛠 Technical Implementation
New Files Created:
history_model.dart - HistoryNode and HistoryTree data structures
history_timeline.dart - Visual timeline widget with expand/collapse functionality
history_manager.dart - Core history management logic and utilities
history_test.dart - Unit tests for history functionality
Modified Files:
canvas_state.dart - Updated to use HistoryTree instead of linear lists
canvas_cubit.dart - Enhanced with thumbnail generation and tree-based navigation
canvas_screen.dart - Integrated history timeline widget
drawing_canvas.dart - Added canvas key for thumbnail capture
Key Technical Decisions:
RepaintBoundary: Used for efficient thumbnail generation without performance impact
State Diffing: Only stores changes between states, not full snapshots
Tree Structure: Supports branching history unlike traditional linear undo/redo
Async Operations: Thumbnail generation happens asynchronously to avoid UI blocking
🎯 Acceptance Criteria Met
✅ Visual timeline widget in the UI - Implemented as expandable right-side panel
✅ Thumbnail generation for canvas states - Using RepaintBoundary with optimized sizing
✅ Ability to jump to any point in history - Click-to-navigate functionality
✅ History branching support - Tree structure allows multiple editing paths
✅ Performance optimization for large histories - Size limits and efficient algorithms
🧪 Testing
Basic unit tests added for history tree functionality
Manual testing of undo/redo operations
Thumbnail generation verification
Timeline navigation testing
📱 UI/UX Improvements
Clean, modern timeline design that doesn't obstruct canvas
Intuitive expand/collapse behavior
Clear visual indicators for current state
Responsive design that works on different screen sizes
🔄 Backward Compatibility
Existing undo/redo keyboard shortcuts (Ctrl+Z, Ctrl+Shift+Z) still work
No breaking changes to existing API
Graceful fallback for edge cases
🚀 Future Enhancements
This foundation enables future features like:
History search and filtering
History export/import
Collaborative editing with shared history
Advanced branching with named branches
History compression for very long sessions