diff: Respect hunk focus mode

e88c425c548144ae09f719d133303deed9c8b778
Keep plain diff rendering unchanged when callers set hunk focus.
Only render focused line numbers and gutter markers when the viewer is
configured to dim unfocused hunks.

Assisted-by: Codex:gpt-5.6-sol
Alexis Sellier committed ago 1 parent eb5a470e
crates/diff/src/viewer.rs +4 -4
2323 2323
        old_line: u32,
2324 2324
        row_cols: usize,
2325 2325
        decoration: &HunkDecoration,
2326 2326
        focus_row: bool,
2327 2327
    ) -> RenderRow {
2328 -
        let line_number_fg = if matches!(self.state.focus, Some(DiffFocus::Hunk(focused)) if focused == meta.hunk)
2329 -
        {
2328 +
        let focused_hunk = self.options.hunk_focus == HunkFocus::DimUnfocused
2329 +
            && matches!(self.state.focus, Some(DiffFocus::Hunk(focused)) if focused == meta.hunk);
2330 +
        let line_number_fg = if focused_hunk {
2330 2331
            SELECTED_LINE_NUMBER_FG
2331 2332
        } else {
2332 2333
            LINE_NUMBER_FG
2333 2334
        };
2334 2335
        let (cells, source, row_style, source_style) = match line.kind {
2381 2382
                Line::new(NO_NEWLINE_MARKER).style(Style::default().fg(colors::rgb::DIM)),
2382 2383
                Style::default(),
2383 2384
                Style::default(),
2384 2385
            ),
2385 2386
        };
2386 -
        let focused = focus_row
2387 -
            && matches!(self.state.focus, Some(DiffFocus::Hunk(hunk)) if hunk == meta.hunk);
2387 +
        let focused = focus_row && focused_hunk;
2388 2388
        let decoration = HunkRowDecoration {
2389 2389
            gutter: if matches!(line.kind, DiffLineKind::Addition | DiffLineKind::Deletion) {
2390 2390
                decoration.gutter
2391 2391
            } else {
2392 2392
                None
a.rs +0 -0
image.png +0 -0
image.png +0 -0
a.rs +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
first.rs +0 -0
second.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
crates/diff/tests/golden.rs +12 -0
33 33
            style: Some(Style::default().dim()),
34 34
        }
35 35
    }
36 36
}
37 37
38 +
#[test]
39 +
fn plain_hunk_focus_does_not_change_rendering() {
40 +
    let viewer = two_hunk_viewer();
41 +
    let mut focused = two_hunk_viewer();
42 +
    focused.set_focus(Some(DiffFocus::Hunk(HunkId::new(0))));
43 +
44 +
    assert_eq!(
45 +
        render_buffer(focused, 64, 12),
46 +
        render_buffer(viewer, 64, 12)
47 +
    );
48 +
}
49 +
38 50
#[test]
39 51
fn expanded_file_card_matches_golden_frame() {
40 52
    assert_golden(
41 53
        "expanded_file_card_64x9.txt",
42 54
        include_str!("golden/expanded_file_card_64x9.txt"),
a.rs +0 -0
a.rs +0 -0
crates/diff/tests/golden/focused_second_file_64x6.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮🮘
2 2
│ ⊙ b.rs 2 LOC                                          +1 -1 │🮘
3 3
├─────────────────────────────────────────────────────────────┤🮘
4 -
│ >1    1       keep                                          │▗
4 +
│  1    1       keep                                          │▗
5 5
│  2          - before                                        │▐
6 6
│       2     + after                                         │▝