diff: Highlight and navigate inactive files
45bd4683b3274a68f9e0bffa23c00fca8aa141dc
Collapsed files must remain reachable through hunk navigation. Sticky file chrome must reflect the same active state as each card. Assisted-by: Codex:gpt-5.6
1 parent
96f8631a
crates/diff/src/viewer.rs
+32 -3
| 1674 | 1674 | } else { |
|
| 1675 | 1675 | line |
|
| 1676 | 1676 | }; |
|
| 1677 | 1677 | return Some(RenderRow { line, diff: None }); |
|
| 1678 | 1678 | } |
|
| 1679 | - | self.file_row_location(row) |
|
| 1680 | - | .map(|location| self.render_file_row(location, cols)) |
|
| 1679 | + | self.file_row_location(row).map(|location| { |
|
| 1680 | + | let file = location.file.id; |
|
| 1681 | + | let mut row = self.render_file_row(location, cols); |
|
| 1682 | + | if self.dims_unfocused_file(file) { |
|
| 1683 | + | row.line = Self::muted_line(row.line); |
|
| 1684 | + | } |
|
| 1685 | + | row |
|
| 1686 | + | }) |
|
| 1681 | 1687 | } |
|
| 1682 | 1688 | ||
| 1683 | 1689 | /// Returns one rendered row inside a file card. |
|
| 1684 | 1690 | fn render_file_row(&self, location: FileRowLocation<'_>, cols: usize) -> RenderRow { |
|
| 1685 | 1691 | let file = location.file; |
| 1985 | 1991 | /// Returns sticky file-header rows for the current offset. |
|
| 1986 | 1992 | fn sticky_rows(&self, scroll: usize, visible_rows: usize, cols: usize) -> Vec<Line> { |
|
| 1987 | 1993 | // Build the fixed sticky header strip directly from current scroll context. |
|
| 1988 | 1994 | self.sticky_header_rows(scroll, visible_rows) |
|
| 1989 | 1995 | .map(|sticky| { |
|
| 1996 | + | let inactive = self |
|
| 1997 | + | .file_row_location(sticky.start) |
|
| 1998 | + | .is_some_and(|location| self.dims_unfocused_file(location.file.id)); |
|
| 1990 | 1999 | (STICKY_HEADER_ROWS - sticky.rows..STICKY_HEADER_ROWS) |
|
| 1991 | 2000 | .map(|index| { |
|
| 1992 | 2001 | if index == STICKY_HEADER_ROWS - 1 { |
|
| 1993 | - | FILE_BORDER.divider(cols.saturating_sub(2), STICKY_DIVIDER) |
|
| 2002 | + | let line = FILE_BORDER.divider(cols.saturating_sub(2), STICKY_DIVIDER); |
|
| 2003 | + | if inactive { |
|
| 2004 | + | Self::muted_line(line) |
|
| 2005 | + | } else { |
|
| 2006 | + | line |
|
| 2007 | + | } |
|
| 1994 | 2008 | } else { |
|
| 1995 | 2009 | self.render_row(sticky.start + index, cols) |
|
| 1996 | 2010 | .map(|row| row.line) |
|
| 1997 | 2011 | .unwrap_or_default() |
|
| 1998 | 2012 | } |
| 2126 | 2140 | row: indexed.start, |
|
| 2127 | 2141 | height: 1, |
|
| 2128 | 2142 | file_start: indexed.start, |
|
| 2129 | 2143 | }); |
|
| 2130 | 2144 | } |
|
| 2145 | + | if filter == FocusFilter::HunkNavigation && file.hunks.is_empty() { |
|
| 2146 | + | targets.push(FocusTarget { |
|
| 2147 | + | focus: DiffFocus::File(file.id), |
|
| 2148 | + | row: indexed.start + FILE_HEADER_ROW, |
|
| 2149 | + | height: 1, |
|
| 2150 | + | file_start: indexed.start, |
|
| 2151 | + | }); |
|
| 2152 | + | } |
|
| 2131 | 2153 | if filter == FocusFilter::HunkNavigation { |
|
| 2132 | 2154 | for (hunk, local) in file.hunk_body_rows(self.hunk_gaps(file.id)) { |
|
| 2133 | 2155 | let leading = hunk |
|
| 2134 | 2156 | .lines |
|
| 2135 | 2157 | .iter() |
| 2389 | 2411 | fn dims_unfocused(&self, target: DiffFocus) -> bool { |
|
| 2390 | 2412 | self.options.hunk_focus == HunkFocus::DimUnfocused |
|
| 2391 | 2413 | && matches!(self.state.focus, Some(focus) if focus != target) |
|
| 2392 | 2414 | } |
|
| 2393 | 2415 | ||
| 2416 | + | /// Returns whether focus styling should dim a file card. |
|
| 2417 | + | fn dims_unfocused_file(&self, file: FileId) -> bool { |
|
| 2418 | + | self.options.hunk_focus == HunkFocus::DimUnfocused |
|
| 2419 | + | && self.state.focus.is_some() |
|
| 2420 | + | && self.focused_file() != Some(file) |
|
| 2421 | + | } |
|
| 2422 | + | ||
| 2394 | 2423 | /// Returns a row with every label rendered dimly. |
|
| 2395 | 2424 | fn muted_line(line: Line) -> Line { |
|
| 2396 | 2425 | line.into_iter() |
|
| 2397 | 2426 | .map(|label| { |
|
| 2398 | 2427 | let style = label |
a.rs
+0 -0
image.png
+0 -0
a.rs
+0 -0
b.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
b.rs
+0 -0
crates/diff/tests/golden/sticky_header_before_next_file_64x5.txt
+0 -0
src/a.rs
+0 -0
src/b.rs
+0 -0
README.md
+0 -0
src/app/a.rs
+0 -0
src/lib/b.rs
+0 -0
README.md
+0 -0
a.rs
+0 -0
b.rs
+0 -0
assets/css/style.css
+0 -0
assets/css/style.css
+0 -0
first.rs
+0 -0
second.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
b.rs
+0 -0
a.rs\n",
+0 -0
new.rs\n",
+0 -0
a\n\
+0 -0