diff: Hunk focus, status file headers

94cd6ba53bd280a380b0b83e58d307a90012a687
Add a `HunkFocus` option that dims unfocused hunks, and render file
headers with the decorated status or file-kind marker. Remove
collapsible file cards and their actions, state, and keys. Navigate
hunks from the visible position, centering newly focused hunks and
preserving scroll otherwise. Reject empty highlight results for
non-empty rows and resolve highlight sources by file id so single-hunk
documents highlight correctly. Support `UPDATE_GOLDEN=1` to refresh
golden frames.

Assisted-by: Claude:fable-5
Alexis Sellier committed ago 1 parent ea8ec59c
crates/diff/benches/render.rs +5 -36
1 1
//! Render benchmarks for `rustik-diff`.
2 2
//!
3 3
//! The benchmark decodes deterministic unified diffs once, then exercises
4 -
//! render, scroll, resize, focus, collapse, highlight-request, and highlight-refresh paths.
4 +
//! render, scroll, resize, focus, highlight-request, and highlight-refresh paths.
5 5
6 6
use std::hint::black_box;
7 7
use std::io::{self, Write as _};
8 8
use std::str::FromStr;
9 9
use std::time::{Duration, Instant};
147 147
/// Named benchmark workload.
148 148
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
149 149
enum Workload {
150 150
    /// Original fixed-area, warm-cache, one-line scroll workload.
151 151
    WarmScroll,
152 -
    /// Mixed pager session with scrolling, navigation, resize, and collapse.
152 +
    /// Mixed pager session with scrolling, navigation, and resize.
153 153
    Session,
154 154
    /// Width-changing render workload.
155 155
    Resize,
156 156
    /// Scrolling offsets concentrated around file boundaries.
157 157
    Sticky,
158 -
    /// Focus and collapse workload across many files.
159 -
    Collapse,
160 158
    /// Visible syntax-highlight landing workload.
161 159
    Highlight,
162 160
    /// Visible highlight request scheduling without drawing rows.
163 161
    HighlightRequests,
164 162
    /// Steady-state render of word-diff overlays on a warm highlight cache.
180 178
            Self::All => vec![
181 179
                Self::WarmScroll,
182 180
                Self::Session,
183 181
                Self::Resize,
184 182
                Self::Sticky,
185 -
                Self::Collapse,
186 183
                Self::Highlight,
187 184
                Self::HighlightRequests,
188 185
                Self::WordDiff,
189 186
                Self::ManyFiles,
190 187
                Self::HugeFile,
199 196
        match self {
200 197
            Self::WarmScroll => "warm-scroll",
201 198
            Self::Session => "session",
202 199
            Self::Resize => "resize",
203 200
            Self::Sticky => "sticky",
204 -
            Self::Collapse => "collapse",
205 201
            Self::Highlight => "highlight",
206 202
            Self::HighlightRequests => "highlight-requests",
207 203
            Self::WordDiff => "word-diff",
208 204
            Self::ManyFiles => "many-files",
209 205
            Self::HugeFile => "huge-file",
219 215
            Self::Highlight => "ms/land",
220 216
            Self::WarmScroll
221 217
            | Self::Session
222 218
            | Self::Resize
223 219
            | Self::Sticky
224 -
            | Self::Collapse
225 220
            | Self::WordDiff
226 221
            | Self::ManyFiles
227 222
            | Self::HugeFile
228 223
            | Self::LongLines
229 224
            | Self::All => "fps",
267 262
                    lines,
268 263
                    hunk_lines: lines,
269 264
                    profile: LineProfile::Normal,
270 265
                }
271 266
            }
272 -
            Self::Sticky | Self::Collapse => DiffShape {
267 +
            Self::Sticky => DiffShape {
273 268
                files: args.files.max(256),
274 269
                lines: 32,
275 270
                hunk_lines: 16,
276 271
                profile: LineProfile::Normal,
277 272
            },
297 292
        match value {
298 293
            "warm-scroll" | "plain" | "scroll" => Ok(Self::WarmScroll),
299 294
            "session" => Ok(Self::Session),
300 295
            "resize" => Ok(Self::Resize),
301 296
            "sticky" | "sticky-boundaries" => Ok(Self::Sticky),
302 -
            "collapse" => Ok(Self::Collapse),
303 297
            "highlight" | "highlights" => Ok(Self::Highlight),
304 298
            "highlight-requests" | "requests" => Ok(Self::HighlightRequests),
305 299
            "word-diff" | "worddiff" => Ok(Self::WordDiff),
306 300
            "many-files" => Ok(Self::ManyFiles),
307 301
            "huge-file" => Ok(Self::HugeFile),
420 414
    match workload {
421 415
        Workload::WarmScroll => run_warm_scroll(document, frames),
422 416
        Workload::Session => run_session(document, frames),
423 417
        Workload::Resize => run_resize(document, frames),
424 418
        Workload::Sticky => run_sticky(document, frames),
425 -
        Workload::Collapse => run_collapse(document, frames),
426 419
        Workload::Highlight => run_highlight(document, frames),
427 420
        Workload::HighlightRequests => run_highlight_requests(document, frames),
428 421
        Workload::WordDiff => run_word_diff(document, frames),
429 422
        Workload::ManyFiles => run_session(document, frames),
430 423
        Workload::HugeFile => run_sticky(document, frames),
472 465
            }
473 466
            9 => {
474 467
                viewer.apply(DiffAction::FocusNext, area);
475 468
            }
476 469
            10 => {
477 -
                viewer.apply(DiffAction::ToggleFocusedFile, area);
470 +
                viewer.apply(DiffAction::FocusPrevious, area);
478 471
            }
479 472
            11 => {
480 -
                viewer.apply(DiffAction::ToggleFocusedFile, area);
473 +
                viewer.apply(DiffAction::NextHunk, area);
481 474
            }
482 475
            12 => {
483 476
                viewer.apply(DiffAction::PreviousHunk, area);
484 477
            }
485 478
            _ => {
516 509
        }
517 510
        AREA
518 511
    })
519 512
}
520 513
521 -
/// Renders while repeatedly focusing and collapsing file cards.
522 -
fn run_collapse(document: DiffDocument, frames: usize) -> (Duration, usize) {
523 -
    run_scripted(document, frames, |viewer, frame| {
524 -
        match frame % 6 {
525 -
            0 => {
526 -
                viewer.apply(DiffAction::FocusNext, AREA);
527 -
            }
528 -
            1 => {
529 -
                viewer.apply(DiffAction::CollapseFocusedFile, AREA);
530 -
            }
531 -
            2 => {
532 -
                viewer.apply(DiffAction::ToggleFocusedFile, AREA);
533 -
            }
534 -
            3 => {
535 -
                viewer.apply(DiffAction::NextHunk, AREA);
536 -
            }
537 -
            _ => {
538 -
                viewer.apply(DiffAction::Scroll(Scroll::Lines(3)), AREA);
539 -
            }
540 -
        }
541 -
        AREA
542 -
    })
543 -
}
544 -
545 514
/// Renders until visible rows have real syntax highlights applied.
546 515
fn run_highlight(document: DiffDocument, frames: usize) -> (Duration, usize) {
547 516
    let mut viewer = DiffViewer::new(document, DiffOptions::default());
548 517
    let mut buffer = Buffer::empty(AREA);
549 518
    let rows = rustik_tui::Widget::size(&viewer, Constraint::UNBOUNDED).rows;
src/file_{file:04}.rs\n" +0 -0
crates/diff/src/highlighter.rs +5 -3
266 266
    }
267 267
268 268
    /// Returns cached context that contains the requested source row.
269 269
    fn context_source_for(&self, request: &HighlightRequest) -> Option<&HighlightSource> {
270 270
        let key = (request.key.file, request.key.side);
271 -
        self.context_sources.get(&key)?.iter().find(|source| {
272 -
            source.line(request.key.source_line) == request.source.line(request.key.source_line)
273 -
        })
271 +
        let expected = request.source.line(request.key.source_line)?;
272 +
        self.context_sources
273 +
            .get(&key)?
274 +
            .iter()
275 +
            .find(|source| source.line(request.key.source_line) == Some(expected))
274 276
    }
275 277
276 278
    /// Refetches and decodes one context update.
277 279
    fn context(&mut self, request: ContextRequest) -> Option<ContextUpdate> {
278 280
        let repo = self.repo.as_ref()?;
crates/diff/src/lib.rs +1 -1
45 45
};
46 46
#[cfg(feature = "builtins")]
47 47
pub use highlighter::{HighlightOutput, Highlighter, spawn_highlighter};
48 48
pub use viewer::{
49 49
    ContextRequest, ContextUpdate, DiffAction, DiffFocus, DiffOptions, DiffPalette, DiffState,
50 -
    DiffViewer, FileTree, FileTreeMode, FileTreeTarget, ViewChange,
50 +
    DiffViewer, FileTree, FileTreeMode, FileTreeTarget, HunkFocus, ViewChange,
51 51
};
crates/diff/src/viewer.rs +257 -149
11 11
12 12
use rustik_highlight as syntax;
13 13
use rustik_tui as tui;
14 14
use tui::{
15 15
    Badge, Buffer, Cell, Color, Constraint, Control, Event, HStack, Key, Label, Line, Mouse,
16 -
    MouseButton, Placement, Rect, Scroll, ScrollView, ScrollbarStyle, Size, Style, Table,
17 -
    TableOptions, Text, TreeStyle, VStack, View, Viewport, Widget, colors,
16 +
    MouseButton, Rect, Scroll, ScrollView, ScrollbarStyle, Size, Style, Table, TableOptions, Text,
17 +
    VStack, View, Viewport, Widget, colors,
18 18
};
19 19
20 20
use crate::context::{self, ContextChange, ContextState};
21 21
use crate::decorate::{DiffDecorator, FileDecoration, HunkDecoration};
22 22
use crate::highlight::{DiffHighlighter, HighlightKeyInput, HighlightResult};
43 43
const MIN_RENDER_COLS: usize = 12;
44 44
/// Width of old and new line number cells.
45 45
const LINE_NUMBER_WIDTH: usize = 5;
46 46
/// Foreground color used by old and new line number cells.
47 47
const LINE_NUMBER_FG: Color = colors::fixed::DIM;
48 +
/// Foreground color used by line number cells in the focused hunk.
49 +
const SELECTED_LINE_NUMBER_FG: Color = Color::Fixed(242);
48 50
/// Width of the hunk marker cell.
49 51
const MARKER_WIDTH: usize = 3;
50 52
/// Scrollbar track glyph (distinct from box-drawing borders so the column reads as a track).
51 53
const SCROLLBAR_TRACK: char = '🮘';
52 54
/// Scrollbar thumb glyph.
69 71
const NO_NEWLINE_MARKER: &str = "\\ No newline at end of file";
70 72
/// Rendered source text replacement for a single source tab.
71 73
const SOURCE_TAB_MARKER: &str = "·   ";
72 74
/// Marker cell shown between hunks in the diff marker column.
73 75
const HUNK_GAP_MARKER_CELL: &str = " ⋮ ";
76 +
/// Separator shown between file header metadata segments.
77 +
const FILE_HEADER_SEGMENT_SEPARATOR: &str = "  \u{00b7} ";
74 78
/// Default syntax theme selection stored in highlight keys.
75 79
const DEFAULT_THEME: &str = "auto";
76 80
/// Number of rows in a sticky file header.
77 81
const STICKY_HEADER_ROWS: usize = 3;
78 82
/// Number of body rows moved by keyboard line-scroll inputs.
95 99
pub struct DiffState {
96 100
    /// Vertical viewport over the rendered document.
97 101
    pub scroll: Viewport,
98 102
    /// Currently focused file or hunk.
99 103
    pub focus: Option<DiffFocus>,
100 -
    /// Collapsed file sections.
101 -
    pub collapsed_files: BTreeSet<FileId>,
102 -
}
103 -
104 -
impl DiffState {
105 -
    /// Returns whether replacing this state with `next` invalidates cached row positions.
106 -
    fn invalidates_index(&self, next: &Self) -> bool {
107 -
        self.collapsed_files != next.collapsed_files
108 -
    }
109 104
}
110 105
111 106
/// Focus target inside a diff document.
112 107
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
113 108
pub enum DiffFocus {
130 125
    FocusPrevious,
131 126
    /// Focus the next hunk target.
132 127
    NextHunk,
133 128
    /// Focus the previous hunk target.
134 129
    PreviousHunk,
135 -
    /// Toggle the focused file between collapsed and expanded states.
136 -
    ToggleFocusedFile,
137 -
    /// Collapse the focused file, or report no change if it is already collapsed.
138 -
    CollapseFocusedFile,
139 130
    /// Toggle the file tree between automatic visibility and hidden.
140 131
    ToggleFileTree,
141 132
    /// Move the file-tree cursor by visible rows, jumping to files as they are selected.
142 133
    MoveFileTree(isize),
143 134
    /// Show the current file-tree target without changing folder expansion.
170 161
    pub diff_palette: DiffPalette,
171 162
    /// Whether the file tree may be rendered beside the diff.
172 163
    pub file_tree: FileTreeMode,
173 164
    /// Folder name shown as the file tree root.
174 165
    pub file_tree_root: String,
166 +
    /// Visual treatment for hunk focus.
167 +
    pub hunk_focus: HunkFocus,
168 +
}
169 +
170 +
/// Visual treatment for hunk focus.
171 +
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
172 +
pub enum HunkFocus {
173 +
    /// Render focused and unfocused hunks normally.
174 +
    #[default]
175 +
    Plain,
176 +
    /// Force all non-focused hunk body rows to the dim foreground.
177 +
    DimUnfocused,
175 178
}
176 179
177 180
/// Positive and negative colors used for diff chrome.
178 181
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
179 182
pub struct DiffPalette {
352 355
            syntax: None,
353 356
            theme: DEFAULT_THEME.to_owned(),
354 357
            diff_palette: DiffPalette::default(),
355 358
            file_tree: FileTreeMode::default(),
356 359
            file_tree_root: ".".to_owned(),
360 +
            hunk_focus: HunkFocus::default(),
357 361
        }
358 362
    }
359 363
}
360 364
361 365
impl Default for DiffPalette {
499 503
    /// Returns the viewed document.
500 504
    pub const fn document(&self) -> &DiffDocument {
501 505
        &self.document
502 506
    }
503 507
508 +
    /// Returns the viewer options.
509 +
    pub const fn options(&self) -> &DiffOptions {
510 +
        &self.options
511 +
    }
512 +
504 513
    /// Returns the viewer state.
505 514
    pub const fn state(&self) -> &DiffState {
506 515
        &self.state
507 516
    }
508 517
509 518
    /// Replaces the viewer state.
510 519
    pub fn set_state(&mut self, state: DiffState) {
511 -
        let rebuild = self.state.invalidates_index(&state);
512 520
        self.state = state;
513 -
514 -
        if rebuild {
515 -
            self.rebuild_index();
516 -
        }
517 521
    }
518 522
519 523
    /// Replaces existing file diffs in place, matching them by id.
520 524
    pub fn replace_file_diffs(&mut self, files: impl IntoIterator<Item = FileDiff>) {
521 525
        for replacement in files {
589 593
    /// Sets the focused file or hunk.
590 594
    pub fn set_focus(&mut self, focus: Option<DiffFocus>) {
591 595
        self.state.focus = focus;
592 596
    }
593 597
594 -
    /// Sets the collapsed file sections.
595 -
    pub fn set_collapsed_files(&mut self, collapsed_files: BTreeSet<FileId>) {
596 -
        self.state.collapsed_files = collapsed_files;
597 -
        self.rebuild_index();
598 -
    }
599 -
600 598
    /// Returns the file containing the current focus.
601 599
    pub fn focused_file(&self) -> Option<FileId> {
602 600
        match self.state.focus? {
603 601
            DiffFocus::File(file) => Some(file),
604 602
            DiffFocus::Hunk(hunk) => self
806 804
            }
807 805
            DiffAction::PreviousHunk => {
808 806
                self.focus(diff.rows, -1, FocusFilter::Hunk);
809 807
                self.sync_file_tree();
810 808
            }
811 -
            DiffAction::ToggleFocusedFile => {
812 -
                let active_file = self.active_file();
813 -
                self.toggle_active_file();
814 -
                if active_file.is_some() {
815 -
                    self.sync_file_tree();
816 -
                }
817 -
            }
818 -
            DiffAction::CollapseFocusedFile => {
819 -
                let focused_file = self.focused_file();
820 -
                self.collapse_focused_file();
821 -
                if focused_file.is_some() {
822 -
                    self.sync_file_tree();
823 -
                }
824 -
            }
825 809
            DiffAction::ToggleFileTree => match self.file_tree_visibility {
826 810
                FileTreeVisibility::Hidden => {
827 811
                    self.file_tree_visibility = FileTreeVisibility::Visible;
828 812
                    if self.layout(area).tree.is_some() {
829 813
                        self.sync_file_tree();
866 850
            DiffAction::ExpandFileTreeFolder => {
867 851
                self.file_tree.expand_folder();
868 852
            }
869 853
        }
870 854
871 -
        if before.invalidates_index(&self.state) {
872 -
            let collapsed_file_anchor = self
873 -
                .state
874 -
                .collapsed_files
875 -
                .iter()
876 -
                .find(|file| !before.collapsed_files.contains(file))
877 -
                .copied();
878 -
            self.rebuild_index();
879 -
            if let Some(file) = collapsed_file_anchor {
880 -
                self.show_file(file, diff.rows);
881 -
            } else {
882 -
                self.state
883 -
                    .scroll
884 -
                    .clamp(self.scroll_rows(diff.rows), diff.rows);
885 -
            }
886 -
        }
887 855
        if self.state == before
888 856
            && self.file_tree_visibility == before_visibility
889 857
            && *self.file_tree.state() == before_file_tree
890 858
        {
891 859
            ViewChange::Unchanged
925 893
                    None => return Control::Continue,
926 894
                };
927 895
                self.apply(action, area);
928 896
                return Control::Redraw;
929 897
            }
930 -
            Event::Key(Key::Esc) => {
931 -
                if self.apply(DiffAction::CollapseFocusedFile, area) == ViewChange::Changed {
932 -
                    return Control::Redraw;
933 -
                }
934 -
                return Control::Quit;
935 -
            }
898 +
            Event::Key(Key::Esc) => return Control::Quit,
936 899
            Event::Key(Key::Char('j') | Key::Down) => {
937 900
                DiffAction::Scroll(Scroll::Lines(LINE_SCROLL_ROWS))
938 901
            }
939 902
            Event::Key(Key::Char('k') | Key::Up) => {
940 903
                DiffAction::Scroll(Scroll::Lines(-LINE_SCROLL_ROWS))
953 916
            }
954 917
            Event::Key(Key::Char('g') | Key::Home) => DiffAction::Scroll(Scroll::Top),
955 918
            Event::Key(Key::Char('G') | Key::End) => DiffAction::Scroll(Scroll::Bottom),
956 919
            Event::Key(Key::Char('n')) => DiffAction::FocusNext,
957 920
            Event::Key(Key::Char('p')) => DiffAction::FocusPrevious,
958 -
            Event::Key(Key::Enter) => DiffAction::ToggleFocusedFile,
959 921
            _ => return Control::Continue,
960 922
        };
961 923
        match self.apply(action, area) {
962 924
            ViewChange::Changed => Control::Redraw,
963 925
            ViewChange::Unchanged => Control::Continue,
1063 1025
        source
1064 1026
    }
1065 1027
1066 1028
    /// Builds source text for one hunk side.
1067 1029
    fn build_highlight_source(&self, meta: &DiffLineMeta) -> HighlightSource {
1068 -
        let Some(file) = self.document.files.get(*meta.file) else {
1030 +
        let Some(file) = self.document.files.iter().find(|file| file.id == meta.file) else {
1069 1031
            return meta.single_row_source();
1070 1032
        };
1071 1033
        let Some(hunk) = file.hunks.iter().find(|hunk| hunk.id == meta.hunk) else {
1072 1034
            return meta.single_row_source();
1073 1035
        };
1083 1045
    pub fn apply_highlights(&mut self, results: impl IntoIterator<Item = HighlightResult>) -> bool {
1084 1046
        let mut changed = false;
1085 1047
        for result in results {
1086 1048
            self.pending_highlights.remove(&result.key);
1087 1049
1088 -
            if let Entry::Vacant(slot) = self.word_diffs.entry(result.hunk)
1089 -
                && let Some(hunk) = self
1090 -
                    .document
1091 -
                    .files
1092 -
                    .iter()
1093 -
                    .find(|f| f.id == result.key.file)
1094 -
                    .and_then(|f| f.hunks.iter().find(|h| h.id == result.hunk))
1095 -
            {
1050 +
            let Some(hunk) = self
1051 +
                .document
1052 +
                .files
1053 +
                .iter()
1054 +
                .find(|f| f.id == result.key.file)
1055 +
                .and_then(|f| f.hunks.iter().find(|h| h.id == result.hunk))
1056 +
            else {
1057 +
                continue;
1058 +
            };
1059 +
            let Some(source) = hunk.lines.iter().find(|line| line.id == result.row) else {
1060 +
                continue;
1061 +
            };
1062 +
            // An empty highlight for a non-empty row means the highlighter
1063 +
            // produced nothing useful; keep the plain source text instead.
1064 +
            if !source.text.is_empty() && result.line.width() == 0 {
1065 +
                continue;
1066 +
            }
1067 +
1068 +
            if let Entry::Vacant(slot) = self.word_diffs.entry(result.hunk) {
1096 1069
                slot.insert(crate::word::compute(hunk));
1097 1070
            }
1098 1071
            let bg = match result.key.side {
1099 1072
                DiffSide::New => self.options.diff_palette.positive_word_bg,
1100 1073
                DiffSide::Old => self.options.diff_palette.negative_word_bg,
1130 1103
        self.apply_highlights(highlighter.highlight_batch(requests))
1131 1104
    }
1132 1105
1133 1106
    /// Returns the row count for one file card.
1134 1107
    fn file_rows(&self, file: &FileDiff) -> usize {
1135 -
        file.rendered_rows(self.state.collapsed_files.contains(&file.id))
1108 +
        file.rendered_rows()
1136 1109
    }
1137 1110
1138 1111
    /// Returns one rendered row by global row index.
1139 1112
    fn render_row(&self, row: usize, cols: usize) -> Option<RenderRow> {
1140 1113
        let cols = cols.max(MIN_RENDER_COLS);
1152 1125
    fn render_file_row(&self, location: FileRowLocation<'_>, cols: usize) -> RenderRow {
1153 1126
        let file = location.file;
1154 1127
        let border = FILE_BORDER;
1155 1128
        let inner_cols = cols.saturating_sub(2);
1156 1129
        let child_cols = cols.saturating_sub(4);
1157 -
        let collapsed = self.state.collapsed_files.contains(&file.id);
1158 1130
        let local = location.local;
1159 1131
        let bottom = location.end - location.start - 1;
1160 1132
        // Child rows are full-width content lines rendered inside a bordered card.
1161 1133
        let wrap_child = |mut line: Line| {
1162 1134
            Line::truncate(&mut line, child_cols, "…");
1179 1151
            FILE_HEADER_ROW => {
1180 1152
                let decoration = self.file_decoration(file.id);
1181 1153
                return RenderRow {
1182 1154
                    line: wrap_child(file.header_line(
1183 1155
                        child_cols,
1184 -
                        collapsed,
1185 1156
                        self.options.diff_palette,
1186 1157
                        &decoration,
1187 1158
                    )),
1188 1159
                    diff: None,
1189 1160
                };
1192 1163
                return RenderRow {
1193 1164
                    line: border.bottom(inner_cols),
1194 1165
                    diff: None,
1195 1166
                };
1196 1167
            }
1197 -
            _ if !file.has_body(collapsed) => {
1168 +
            _ if !file.has_body() => {
1198 1169
                return RenderRow {
1199 1170
                    line: border.bottom(inner_cols),
1200 1171
                    diff: None,
1201 1172
                };
1202 1173
            }
1206 1177
                    diff: None,
1207 1178
                };
1208 1179
            }
1209 1180
            _ => {}
1210 1181
        }
1211 -
        let mut body_rows = file.hunk_body_rows(collapsed).peekable();
1182 +
        let mut body_rows = file.hunk_body_rows().peekable();
1212 1183
        while let Some(&(hunk, body_start)) = body_rows.peek() {
1213 1184
            let body_end = body_start + hunk.lines.len();
1214 1185
            if local < body_start {
1215 1186
                return RenderRow {
1216 1187
                    line: wrap_child(hunk_gap_line),
1225 1196
                }
1226 1197
                // The corner marker is drawn over the hunk's first body row.
1227 1198
                if local == body_start {
1228 1199
                    row.line = Self::overlay_corner(row.line, &decoration.corner, child_cols);
1229 1200
                }
1201 +
                if self.dims_unfocused_hunk(hunk.id) {
1202 +
                    row.line = Self::muted_hunk_line(row.line);
1203 +
                }
1230 1204
                return RenderRow {
1231 1205
                    line: wrap_child(row.line),
1232 1206
                    diff: row.diff,
1233 1207
                };
1234 1208
            }
1241 1215
    }
1242 1216
1243 1217
    /// Returns source metadata for one rendered row without building UI lines.
1244 1218
    fn diff_meta_at(&self, row: usize) -> Option<DiffLineMeta> {
1245 1219
        let location = self.file_row_location(row)?;
1246 -
        let collapsed = self.state.collapsed_files.contains(&location.file.id);
1247 -
        for (hunk, body_start) in location.file.hunk_body_rows(collapsed) {
1220 +
        for (hunk, body_start) in location.file.hunk_body_rows() {
1248 1221
            let body_end = body_start + hunk.lines.len();
1249 1222
            if location.local < body_start {
1250 1223
                return None;
1251 1224
            }
1252 1225
            if location.local < body_end {
1432 1405
        }
1433 1406
        let location = self.file_row_location(scroll)?;
1434 1407
        if scroll <= location.start {
1435 1408
            return None;
1436 1409
        }
1437 -
        if self.state.collapsed_files.contains(&location.file.id) {
1438 -
            return None;
1439 -
        }
1440 1410
        let file_bottom = location.end.saturating_sub(location.start + 1);
1441 1411
        let rows = file_bottom
1442 1412
            .saturating_sub(location.local)
1443 1413
            .min(STICKY_HEADER_ROWS)
1444 1414
            .min(visible_rows);
1469 1439
                    targets
1470 1440
                        .iter()
1471 1441
                        .position(|target| target.focus == DiffFocus::File(file))
1472 1442
                })
1473 1443
            });
1474 -
        let next = match (current, delta.is_negative()) {
1475 -
            (Some(index), true) => index.checked_sub(1),
1476 -
            (Some(index), false) => index.checked_add(1).filter(|index| *index < targets.len()),
1477 -
            (None, true) => targets.len().checked_sub(1),
1478 -
            (None, false) => Some(0),
1444 +
        let next = match (current, filter, delta.is_negative()) {
1445 +
            (Some(index), _, true) => index.checked_sub(1),
1446 +
            (Some(index), _, false) => index.checked_add(1).filter(|index| *index < targets.len()),
1447 +
            (None, FocusFilter::Hunk, true) => targets
1448 +
                .partition_point(|target| target.row <= self.state.scroll.offset)
1449 +
                .checked_sub(1),
1450 +
            (None, FocusFilter::Hunk, false) => {
1451 +
                let index = targets.partition_point(|target| target.row < self.state.scroll.offset);
1452 +
                (index < targets.len()).then_some(index)
1453 +
            }
1454 +
            (None, FocusFilter::File, true) => targets.len().checked_sub(1),
1455 +
            (None, FocusFilter::File, false) => Some(0),
1479 1456
        };
1480 1457
        let Some(target) = next.and_then(|next| targets.get(next)) else {
1481 1458
            return;
1482 1459
        };
1460 +
        let was_hunk_focused = matches!(self.state.focus, Some(DiffFocus::Hunk(_)));
1483 1461
1484 1462
        self.state.focus = Some(target.focus);
1485 1463
        if filter == FocusFilter::File {
1486 1464
            self.state
1487 1465
                .scroll
1488 1466
                .set_offset(target.row, self.scroll_rows(visible_rows), visible_rows);
1489 1467
            return;
1490 1468
        }
1491 1469
1492 -
        let margin = visible_rows / 4;
1493 -
        let before = margin.max(self.sticky_row_count(self.state.scroll.offset, visible_rows));
1494 -
        self.state.scroll.scroll_to_row(
1495 -
            target.row,
1496 -
            self.scroll_rows(visible_rows),
1470 +
        self.scroll_to_focused_hunk(
1471 +
            target,
1497 1472
            visible_rows,
1498 -
            Placement::Margin {
1499 -
                before,
1500 -
                after: margin,
1473 +
            if was_hunk_focused {
1474 +
                HunkScroll::Preserve
1475 +
            } else {
1476 +
                HunkScroll::Center
1501 1477
            },
1502 1478
        );
1503 1479
    }
1504 1480
1481 +
    /// Scrolls to place a focused hunk using the review pager policy.
1482 +
    fn scroll_to_focused_hunk(
1483 +
        &mut self,
1484 +
        target: &FocusTarget,
1485 +
        visible_rows: usize,
1486 +
        scroll: HunkScroll,
1487 +
    ) {
1488 +
        let next = match scroll {
1489 +
            HunkScroll::Center => {
1490 +
                let centered = Self::centered_focus_scroll(target.row, target.height, visible_rows);
1491 +
                centered.saturating_sub(target.sticky_rows(centered))
1492 +
            }
1493 +
            HunkScroll::Preserve => Self::preserved_focus_scroll(
1494 +
                target.row,
1495 +
                target.height,
1496 +
                visible_rows,
1497 +
                self.state.scroll.offset,
1498 +
                target.sticky_rows(self.state.scroll.offset),
1499 +
            ),
1500 +
        };
1501 +
1502 +
        self.state
1503 +
            .scroll
1504 +
            .set_offset(next, self.scroll_rows(visible_rows), visible_rows);
1505 +
    }
1506 +
1507 +
    /// Returns the scroll offset that centers a focused hunk when possible.
1508 +
    fn centered_focus_scroll(row: usize, height: usize, visible_rows: usize) -> usize {
1509 +
        let target = if height >= visible_rows {
1510 +
            0
1511 +
        } else {
1512 +
            visible_rows.saturating_sub(height) / 2
1513 +
        };
1514 +
1515 +
        row.saturating_sub(target)
1516 +
    }
1517 +
1518 +
    /// Returns a scroll offset that preserves middle-half focused hunk visibility.
1519 +
    fn preserved_focus_scroll(
1520 +
        row: usize,
1521 +
        height: usize,
1522 +
        visible_rows: usize,
1523 +
        scroll: usize,
1524 +
        sticky_rows: usize,
1525 +
    ) -> usize {
1526 +
        if visible_rows == 0 {
1527 +
            return scroll;
1528 +
        }
1529 +
        let height = height.max(1);
1530 +
        if height >= visible_rows {
1531 +
            return Self::large_focused_scroll(row, height, visible_rows, scroll, sticky_rows);
1532 +
        }
1533 +
1534 +
        let top = (visible_rows / 4).max(sticky_rows);
1535 +
        let bottom = visible_rows.saturating_sub(visible_rows / 4);
1536 +
        let screen_top = row.saturating_sub(scroll);
1537 +
        let screen_bottom = screen_top.saturating_add(height);
1538 +
1539 +
        if screen_top < top {
1540 +
            row.saturating_sub(top)
1541 +
        } else if screen_bottom > bottom {
1542 +
            row.saturating_add(height).saturating_sub(bottom)
1543 +
        } else {
1544 +
            scroll
1545 +
        }
1546 +
    }
1547 +
1548 +
    /// Returns scroll for a focused hunk taller than the viewport.
1549 +
    fn large_focused_scroll(
1550 +
        row: usize,
1551 +
        height: usize,
1552 +
        visible_rows: usize,
1553 +
        scroll: usize,
1554 +
        sticky_rows: usize,
1555 +
    ) -> usize {
1556 +
        let top = row.saturating_sub(sticky_rows);
1557 +
        let end = row.saturating_add(height);
1558 +
        if scroll < top {
1559 +
            return top;
1560 +
        }
1561 +
        if scroll >= end {
1562 +
            return end.saturating_sub(visible_rows);
1563 +
        }
1564 +
        scroll
1565 +
    }
1566 +
1505 1567
    /// Returns focusable targets in rendered row order.
1506 1568
    fn focus_targets(&self, filter: FocusFilter) -> Vec<FocusTarget> {
1507 1569
        let mut targets = Vec::new();
1508 1570
1509 1571
        for indexed in &self.index.files {
1510 1572
            let Some(file) = self.document.files.get(indexed.file_index) else {
1511 1573
                continue;
1512 1574
            };
1513 -
            let collapsed = self.state.collapsed_files.contains(&file.id);
1514 1575
            if filter == FocusFilter::File {
1515 1576
                targets.push(FocusTarget {
1516 1577
                    focus: DiffFocus::File(file.id),
1517 1578
                    row: indexed.start,
1579 +
                    height: 1,
1580 +
                    file_start: indexed.start,
1518 1581
                });
1519 1582
            }
1520 1583
            if filter == FocusFilter::Hunk {
1521 -
                for (hunk, local) in file.hunk_body_rows(collapsed) {
1584 +
                for (hunk, local) in file.hunk_body_rows() {
1522 1585
                    targets.push(FocusTarget {
1523 1586
                        focus: DiffFocus::Hunk(hunk.id),
1524 1587
                        row: indexed.start + local,
1588 +
                        height: hunk.lines.len(),
1589 +
                        file_start: indexed.start,
1525 1590
                    });
1526 1591
                }
1527 1592
            }
1528 1593
        }
1529 1594
        targets
1530 1595
    }
1531 1596
1532 -
    /// Toggles the active file between collapsed and expanded states.
1533 -
    fn toggle_active_file(&mut self) {
1534 -
        let Some(file) = self.active_file() else {
1535 -
            return;
1536 -
        };
1537 -
        if !self.state.collapsed_files.remove(&file) {
1538 -
            self.state.collapsed_files.insert(file);
1539 -
            self.state.focus = Some(DiffFocus::File(file));
1540 -
        }
1541 -
    }
1542 -
1543 -
    /// Collapses the file containing the current focus.
1544 -
    fn collapse_focused_file(&mut self) {
1545 -
        let Some(file) = self.focused_file() else {
1546 -
            return;
1547 -
        };
1548 -
        self.state.collapsed_files.insert(file);
1549 -
        self.state.focus = Some(DiffFocus::File(file));
1550 -
    }
1551 -
1552 1597
    /// Returns one rendered row inside a hunk.
1553 1598
    fn hunk_row_at(
1554 1599
        &self,
1555 1600
        file: &FileDiff,
1556 1601
        hunk: &crate::Hunk,
1587 1632
        meta: DiffLineMeta,
1588 1633
        line: &DiffLine,
1589 1634
        old_line: u32,
1590 1635
        row_cols: usize,
1591 1636
    ) -> RenderRow {
1637 +
        let line_number_fg = if matches!(self.state.focus, Some(DiffFocus::Hunk(focused)) if focused == meta.hunk)
1638 +
        {
1639 +
            SELECTED_LINE_NUMBER_FG
1640 +
        } else {
1641 +
            LINE_NUMBER_FG
1642 +
        };
1592 1643
        let (cells, source, row_style, source_style) = match line.kind {
1593 1644
            DiffLineKind::Addition => (
1594 1645
                [
1595 1646
                    Self::blank_number(self.options.diff_palette.positive_row_bg),
1596 1647
                    Self::number_cell(
1597 1648
                        meta.source_line,
1598 -
                        LINE_NUMBER_FG,
1649 +
                        line_number_fg,
1599 1650
                        self.options.diff_palette.positive_row_bg,
1600 1651
                    ),
1601 1652
                    Self::marker_cell(" + ", self.options.diff_palette.positive_fg),
1602 1653
                ],
1603 1654
                self.rendered_source(&meta),
1606 1657
            ),
1607 1658
            DiffLineKind::Deletion => (
1608 1659
                [
1609 1660
                    Self::number_cell(
1610 1661
                        meta.source_line,
1611 -
                        LINE_NUMBER_FG,
1662 +
                        line_number_fg,
1612 1663
                        self.options.diff_palette.negative_row_bg,
1613 1664
                    ),
1614 1665
                    Self::blank_number(self.options.diff_palette.negative_row_bg),
1615 1666
                    Self::marker_cell(" - ", self.options.diff_palette.negative_fg),
1616 1667
                ],
1620 1671
                    .bg(self.options.diff_palette.negative_row_bg)
1621 1672
                    .dim(),
1622 1673
            ),
1623 1674
            DiffLineKind::Context => (
1624 1675
                [
1625 -
                    Self::number_cell(old_line, LINE_NUMBER_FG, Color::Unset),
1626 -
                    Self::number_cell(meta.source_line, LINE_NUMBER_FG, Color::Unset),
1676 +
                    Self::number_cell(old_line, line_number_fg, Color::Unset),
1677 +
                    Self::number_cell(meta.source_line, line_number_fg, Color::Unset),
1627 1678
                    Self::marker_cell("   ", Color::Unset),
1628 1679
                ],
1629 1680
                self.rendered_source(&meta),
1630 1681
                Style::default(),
1631 1682
                Style::default(),
1686 1737
    /// Cached entries already include the word-diff overlay (applied once in
1687 1738
    /// [`Self::apply_highlights`]). On a cache miss -- the window before the
1688 1739
    /// highlight worker responds -- a plain Line is returned; the word-diff
1689 1740
    /// background lands once the cached overlaid line arrives.
1690 1741
    fn rendered_source(&self, meta: &DiffLineMeta) -> Line {
1691 -
        let has_tabs = meta.text.contains('\t');
1692 1742
        if let Some(line) = self.highlights.get(&self.key_for(meta)) {
1693 1743
            let line = line.clone();
1694 -
            return if has_tabs {
1744 +
            return if meta.text.contains('\t') {
1695 1745
                Self::expand_source_tabs(line)
1696 1746
            } else {
1697 1747
                line
1698 1748
            };
1699 1749
        }
1700 -
        if has_tabs {
1750 +
1751 +
        Self::plain_source_line(meta)
1752 +
    }
1753 +
1754 +
    /// Returns the unhighlighted source text for a row.
1755 +
    fn plain_source_line(meta: &DiffLineMeta) -> Line {
1756 +
        if meta.text.contains('\t') {
1701 1757
            Self::expand_source_tabs(Line::new(meta.text.as_str()))
1702 1758
        } else {
1703 1759
            Line::new(meta.text.as_str())
1704 1760
        }
1705 1761
    }
1743 1799
    /// Returns a marker cell.
1744 1800
    fn marker_cell(marker: &str, foreground: Color) -> Line {
1745 1801
        Line::new(Label::new(marker).fg(foreground)).padded(MARKER_WIDTH)
1746 1802
    }
1747 1803
1804 +
    /// Returns whether hunk focus should dim this non-focused hunk.
1805 +
    fn dims_unfocused_hunk(&self, hunk: HunkId) -> bool {
1806 +
        self.options.hunk_focus == HunkFocus::DimUnfocused
1807 +
            && matches!(self.state.focus, Some(DiffFocus::Hunk(focused)) if focused != hunk)
1808 +
    }
1809 +
1810 +
    /// Returns a hunk row with every label rendered dimly.
1811 +
    fn muted_hunk_line(line: Line) -> Line {
1812 +
        line.into_iter()
1813 +
            .map(|label| {
1814 +
                let style = label
1815 +
                    .paint
1816 +
                    .style()
1817 +
                    .bg(Self::muted_background(label.paint.style().bg_color()))
1818 +
                    .dim();
1819 +
                Label::new(label.content()).style(style)
1820 +
            })
1821 +
            .collect::<Vec<_>>()
1822 +
            .into()
1823 +
    }
1824 +
1825 +
    /// Returns a darker variant of an inactive hunk background, at half the
1826 +
    /// brightness of the focused one.
1827 +
    fn muted_background(color: Color) -> Color {
1828 +
        match color {
1829 +
            Color::RGB(r, g, b) => Color::RGB(r / 2, g / 2, b / 2),
1830 +
            color => color,
1831 +
        }
1832 +
    }
1833 +
1748 1834
    /// Overlays `corner` onto the right edge of a child-width row line.
1749 1835
    ///
1750 1836
    /// The hunk row already fills `cols`; truncating to leave room for the
1751 1837
    /// corner and re-padding preserves the row background, then the corner is
1752 1838
    /// appended so it sits flush in the hunk's top-right corner. A corner that
1801 1887
struct FocusTarget {
1802 1888
    /// Focus value.
1803 1889
    focus: DiffFocus,
1804 1890
    /// Rendered row index.
1805 1891
    row: usize,
1892 +
    /// Rendered height of the focus target.
1893 +
    height: usize,
1894 +
    /// Rendered row where the containing file starts.
1895 +
    file_start: usize,
1896 +
}
1897 +
1898 +
impl FocusTarget {
1899 +
    /// Returns sticky file-header rows covering a scroll offset.
1900 +
    fn sticky_rows(self, scroll: usize) -> usize {
1901 +
        if scroll > self.file_start {
1902 +
            STICKY_HEADER_ROWS
1903 +
        } else {
1904 +
            0
1905 +
        }
1906 +
    }
1806 1907
}
1807 1908
1808 1909
/// Focus target filter.
1809 1910
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1810 1911
enum FocusFilter {
1812 1913
    File,
1813 1914
    /// Hunk targets only.
1814 1915
    Hunk,
1815 1916
}
1816 1917
1918 +
/// Hunk navigation scroll behavior.
1919 +
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1920 +
enum HunkScroll {
1921 +
    /// Center the focused hunk when possible.
1922 +
    Center,
1923 +
    /// Preserve current scroll while the focused hunk remains comfortably visible.
1924 +
    Preserve,
1925 +
}
1926 +
1817 1927
impl FileDiff {
1818 1928
    /// Returns whether this file card should render hunk rows.
1819 -
    fn has_body(&self, collapsed: bool) -> bool {
1820 -
        !collapsed && !self.hunks.is_empty()
1929 +
    fn has_body(&self) -> bool {
1930 +
        !self.hunks.is_empty()
1821 1931
    }
1822 1932
1823 1933
    /// Returns the rendered row count for this file's card.
1824 -
    fn rendered_rows(&self, collapsed: bool) -> usize {
1825 -
        if !self.has_body(collapsed) {
1934 +
    fn rendered_rows(&self) -> usize {
1935 +
        if !self.has_body() {
1826 1936
            return EMPTY_CARD_ROWS;
1827 1937
        }
1828 1938
        let hunks = self.hunks.len();
1829 1939
        let body: usize = self.hunks.iter().map(|hunk| hunk.lines.len()).sum();
1830 1940
        // top + header + divider + body lines + gaps + bottom.
1831 1941
        HUNK_BODY_START + body + hunks.saturating_sub(1) + 1
1832 1942
    }
1833 1943
1834 1944
    /// Returns each hunk together with the local row of its first body line.
1835 -
    fn hunk_body_rows(&self, collapsed: bool) -> impl Iterator<Item = (&Hunk, usize)> + '_ {
1836 -
        let has_body = self.has_body(collapsed);
1945 +
    fn hunk_body_rows(&self) -> impl Iterator<Item = (&Hunk, usize)> + '_ {
1837 1946
        self.hunks
1838 1947
            .iter()
1839 1948
            .enumerate()
1840 1949
            .scan(HUNK_BODY_START, move |local, (index, hunk)| {
1841 -
                if !has_body {
1842 -
                    return None;
1843 -
                }
1844 1950
                if index > 0 {
1845 1951
                    *local += 1;
1846 1952
                }
1847 1953
                let row = *local;
1848 1954
                *local += hunk.lines.len();
1849 1955
                Some((hunk, row))
1850 1956
            })
1851 1957
    }
1852 1958
1853 1959
    /// Returns a file header line, applying any host decoration.
1854 -
    fn header_line(
1855 -
        &self,
1856 -
        cols: usize,
1857 -
        collapsed: bool,
1858 -
        palette: DiffPalette,
1859 -
        decoration: &FileDecoration,
1860 -
    ) -> Line {
1960 +
    ///
1961 +
    /// The leading marker is the decorated status when the host provides one,
1962 +
    /// and the file-kind marker otherwise.
1963 +
    fn header_line(&self, cols: usize, palette: DiffPalette, decoration: &FileDecoration) -> Line {
1861 1964
        let mut left = Line::blank();
1862 -
        let marker = if collapsed {
1863 -
            TreeStyle::DEFAULT.collapsed_marker
1864 -
        } else {
1865 -
            TreeStyle::DEFAULT.expanded_marker
1866 -
        };
1867 -
        left.push(Label::from_char(marker).fg(LINE_NUMBER_FG));
1868 -
        left.push(Label::space());
1869 1965
        if let Some(status) = &decoration.status {
1870 1966
            left.push(Label::from_char(status.item).style(status.style));
1871 -
            left.push(Label::space());
1967 +
        } else {
1968 +
            let fg = match self.header.kind {
1969 +
                FileKind::Added => palette.positive_fg,
1970 +
                FileKind::Deleted => palette.negative_fg,
1971 +
                FileKind::Renamed => FILE_KIND_BADGE_FG,
1972 +
                FileKind::Modified | FileKind::Copied | FileKind::ModeChanged | FileKind::Binary => {
1973 +
                    Color::Yellow
1974 +
                }
1975 +
            };
1976 +
            left.push(Label::from_char(self.header.kind.marker()).fg(fg));
1872 1977
        }
1978 +
        left.push(Label::space());
1873 1979
        left = left.extend(self.path_line());
1874 1980
1875 1981
        if let Some(badge) = self.badge(palette) {
1876 1982
            left.push(Label::space());
1877 1983
            left = left.extend(badge.line());
1887 1993
            right.push(side);
1888 1994
        }
1889 1995
        let mut header = HStack::default().child(left).spacer();
1890 1996
        for (index, segment) in right.into_iter().enumerate() {
1891 1997
            if index > 0 {
1892 -
                header = header.child(Line::new("  "));
1998 +
                header = header.child(Line::new(
1999 +
                    Label::new(FILE_HEADER_SEGMENT_SEPARATOR).fg(colors::rgb::DIM),
2000 +
                ));
1893 2001
            }
1894 2002
            header = header.child(segment);
1895 2003
        }
1896 2004
        header.to_line(Constraint::tight(cols))
1897 2005
    }
a.rs +0 -0
a.rs +0 -0
b.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
b.rs +0 -0
crates/diff/tests/golden.rs +1 -17
1 1
#![allow(clippy::unwrap_used)]
2 2
3 -
use std::collections::BTreeSet;
4 -
5 3
use rustik_diff::{
6 -
    Decode, DiffAction, DiffDocument, DiffOptions, DiffSide, DiffViewer, FileId, FileTreeMode,
4 +
    Decode, DiffAction, DiffDocument, DiffOptions, DiffSide, DiffViewer, FileTreeMode,
7 5
    HighlightResult,
8 6
};
9 7
use rustik_tui::{Buffer, Color, Label, Line, Rect, Scroll, colors};
10 8
11 9
#[test]
28 26
        64,
29 27
        12,
30 28
    );
31 29
}
32 30
33 -
#[test]
34 -
fn collapsed_file_matches_golden_frame() {
35 -
    let mut viewer = sample_viewer();
36 -
    viewer.set_collapsed_files(BTreeSet::from([FileId::new(0)]));
37 -
38 -
    assert_golden(
39 -
        "collapsed_file_64x6.txt",
40 -
        include_str!("golden/collapsed_file_64x6.txt"),
41 -
        viewer,
42 -
        64,
43 -
        6,
44 -
    );
45 -
}
46 -
47 31
#[test]
48 32
fn focused_second_file_matches_golden_frame() {
49 33
    let mut viewer = two_file_viewer();
50 34
    viewer.apply(DiffAction::FocusNext, Rect::new(0, 0, 64, 6));
51 35
    viewer.apply(DiffAction::FocusNext, Rect::new(0, 0, 64, 6));
a.rs +0 -0
crates/diff/tests/golden/bottom_of_file_64x5.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮🮘
2 -
│ ▿ a.rs                                                +2 -1 │🮘
2 +
│ ⊙ a.rs                                                +2 -1 │🮘
3 3
├╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴┤▗
4 4
│ 3    4       tail                                           │▐
5 5
╰─────────────────────────────────────────────────────────────╯▐
crates/diff/tests/golden/collapsed_file_64x6.txt deleted +0 -6
1 -
╭─────────────────────────────────────────────────────────────╮🮘
2 -
│ ▹ a.rs                                                +2 -1 │🮘
3 -
╰─────────────────────────────────────────────────────────────╯🮘
4 -
                                                               🮘
5 -
                                                               🮘
6 -
                                                               🮘
crates/diff/tests/golden/expanded_file_card_64x9.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮🮘
2 -
│ ▿ a.rs                                                +2 -1 │🮘
2 +
│ ⊙ a.rs                                                +2 -1 │🮘
3 3
├─────────────────────────────────────────────────────────────┤🮘
4 4
│ 1    1       context                                        │🮘
5 5
│ 2          - old                                            │🮘
6 6
│      2     + new                                            │🮘
7 7
│      3     + extra                                          │🮘
crates/diff/tests/golden/file_kinds_80x24.txt +6 -6
1 1
╭─────────────────────────────────────────────────────────────────────────────╮🮘
2 -
│ ▿ new.rs  created                                                        +1 │🮘
2 +
│ ⊕ new.rs  created                                                        +1 │🮘
3 3
├─────────────────────────────────────────────────────────────────────────────┤🮘
4 4
│      1     + new                                                            │🮘
5 5
╰─────────────────────────────────────────────────────────────────────────────╯🮘
6 6
╭─────────────────────────────────────────────────────────────────────────────╮🮘
7 -
│ ▿ old.rs  deleted                                                        -1 │🮘
7 +
│ ⊖ old.rs  deleted                                                        -1 │🮘
8 8
├─────────────────────────────────────────────────────────────────────────────┤🮘
9 9
│ 1          - old                                                            │🮘
10 10
╰─────────────────────────────────────────────────────────────────────────────╯🮘
11 11
╭─────────────────────────────────────────────────────────────────────────────╮🮘
12 -
│ ▿ from.rs → to.rs  moved                                                    │🮘
12 +
│ ↦ from.rs → to.rs  moved                                                    │🮘
13 13
╰─────────────────────────────────────────────────────────────────────────────╯🮘
14 14
╭─────────────────────────────────────────────────────────────────────────────╮🮘
15 -
│ ▿ copy.rs → copy2.rs  copied                                                │🮘
15 +
│ ⇉ copy.rs → copy2.rs  copied                                                │🮘
16 16
╰─────────────────────────────────────────────────────────────────────────────╯🮘
17 17
╭─────────────────────────────────────────────────────────────────────────────╮🮘
18 -
│ ▿ mode.sh  mode changed                                                     │🮘
18 +
│ ⊙ mode.sh  mode changed                                                     │🮘
19 19
╰─────────────────────────────────────────────────────────────────────────────╯🮘
20 20
╭─────────────────────────────────────────────────────────────────────────────╮🮘
21 -
│ ▿ image.png  binary                                                         │🮘
21 +
│ ⊙ image.png  binary                                                         │🮘
22 22
╰─────────────────────────────────────────────────────────────────────────────╯🮘
23 23
                                                                               🮘
24 24
                                                                               🮘
crates/diff/tests/golden/focused_second_file_64x6.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮🮘
2 -
│ ▿ b.rs                                                +1 -1 │🮘
2 +
│ ⊙ b.rs                                                +1 -1 │🮘
3 3
├─────────────────────────────────────────────────────────────┤🮘
4 4
│ 1    1       keep                                           │▗
5 5
│ 2          - before                                         │▐
6 6
│      2     + after                                          │▝
crates/diff/tests/golden/highlighted_source_64x5.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮▐
2 -
│ ▿ a.rs                                                +2 -1 │▐
2 +
│ ⊙ a.rs                                                +2 -1 │▐
3 3
├─────────────────────────────────────────────────────────────┤▝
4 4
│ 1    1       highlighted context                            │🮘
5 5
│ 2          - old                                            │🮘
crates/diff/tests/golden/multi_hunk_gap_64x12.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮🮘
2 -
│ ▿ a.rs                                                +2 -2 │🮘
2 +
│ ⊙ a.rs                                                +2 -2 │🮘
3 3
├─────────────────────────────────────────────────────────────┤🮘
4 4
│ 1    1       keep                                           │🮘
5 5
│ 2          - old                                            │🮘
6 6
│      2     + new                                            │🮘
7 7
│            ⋮                                                │🮘
crates/diff/tests/golden/narrow_view_14x8.txt +1 -1
1 1
╭───────────╮▐
2 -
│ ▿ a.rs +… │▐
2 +
│ ⊙ a.rs +… │▐
3 3
├───────────┤▐
4 4
│ 1    1  … │▐
5 5
│ 2       … │▐
6 6
│      2  … │▐
7 7
│      3  … │▐
crates/diff/tests/golden/preamble_and_no_newline_64x17.txt +1 -1
7 7
│                                                             │🮘
8 8
│ Message body text 1.                                        │🮘
9 9
│ Message body text 2.                                        │🮘
10 10
╰─────────────────────────────────────────────────────────────╯🮘
11 11
╭─────────────────────────────────────────────────────────────╮🮘
12 -
│ ▿ a.rs                                                +1 -1 │🮘
12 +
│ ⊙ a.rs                                                +1 -1 │🮘
13 13
├─────────────────────────────────────────────────────────────┤🮘
14 14
│ 1          - old                                            │🮘
15 15
│      1     + new                                            │🮘
16 16
│              \ No newline at end of file                    │🮘
17 17
╰─────────────────────────────────────────────────────────────╯🮘
crates/diff/tests/golden/sticky_header_before_next_file_64x5.txt +1 -1
1 1
╰─────────────────────────────────────────────────────────────╯🮘
2 2
╭─────────────────────────────────────────────────────────────╮🮘
3 -
│ ▿ b.rs                                                +1 -1 │▗
3 +
│ ⊙ b.rs                                                +1 -1 │▗
4 4
├─────────────────────────────────────────────────────────────┤▐
5 5
│ 1    1       keep                                           │🮘
crates/diff/tests/golden/sticky_header_file_end_boundary_64x5.txt +2 -2
1 -
│ ▿ a.rs                                                +2 -1 │🮘
1 +
│ ⊙ a.rs                                                +2 -1 │🮘
2 2
├╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴┤▗
3 3
╰─────────────────────────────────────────────────────────────╯▐
4 4
╭─────────────────────────────────────────────────────────────╮🮘
5 -
│ ▿ b.rs                                                +1 -1 │🮘
5 +
│ ⊙ b.rs                                                +1 -1 │🮘
crates/diff/tests/golden/sticky_header_full_corner_boundary_64x5.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮🮘
2 -
│ ▿ a.rs                                                +2 -1 │▗
2 +
│ ⊙ a.rs                                                +2 -1 │▗
3 3
├╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴┤▐
4 4
╰─────────────────────────────────────────────────────────────╯🮘
5 5
╭─────────────────────────────────────────────────────────────╮🮘
crates/diff/tests/golden/sticky_header_inside_file_64x5.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮🮘
2 -
│ ▿ a.rs                                                +2 -1 │🮘
2 +
│ ⊙ a.rs                                                +2 -1 │🮘
3 3
├╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴┤▗
4 4
│ 3    4       tail                                           │▐
5 5
╰─────────────────────────────────────────────────────────────╯▐
crates/diff/tests/golden/sticky_header_replaces_chrome_64x5.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮🮘
2 -
│ ▿ a.rs                                                +2 -1 │▗
2 +
│ ⊙ a.rs                                                +2 -1 │▗
3 3
├╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴┤▐
4 4
│      3     + extra                                          │▐
5 5
│ 3    4       tail                                           │🮘
crates/diff/tests/golden/sticky_header_starting_64x5.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮▗
2 -
│ ▿ a.rs                                                +2 -1 │▐
2 +
│ ⊙ a.rs                                                +2 -1 │▐
3 3
├╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴┤▐
4 4
│ 2          - old                                            │🮘
5 5
│      2     + new                                            │🮘
crates/diff/tests/golden/wide_file_tree_120x12.txt +2 -2
1 1
          ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────╮▐
2 -
▿ rustik/ │ ▿ a.rs                                                                                              +2 -1 │▐
2 +
▿ rustik/ │ ⊙ a.rs                                                                                              +2 -1 │▐
3 3
  ⊙ a.rs  ├───────────────────────────────────────────────────────────────────────────────────────────────────────────┤▐
4 4
  ⊙ b.rs  │ 1    1       context                                                                                      │▐
5 5
          │ 2          - old                                                                                          │▐
6 6
          │      2     + new                                                                                          │▐
7 7
          │      3     + extra                                                                                        │▐
8 8
          │ 3    4       tail                                                                                         │▐
9 9
          ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯▐
10 10
          ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────╮🮘
11 -
          │ ▿ b.rs                                                                                              +1 -1 │🮘
11 +
          │ ⊙ b.rs                                                                                              +1 -1 │🮘
12 12
          ├───────────────────────────────────────────────────────────────────────────────────────────────────────────┤🮘