From 9fa404c3907d3cb483f2a038170ce39197f07707 Mon Sep 17 00:00:00 2001 From: Bryan Lee <38807139+liby@users.noreply.github.com> Date: Fri, 3 Jan 2025 16:23:10 +0800 Subject: [PATCH] Ensure all search results are visible in theme list When searching in the theme list (e.g., searching for "Snazzy"), some matching themes might be hidden due to incorrect window position handling. This fix ensures all matching themes are visible by adjusting the window position logic. --- src/cli/list_themes.zig | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cli/list_themes.zig b/src/cli/list_themes.zig index c4dd415e7..22e22a972 100644 --- a/src/cli/list_themes.zig +++ b/src/cli/list_themes.zig @@ -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 }; };