diff: Prehighlight the next page
e8888f597ecc402eafec08dfefae5818340b7c25
Request one additional viewport of syntax-highlight work whenever visible rows are scheduled. This removes the fixed lookahead option and keeps scrolling warm without exposing another tuning knob. Assisted-by: Codex:gpt-5.5
1 parent
e0534262
crates/diff/src/viewer.rs
+2 -7
| 53 | 53 | const RENAME_ARROW: &str = "→"; |
|
| 54 | 54 | /// Missing trailing newline marker. |
|
| 55 | 55 | const NO_NEWLINE_MARKER: &str = "\\ No newline at end of file"; |
|
| 56 | 56 | /// Marker cell shown between hunks in the diff marker column. |
|
| 57 | 57 | const HUNK_GAP_MARKER_CELL: &str = " ⋮ "; |
|
| 58 | - | /// Default highlight lookahead after the visible viewport. |
|
| 59 | - | const DEFAULT_HIGHLIGHT_LOOKAHEAD: usize = 4; |
|
| 60 | 58 | /// Default syntax theme selection stored in highlight keys. |
|
| 61 | 59 | const DEFAULT_THEME: &str = "auto"; |
|
| 62 | 60 | /// Number of rows in a sticky file header. |
|
| 63 | 61 | const STICKY_HEADER_ROWS: usize = 3; |
|
| 64 | 62 | /// Number of body rows moved by keyboard line-scroll inputs. |
| 146 | 144 | } |
|
| 147 | 145 | ||
| 148 | 146 | /// Diff viewer options. |
|
| 149 | 147 | #[derive(Clone, Debug)] |
|
| 150 | 148 | pub struct DiffOptions { |
|
| 151 | - | /// Number of rows after the visible viewport to request for highlighting. |
|
| 152 | - | pub highlight_lookahead: usize, |
|
| 153 | 149 | /// Optional syntax override stored in highlight requests. |
|
| 154 | 150 | pub syntax: Option<String>, |
|
| 155 | 151 | /// Theme name stored in highlight requests. |
|
| 156 | 152 | pub theme: String, |
|
| 157 | 153 | /// Positive and negative colors used for diff chrome. |
| 328 | 324 | } |
|
| 329 | 325 | ||
| 330 | 326 | impl Default for DiffOptions { |
|
| 331 | 327 | fn default() -> Self { |
|
| 332 | 328 | Self { |
|
| 333 | - | highlight_lookahead: DEFAULT_HIGHLIGHT_LOOKAHEAD, |
|
| 334 | 329 | syntax: None, |
|
| 335 | 330 | theme: DEFAULT_THEME.to_owned(), |
|
| 336 | 331 | diff_palette: DiffPalette::default(), |
|
| 337 | 332 | file_tree: FileTreeMode::default(), |
|
| 338 | 333 | file_tree_root: ".".to_owned(), |
| 878 | 873 | ViewChange::Changed => Control::Redraw, |
|
| 879 | 874 | ViewChange::Unchanged => Control::Continue, |
|
| 880 | 875 | } |
|
| 881 | 876 | } |
|
| 882 | 877 | ||
| 883 | - | /// Returns highlight requests for visible source rows plus configured lookahead. |
|
| 878 | + | /// Returns highlight requests for visible source rows plus one viewport of lookahead. |
|
| 884 | 879 | pub fn highlight_requests(&mut self, area: Rect) -> Vec<HighlightRequest> { |
|
| 885 | 880 | let diff = self.layout(area).diff; |
|
| 886 | - | let take = diff.rows.saturating_add(self.options.highlight_lookahead); |
|
| 881 | + | let take = diff.rows.saturating_mul(2); |
|
| 887 | 882 | let view = View::new( |
|
| 888 | 883 | self.state.scroll.offset, |
|
| 889 | 884 | self.render_rows_for(self.state.scroll.offset, diff.rows), |
|
| 890 | 885 | diff.rows, |
|
| 891 | 886 | ); |
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
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
assets/css/style.css
+0 -0
assets/css/style.css
+0 -0
a.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
b.rs
+0 -0