diff: Fix sticky file header bug
19f0e9ba70a2ab6b16a12f82f1f4ab777dce8882
The header now stays pinned while the current file still owns the body area.
1 parent
750d7fb7
crates/diff/src/renderer.rs
+2 -3
| 686 | 686 | } |
|
| 687 | 687 | ||
| 688 | 688 | /// Returns the number of sticky rows for the current offset. |
|
| 689 | 689 | fn sticky_row_count(&self, scroll: usize, visible_rows: usize) -> usize { |
|
| 690 | 690 | self.sticky_start(scroll, visible_rows) |
|
| 691 | - | .map_or(0, |_| STICKY_HEADER_ROWS) |
|
| 691 | + | .map_or(0, |_| STICKY_HEADER_ROWS.min(visible_rows)) |
|
| 692 | 692 | } |
|
| 693 | 693 | ||
| 694 | 694 | /// Returns the source row for the sticky header at the current offset. |
|
| 695 | 695 | fn sticky_start(&self, scroll: usize, visible_rows: usize) -> Option<usize> { |
|
| 696 | 696 | let rows = self.row_count(); |
| 700 | 700 | } |
|
| 701 | 701 | let location = self.file_row_location(scroll)?; |
|
| 702 | 702 | if scroll <= location.start { |
|
| 703 | 703 | return None; |
|
| 704 | 704 | } |
|
| 705 | - | let file_bottom = location.end.saturating_sub(1); |
|
| 706 | - | if file_bottom < scroll.saturating_add(visible_rows) { |
|
| 705 | + | if location.end <= scroll.saturating_add(STICKY_HEADER_ROWS.min(visible_rows)) { |
|
| 707 | 706 | return None; |
|
| 708 | 707 | } |
|
| 709 | 708 | Some(location.start) |
|
| 710 | 709 | } |
|
| 711 | 710 |
a.rs
+0 -0
a.rs
+0 -0
b.rs
+0 -0
a.rs
+0 -0
crates/diff/tests/golden/bottom_of_file_64x5.txt
+4 -4
| 1 | - | โ 2 - old โ๐ฎ |
|
| 2 | - | โ 2 + new โ๐ฎ |
|
| 3 | - | โ 3 + extra โ๐ฎ |
|
| 4 | - | โ 3 4 tail โโ |
|
| 1 | + | โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ๐ฎ |
|
| 2 | + | โ โ a.rs +2 -1 โ๐ฎ |
|
| 3 | + | โโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโดโค๐ฎ |
|
| 4 | + | โ 3 4 tail โ๐ฎ |
|
| 5 | 5 | โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏโ |