Skip to content

fixed the cursor index when filtering list#111

Open
menosbits wants to merge 1 commit into
meszmate:mainfrom
menosbits:main
Open

fixed the cursor index when filtering list#111
menosbits wants to merge 1 commit into
meszmate:mainfrom
menosbits:main

Conversation

@menosbits
Copy link
Copy Markdown

In src/components/list.zig, the function updateFilter() sets the List's cursor field to "self.filtered_indices.items.len - 1" — i.e., to the last filtered item — when the cursor field is greater than or equal to filtered_indices.items.len and that length is greater than zero.

This behavior is confusing because it makes it appear as if there is only one filtered item, while there are other items above. You can see the behavior in this video:

Before.changes.mp4

In my view, the correct behavior is to reset the cursor to the first item when the list is filtered. Accordingly, the code has been changed to the following:

--- a/src/components/list.zig
+++ b/src/components/list.zig
@@ -391,7 +391,7 @@ pub fn List(comptime T: type) type {
             }
 
             if (self.cursor >= self.filtered_indices.items.len and self.filtered_indices.items.len > 0) {
-                self.cursor = self.filtered_indices.items.len - 1;
+                self.cursor = 0;
             }
             self.ensureVisible();
         }

This is the behavior after the change:

After.changes.mp4

Nice library, btw. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant