fix: scroll_cursor_min_border_distance should always be read from config

And fix an off-by-one issue causing the distance at the bottom of the view
to be one line less than the top.

close #506
This commit is contained in:
CJ van den Berg 2026-02-18 14:14:47 +01:00
parent f4cf15e5c3
commit 4fcde7b861
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 11 additions and 10 deletions

View file

@ -9,7 +9,7 @@ col: usize = 0,
rows: usize = 0,
cols: usize = 0,
const scroll_cursor_min_border_distance = 5;
pub var scroll_cursor_min_border_distance: usize = 5;
const scroll_cursor_min_border_distance_mouse = 1;
const Self = @This();
@ -65,7 +65,7 @@ inline fn is_at_top(self: *const Self) bool {
inline fn is_at_bottom(self: *const Self, root: Buffer.Root) bool {
if (root.lines() < self.rows) return true;
return self.row >= root.lines() - scroll_cursor_min_border_distance;
return self.row >= root.lines() -| scroll_cursor_min_border_distance;
}
pub inline fn is_visible(self: *const Self, cursor: *const Cursor) bool {
@ -96,7 +96,7 @@ inline fn to_cursor_bottom(self: *const Self, root: Buffer.Root) Cursor {
fn clamp_row(self: *Self, cursor: *const Cursor, abs: bool, bottom_offset: usize) void {
const top_min_border_distance: usize = if (abs) scroll_cursor_min_border_distance_mouse else scroll_cursor_min_border_distance;
const bottom_min_border_distance: usize = top_min_border_distance + bottom_offset;
const bottom_min_border_distance: usize = top_min_border_distance + bottom_offset + 1;
if (cursor.row < top_min_border_distance) {
self.row = 0;
return;