Skip to content

feat: add SelectableParagraph widget with dim effect - #41

Merged
unhappychoice merged 10 commits into
mainfrom
feat/selectable-paragraph-with-dim
Nov 11, 2025
Merged

unhappychoice merged 10 commits into
mainfrom
feat/selectable-paragraph-with-dim

Conversation

@unhappychoice

@unhappychoice unhappychoice commented Nov 11, 2025 •

Copy link
Copy Markdown
Owner

Summary

  • Add custom SelectableParagraph widget to replace ratatui's Paragraph
  • Migrate all panes (Editor, FileTree, StatusBar, Terminal) to use the new widget
  • Add distance-based dimming effect to Editor and FileTree

Changes

New Widget: SelectableParagraph

  • Character-boundary wrapping (instead of word-boundary)
  • Unicode width support for CJK characters and emojis
  • Wrap-aware padding (first line vs continuation lines)
  • Line selection with customizable background/foreground styles
  • Distance-based dimming effect with configurable opacity
  • Preserves child element styles (z-index priority)

Refactoring Benefits

  • Editor: Reduced by ~100 lines, removed manual background fill and opacity logic
  • FileTree: Simplified wrap calculation, fixed line index tracking for selection
  • StatusBar/Terminal: Consistent padding and wrap behavior
  • All panes now share common text rendering infrastructure

Technical Details

Wrap-aware Padding

The widget handles three rendering modes:

  1. No wrap: Apply both left and right padding
  2. First wrap line: Apply left padding only, extend to right edge
  3. Continuation lines: No padding, use full width

Child Element Priority

Child elements (spans with their own bg/fg) take precedence over parent selection styles, ensuring proper rendering of special elements like cursors.

Dim Effect

  • Center line: full brightness (opacity 1.0)
  • Gradually fades to minimum opacity (0.6) over 20 lines
  • Applied to foreground colors only
  • Used in both Editor (cursor line center) and FileTree (selected file center)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Line selection highlighting across panes with selectable-line styling
    • Cursor/current-line highlighting in the editor
    • Reusable selectable-paragraph widget powering selectable lines and per-line dimming
  • Refactor

    • Unified rendering across editor, file tree, status bar, and terminal for consistent styling, padding, and selection support
    • Simplified file-tree and line layout for more compact, predictable rendering

unhappychoice and others added 5 commits November 11, 2025 21:20
When content width exceeds area width and lines wrap to multiple rows,
only the last wrapped row should be filled to the right edge.

Changes:
- Calculate wrapped line count: content_width.div_ceil(area_width)
- Calculate total space needed: wrapped_lines * area_width
- Fill remaining space: total_space_needed - content_width
- Fix FileTree stats calculation: use individual additions_str and deletions_str
  instead of combined stats_str to avoid off-by-one error

This ensures proper background rendering for:
- FileTree: directory headers, selected files, and normal files
- Editor: cursor lines

Example: content_width=120, area_width=50
- Wraps to 3 lines (50 + 50 + 20 chars)
- Last line needs 30 spaces fill (50 - 20 = 30)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add custom SelectableParagraph widget to replace ratatui's Paragraph with:
- Character-boundary wrapping instead of word-boundary wrapping
- Unicode width support for CJK characters and emojis
- Configurable padding with wrap-aware behavior
- Line selection with customizable styles
- Distance-based dimming effect

The widget preserves child element styles (z-index priority) and handles
three rendering modes: no wrap, first wrap line, and continuation lines.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Replace ratatui's Paragraph with SelectableParagraph in StatusBar and
Terminal panes. Move padding configuration from Block to widget for
consistent wrap behavior.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Replace manual background fill and wrap logic with SelectableParagraph.
Add distance-based dimming effect and fix line index tracking to properly
distinguish between pre-wrap line indices (for selection) and post-wrap
display line indices (for scroll calculation).

Changes:
- Remove manual background color application from each span
- Add cached_current_display_line_index for scroll calculation
- Use SelectableParagraph's selection and dim features
- Simplify wrap calculation to handle first line and continuation widths

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Replace manual cursor line background rendering and distance-based opacity
with SelectableParagraph's built-in features. Remove duplicate opacity
blending logic and simplify code significantly.

Changes:
- Remove manual padding, background fill, and wrap calculations
- Remove distance_opacity from HighlightContext
- Remove apply_opacity method (now in SelectableParagraph)
- Use SelectableParagraph's selection highlight and dim features
- Preserve cursor character rendering with proper z-index priority

This reduces Editor code by ~100 lines while maintaining all functionality.

🤖 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

Warning

Rate limit exceeded

@unhappychoice has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 20 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b8b1f56 and a852cdb.

📒 Files selected for processing (1)
  • src/widgets/selectable_paragraph.rs (1 hunks)

Walkthrough

Adds a new SelectableParagraph widget and migrates editor, file tree, status bar, and terminal panes to use it; simplifies per-line styling and removes several width/opacity parameters and related helpers. Imports mod widgets; in main.rs.

Changes

Cohort / File(s) Summary
Widget implementation
src/widgets/mod.rs, src/widgets/selectable_paragraph.rs
New SelectableParagraph widget with builder API: per-line lines, optional block, scroll, selected_line, selected_style, background_style, padding, dimming; implements wrapping, per-line dimming/opacity blending, and Widget rendering. SelectableParagraph re-exported in mod.rs.
Editor pane
src/panes/editor.rs
Replaced Paragraph with SelectableParagraph. Removed distance-based opacity and right-edge cursor fill. Updated signatures: fn build_line(...) -> Line<'_> (dropped content_width) and fn render_line_number(...) -> Span<'_> (dropped distance_opacity). Selection computed from cursor + scroll.
File tree pane
src/panes/file_tree.rs
Migrated rendering to SelectableParagraph; removed content-width/line-wrapping helpers and scroll-offset bookkeeping. Updated API: set_commit_metadata(...) drops content_width parameter; build_tree_lines(...) now returns (Vec<Line<'static>>, Option<usize>) (removed area_width and extra return values). Simplified per-line spans (add/del strings) and selection index handling.
Status bar pane
src/panes/status_bar.rs
Switched from Paragraph to SelectableParagraph; removed explicit Wrap, adjusted padding and background application to new widget style.
Terminal pane
src/panes/terminal.rs
Switched from Paragraph to SelectableParagraph; replaced manual padding struct usage with Padding::vertical(1) and adapted selection/cursor/last-line logic to the new widget.
UI integration
src/ui.rs
Call site updated to no longer compute/pass content_width when calling FileTreePane::set_commit_metadata.
Main module
src/main.rs
Added mod widgets; import to include the new widget module.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Pane as UI Pane (Editor/FileTree/Status/Terminal)
  participant Widget as SelectableParagraph
  participant TUI as Terminal Renderer

  Pane->>Widget: Build widget (lines, selected_line, styles, padding, dim)
  Widget-->>Pane: Configured widget (builder returned)
  Pane->>TUI: Render Block + Widget into area
  TUI->>Widget: Widget.render(area, buf)
  Widget->>TUI: Draw per-line spans (wrap, selection, dim, backgrounds)
  TUI-->>Pane: Buffer updated on screen
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Pay attention to:
    • SelectableParagraph rendering: wrap_line, apply_opacity, dimming math, and Widget impl correctness.
    • API signature changes in file_tree.rs (set_commit_metadata, build_tree_lines) and all call sites (e.g., src/ui.rs).
    • Editor pane changes around build_line and render_line_number (off-by-one or selection mapping).
    • Visual differences caused by removing opacity-based styling and full-width backgrounds.

Possibly related PRs

Poem

🐰 I hopped through spans and wrapped each line,
I marked the chosen one with a gentle shine,
Padding snug, dimmed edges soft as loam,
Widgets stitched the panes into a home. 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 clearly and concisely summarizes the main change: adding a new SelectableParagraph widget with a dim effect, which is the central purpose of this PR.

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: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 66d549c and 85810f0.

📒 Files selected for processing (7)
  • src/main.rs (1 hunks)
  • src/panes/editor.rs (6 hunks)
  • src/panes/file_tree.rs (9 hunks)
  • src/panes/status_bar.rs (3 hunks)
  • src/panes/terminal.rs (3 hunks)
  • src/widgets/mod.rs (1 hunks)
  • src/widgets/selectable_paragraph.rs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
src/panes/status_bar.rs (1)
src/widgets/selectable_paragraph.rs (1)
  • block (40-43)
src/panes/terminal.rs (1)
src/widgets/selectable_paragraph.rs (1)
  • block (40-43)
src/panes/editor.rs (3)
src/ui.rs (1)
  • new (47-68)
src/animation.rs (2)
  • new (50-64)
  • new (217-248)
src/widgets/selectable_paragraph.rs (1)
  • block (40-43)
src/panes/file_tree.rs (1)
src/widgets/selectable_paragraph.rs (1)
  • block (40-43)
⏰ 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
Comment thread src/widgets/selectable_paragraph.rs Resolved
Comment thread src/widgets/selectable_paragraph.rs Resolved
unhappychoice and others added 4 commits November 11, 2025 22:29
- Replace Japanese comments with English
- Remove unnecessary .clone() calls

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
SelectableParagraph handles all wrapping internally, so FileTree no longer
needs to:
- Calculate wrapped line counts
- Track display line indices for scroll
- Manage content width caching
- Provide scroll offsets

Also removed unused scroll feature from SelectableParagraph.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Implement automatic scrolling in SelectableParagraph to keep the selected
line centered in the viewport. The widget now:
- Calculates the display line position of the selected original line (after wrapping)
- Computes scroll offset to center the selected line
- Applies the offset when extracting visible lines

This handles all scrolling internally, so panes don't need to manage it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add guards to SelectableParagraph rendering to handle cases where the
terminal area is smaller than the configured padding. Previously, calling
buf.cell_mut().unwrap() would panic when attempting to write padding
outside the available area.

Changes:
- Replace all .unwrap() calls with proper Option handling
- Skip rendering when padding exceeds available width
- Use saturating_sub() to prevent underflow in width calculations

This fixes potential panics when the terminal is resized to very small
dimensions or when padding is larger than the available space.

🤖 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: 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 8da95db and b8b1f56.

📒 Files selected for processing (3)
  • src/panes/file_tree.rs (5 hunks)
  • src/ui.rs (0 hunks)
  • src/widgets/selectable_paragraph.rs (1 hunks)
💤 Files with no reviewable changes (1)
  • src/ui.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/widgets/selectable_paragraph.rs
🧰 Additional context used
🧬 Code graph analysis (1)
src/panes/file_tree.rs (1)
src/widgets/selectable_paragraph.rs (2)
  • new (25-36)
  • block (38-41)
🔇 Additional comments (5)
src/panes/file_tree.rs (5)

3-3: LGTM: Import changes align with SelectableParagraph migration.

The addition of SelectableParagraph and the updated widget imports correctly reflect the refactoring away from manual width calculations to the new widget-based approach.

Also applies to: 8-8


33-55: LGTM: Cleaner API without area_width dependency.

Removing the area_width parameter simplifies the API by delegating layout concerns to SelectableParagraph. The method now focuses solely on building content lines, while the widget handles rendering and wrapping at display time.


57-75: LGTM: SelectableParagraph configuration matches design.

The rendering setup correctly:

  • Separates vertical padding (Block) from horizontal padding (SelectableParagraph)
  • Uses selected_style for background only, preserving child span foreground colors
  • Applies the dimming effect with parameters matching the PR description (20 lines, 0.6 min opacity)

77-205: LGTM: Simplified line construction without manual wrapping.

The refactored build_tree_lines correctly:

  • Builds the directory tree structure and sorts entries
  • Tracks current_line_index at the right moment (line 160, before pushing the line)
  • Applies foreground styling to child spans based on is_current, letting SelectableParagraph handle background and dimming
  • Preserves status indicator colors (line 184) and stats colors (lines 191-196) independently of selection

1-206: Past review comment no longer applicable.

The previous review flagged incorrect wrapped-width calculations in calculate_wrapped_lines (mentioned lines 226-233, 291-298). This refactoring has addressed that concern by removing the manual wrapping logic entirely. SelectableParagraph now handles all text wrapping and layout internally with awareness of its own padding (line 72), eliminating the source of the original issue.

Comment thread src/panes/file_tree.rs Resolved
Apply rustfmt to wrap long lines for better readability.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@unhappychoice
unhappychoice merged commit 9e658ba into main Nov 11, 2025
@unhappychoice
unhappychoice deleted the feat/selectable-paragraph-with-dim branch November 11, 2025 13:57
@coderabbitai coderabbitai Bot mentioned this pull request Nov 26, 2025
4 tasks done
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