Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* crash when opening submodule ([#2895](https://github.com/gitui-org/gitui/issues/2895))
* when staging the last file in a directory, the first item after the directory is no longer skipped [[@Tillerino](https://github.com/Tillerino)] ([#2748](https://github.com/gitui-org/gitui/issues/2748))
* index-out-of-bounds panic when unstaging lines near the end of a diff ([#2953](https://github.com/gitui-org/gitui/issues/2953))
* keep scrolled text visible when terminal resizing changes wrapped line counts [[@jlu-lujing](https://github.com/jlu-lujing)] ([#2149](https://github.com/gitui-org/gitui/issues/2149))

## [0.28.1] - 2026-03-21

Expand Down
43 changes: 34 additions & 9 deletions src/components/utils/scroll_vertical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,23 @@ impl VerticalScroll {
) -> usize {
self.visual_height.set(visual_height);

let new_max = if visual_height == 0 {
0
} else {
selection_max.saturating_sub(visual_height)
};
self.max_top.set(new_max);

let current_top = self.top.get().min(new_max);
let new_top = calc_scroll_top(
self.get_top(),
current_top,
visual_height,
selection,
selection_max,
);
)
.min(new_max);
self.top.set(new_top);

if visual_height == 0 {
self.max_top.set(0);
} else {
let new_max = selection_max.saturating_sub(visual_height);
self.max_top.set(new_max);
}

new_top
}

Expand Down Expand Up @@ -165,6 +167,29 @@ mod tests {
assert_eq!(calc_scroll_top(4, 0, 4, 3), 0);
}

#[test]
fn test_scroll_clamps_top_when_content_reflows_shorter() {
let scroll = VerticalScroll::new();
scroll.max_top.set(20);
scroll.top.set(20);

assert_eq!(scroll.update_no_selection(20, 10), 10);
assert_eq!(scroll.get_top(), 10);

assert_eq!(scroll.update_no_selection(12, 10), 2);
assert_eq!(scroll.get_top(), 2);
}

#[test]
fn test_scroll_clamps_top_when_viewport_grows() {
let scroll = VerticalScroll::new();
scroll.max_top.set(10);
scroll.top.set(10);

assert_eq!(scroll.update_no_selection(20, 15), 5);
assert_eq!(scroll.get_top(), 5);
}

#[test]
fn test_scroll_bottom_into_view() {
let visual_height = 10;
Expand Down