Repository navigation
feat: improve FileTree scroll and unicode width support - #38
Conversation
- Add snapshot files (.snap, __snapshots__) to exclusion patterns - Limit animation to files with ≤2000 changed lines to prevent memory issues - Add exclusion_reason field to FileChange to show why files are skipped - Display specific exclusion reasons in terminal output 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…ulation Add unicode-width crate to handle wide characters (CJK, emojis) correctly when calculating display widths in terminal UI. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add sorted_file_indices() method that returns file indices sorted by directory and filename order, matching FileTree display order. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Add caching mechanism to avoid recalculating file tree on every render - Add auto-scroll to keep selected file visible in center of viewport - Support unicode width for proper display of wide characters - Add set_commit_metadata() method for explicit cache updates 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Add content_width tracking for proper wrap calculation - Use unicode width for accurate line height calculation - Sort file changes to match FileTree display order - Add SwitchFile step for excluded/deleted/renamed files 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Use unicode width instead of char count to calculate cursor line background fill accurately, fixing visual glitches with wide characters. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Call set_commit_metadata() before rendering FileTree - Update dialog width calculation to use unicode width - Update content_width tracking for animation engine 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
WalkthroughAdds Unicode-aware width handling across UI and panes, tracks content width in the animation engine, implements wrapping-aware display/scroll logic, introduces per-file exclusion reasons with a MAX_CHANGE_LINES guard, and makes file-change processing display-order aware while caching file-tree rendering. Changes
Sequence Diagram(s)sequenceDiagram
participant UI
participant Engine as AnimationEngine
participant Git as CommitMetadata
participant FileTree as FileTreePane
UI->>UI: measure layout -> content_width
UI->>Engine: set_content_width(content_width)
UI->>Engine: trigger commit animation
Engine->>Git: sorted_file_indices()
Git-->>Engine: ordered indices
loop per-file (in display order)
Engine->>Engine: decide exclusion (MAX_CHANGE_LINES / patterns)
alt Excluded
Engine->>Engine: Emit SwitchFile
Engine->>Engine: Emit Skip (with exclusion_reason)
else Deleted/Renamed
Engine->>Engine: Emit SwitchFile (old/new)
Engine->>Engine: Emit git add / apply steps
else Normal
Engine->>Engine: Apply hunks with wrapping-aware scroll
end
end
UI->>FileTree: set_commit_metadata(metadata, current_index, theme, content_width)
FileTree->>FileTree: build/cache wrapped lines if needed
UI->>FileTree: render(f, area, theme)
FileTree-->>UI: rendered viewport (wrapped, scrolled)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
Cargo.toml(1 hunks)src/animation.rs(7 hunks)src/git.rs(7 hunks)src/panes/editor.rs(5 hunks)src/panes/file_tree.rs(5 hunks)src/ui.rs(7 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/git.rs (3)
src/ui.rs (1)
new(47-68)src/animation.rs (2)
new(50-64)new(217-248)src/panes/file_tree.rs (1)
new(25-33)
src/panes/file_tree.rs (1)
src/ui.rs (2)
new(47-68)render(181-314)
src/ui.rs (2)
src/animation.rs (2)
new(50-64)new(217-248)src/panes/file_tree.rs (2)
new(25-33)render(61-85)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build (windows-latest)
Add content_width to cache invalidation logic to ensure tree is recalculated when terminal is resized. This fixes visual glitches where long lines would overflow or leave gaps after resize. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/panes/file_tree.rs (1)
191-199: Minor optimization: avoid unnecessary clone.The
dir_textis cloned on line 193 to use it for width calculation after moving it intoSpan::styled. You could calculate the width before the move to avoid this allocation.Apply this diff:
- let dir_text = format!("{}/", dir); + let dir_text = format!("{}/", dir); + let dir_width = dir_text.width(); lines.push(Line::from(vec![Span::styled( - dir_text.clone(), + dir_text, Style::default() .fg(theme.file_tree_directory) .add_modifier(Modifier::BOLD), )])); - display_line_count += Self::calculate_wrapped_lines(dir_text.width(), area_width); + display_line_count += Self::calculate_wrapped_lines(dir_width, area_width);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/panes/file_tree.rs(5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/panes/file_tree.rs (1)
src/ui.rs (2)
new(47-68)render(181-314)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build (windows-latest)
🔇 Additional comments (10)
src/panes/file_tree.rs (10)
16-23: Cache structure looks good.The struct now includes all necessary fields for caching, including
cached_content_widthto handle terminal resizes correctly.
26-35: LGTM!The constructor properly initializes all cache fields and provides a user-friendly placeholder message.
37-63: Cache invalidation now handles content_width changes correctly.The early return now checks
cached_content_width(line 49) and stores it (line 62), ensuring the tree is rebuilt when the terminal is resized. This fully addresses the previous review concern.
65-89: LGTM!The render method correctly uses cached data and implements scrolling to keep the current file visible. The visible height calculation properly accounts for padding.
91-113: LGTM!The scroll calculation correctly centers the current file in the viewport with proper bounds checking and edge case handling.
115-120: LGTM!The wrapping calculation correctly computes the number of display lines using
div_ceilwith proper edge case handling.
185-187: LGTM!Files are now correctly sorted by filename within each directory, ensuring consistent display order.
206-208: LGTM!Correctly tracks the starting line index for the current file before incrementing the display line count.
214-216: LGTM!Line width calculation correctly uses Unicode-aware width measurements for proper handling of wide characters.
254-259: Note: Wrapped current-file lines won't have full-width background.The background fill is only applied when
line_width < area_width, meaning it only fills the first line. If a file entry is long enough to wrap to multiple display lines, the wrapped portions will have background only behind the text, not extending to the right edge. This is likely acceptable given the constraint of working with ratatui's wrapping behavior, but be aware of the visual difference for long filenames.If this visual behavior is unintended, you would need to either:
- Manually split the line into multiple Line objects with explicit background fills, or
- Accept the current behavior as a limitation of auto-wrapping with styled backgrounds
Summary
Changes
FileTree
set_commit_metadata()methodAnimation
Editor
UI & Git
sorted_file_indices()to CommitMetadataTest plan
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Improvements