Skip to content

feat: improve FileTree scroll and unicode width support - #38

Merged
unhappychoice merged 8 commits into
mainfrom
feat/improve-file-tree-scroll-and-unicode
Nov 11, 2025
Merged

unhappychoice merged 8 commits into
mainfrom
feat/improve-file-tree-scroll-and-unicode

Conversation

@unhappychoice

@unhappychoice unhappychoice commented Nov 11, 2025 •

Copy link
Copy Markdown
Owner

Summary

  • Add auto-scroll to FileTree to keep selected file visible in viewport center
  • Add caching mechanism to FileTree to avoid recalculating on every render
  • Add unicode width support for proper display of wide characters (CJK, emojis)
  • Fix cursor line background fill calculation in Editor
  • Unify file display order between FileTree and animation

Changes

FileTree

  • Add caching with set_commit_metadata() method
  • Add auto-scroll to keep selected file in center
  • Support unicode width for proper wide character handling

Animation

  • Track content width for accurate wrap calculation
  • Sort file changes to match FileTree display order
  • Add SwitchFile step for excluded/deleted/renamed files

Editor

  • Fix cursor line background fill using unicode width
  • Remove unnecessary complexity in fill calculation

UI & Git

  • Update UI to use FileTree caching
  • Add sorted_file_indices() to CommitMetadata

Test plan

  • cargo check
  • cargo test
  • cargo clippy
  • cargo fmt
  • Manual testing with various file names including wide characters

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Automatic exclusion of very large or generated/lock files from animations with clear exclusion reasons
  • Improvements

    • Accurate Unicode-aware text width handling across editor, dialogs, and lists
    • Improved file tree: stable sorting, wrapping-aware rendering, caching, and automatic scrolling to current file
    • Cursor line and editor padding now respect display width for correct alignment
    • Time-travel and file-switch behavior updated for smoother visual consistency

unhappychoice and others added 7 commits November 11, 2025 17:30
- 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]>
@coderabbitai

coderabbitai Bot commented Nov 11, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds 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

Cohort / File(s) Change Summary
Dependencies
Cargo.toml
Added unicode-width = "0.1" dependency for Unicode-aware width calculations.
Diff & Metadata
src/git.rs
Added pub exclusion_reason: Option<String> to FileChange; introduced MAX_CHANGE_LINES to mark large diffs as excluded; compute total_changed_lines from hunks; added CommitMetadata::sorted_file_indices() returning hierarchical display order.
Animation Engine
src/animation.rs
Added content_width field and set_content_width(); added calculate_line_display_height() and wrapping-aware display/scroll logic; emit SwitchFile before operations for Deleted/Renamed/Excluded files; use metadata.sorted_file_indices() for processing order; include exclusion reasons in skip messages; updated time-travel/file-switch/reset flows to align with display-order and wrapping.
Editor & UI rendering
src/panes/editor.rs, src/ui.rs
Editor uses UnicodeWidthStr::width() for cursor fill and right-edge padding. UI: render() now takes &mut self, initializes FileTreePane::new(), computes content_width for layout, calls engine.set_content_width(content_width), and uses Unicode-aware dialog width/padding.
File tree pane
src/panes/file_tree.rs
Converted to stateful FileTreePane with caching fields (cached_lines, cached_current_line_index, cached_total_display_lines, cached_metadata_id, cached_current_file_index, cached_content_width); added new() and set_commit_metadata(); render() signature changed to require &mut self and now uses cached lines; added wrapping, scroll-offset calculation, and stable directory/file sorting.

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)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • Pay close attention to cache invalidation in src/panes/file_tree.rs (metadata_id, content_width, current_file_index).
  • Verify Unicode width/wrapping edge cases in calculate_line_display_height() and editor padding.
  • Confirm sorted_file_indices() ordering is stable and that SwitchFile placement preserves intended animation semantics.
  • Check all call sites for UI::render() mutation signature change.

Possibly related PRs

Poem

🐰 I nudge the widths with gentle paws,
Lines wrap neat beneath my claws,
Trees remember what I cache and store,
Files switch tidy — hop, explore! 🥕📜

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.08% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: FileTree scroll improvements and unicode width support are core features across multiple files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/improve-file-tree-scroll-and-unicode

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 90aae09 and 5d9c685.

📒 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)

Comment thread src/panes/file_tree.rs Resolved
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]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/panes/file_tree.rs (1)

191-199: Minor optimization: avoid unnecessary clone.

The dir_text is cloned on line 193 to use it for width calculation after moving it into Span::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

📥 Commits

Reviewing files that changed from the base of the PR and between 5d9c685 and 2544422.

📒 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_width to 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_ceil with 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:

  1. Manually split the line into multiple Line objects with explicit background fills, or
  2. Accept the current behavior as a limitation of auto-wrapping with styled backgrounds

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.

1 participant