cli: handle mouse scroll before setting window

This commit is contained in:
Paul Berg
2024-09-30 11:02:32 +02:00
parent f434c2cb71
commit aa10e5160b

View File

@ -502,20 +502,6 @@ const Preview = struct {
.height = .{ .limit = win.height }, .height = .{ .limit = win.height },
}); });
if (self.filtered.items.len == 0) {
self.current = 0;
self.window = 0;
} else {
const start = self.window;
const end = self.window + theme_list.height - 1;
if (self.current > end)
self.window = self.current - theme_list.height + 1;
if (self.current < start)
self.window = self.current;
if (self.window >= self.filtered.items.len)
self.window = self.filtered.items.len - 1;
}
var highlight: ?usize = null; var highlight: ?usize = null;
if (self.mouse) |mouse| { if (self.mouse) |mouse| {
@ -536,6 +522,20 @@ const Preview = struct {
} }
} }
if (self.filtered.items.len == 0) {
self.current = 0;
self.window = 0;
} else {
const start = self.window;
const end = self.window + theme_list.height - 1;
if (self.current > end)
self.window = self.current - theme_list.height + 1;
if (self.current < start)
self.window = self.current;
if (self.window >= self.filtered.items.len)
self.window = self.filtered.items.len - 1;
}
theme_list.fill(.{ .style = self.ui_standard() }); theme_list.fill(.{ .style = self.ui_standard() });
for (0..theme_list.height) |row| { for (0..theme_list.height) |row| {