Ensure all search results are visible in theme list (#4473)

## Changes

- Add a threshold to determine when to reset window position

- Reset window position to show all results from the top when result set
is small

- Maintain scroll position for larger result sets to preserve navigation
context


https://github.com/user-attachments/assets/826a2411-9b31-4adb-b1b4-f55b05aa911d

Resolves https://github.com/ghostty-org/ghostty/discussions/4472
This commit is contained in:
Mitchell Hashimoto
2025-01-04 14:34:35 -08:00
committed by GitHub

View File

@ -11,6 +11,12 @@ const global_state = &@import("../global.zig").state;
const vaxis = @import("vaxis");
const zf = @import("zf");
// When the number of filtered themes is less than or equal to this threshold,
// the window position will be reset to 0 to show all results from the top.
// This ensures better visibility for small result sets while maintaining
// scroll position for larger lists.
const SMALL_LIST_THRESHOLD = 10;
pub const Options = struct {
/// If true, print the full path to the theme.
path: bool = false,
@ -323,9 +329,15 @@ const Preview = struct {
}
self.current, self.window = current: {
if (selected.len == 0) break :current .{ 0, 0 };
for (self.filtered.items, 0..) |index, i| {
if (std.mem.eql(u8, self.themes[index].theme, selected))
break :current .{ i, i -| relative };
if (std.mem.eql(u8, self.themes[index].theme, selected)) {
// Keep the relative position but ensure all search results are visible
const new_window = i -| relative;
// If the new window would hide some results at the top, adjust it
break :current .{ i, if (self.filtered.items.len <= SMALL_LIST_THRESHOLD) 0 else new_window };
}
}
break :current .{ 0, 0 };
};