Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement filter_mode for both select and multiselect prompts #49

Closed

Conversation

fadeevab
Copy link
Owner

@fadeevab fadeevab commented May 1, 2024

  1. List renders through the self.filter always.
  2. Rc<RefCell> is to handle a subset of filtered mutable references to the items from the
    same structure.

1. List renders through the `filter` always.
2. Rc<RefCell> is to handle a subset of filtered
mutable references to the items from the
same structure.
Copy link
Owner Author

@fadeevab fadeevab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cylewitruk @antoinePutmans I added a quick tour through the patch for you. It implements filtering for both select and mutliselect on top of the previous PR. Welcome to test!

}
}
}
self.filter.set(self.items.to_vec());
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, the self.filter is initiated to all items.

@@ -94,24 +115,34 @@ impl<T: Clone> PromptInteraction<Vec<T>> for MultiSelect<T> {
fn on(&mut self, event: &Event) -> State<Vec<T>> {
let Event::Key(key) = event;

if let Some(state) = self.filter.on(key, self.items.clone()) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, filter is updated.

for (i, item) in self.items.iter().enumerate() {
line2.push_str(&theme.format_multiselect_item(
let mut items_render = String::new();
for (i, item) in self.filter.items().iter().map(|i| i.borrow()).enumerate() {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, just replacing self.items to self.filter.items(). The same in Select.

@cylewitruk
Copy link
Contributor

Will give it a try tomorrow! 😄

@antoinePutmans
Copy link
Contributor

Good job @fadeevab 💪 I will test it tomorrow as well 😄

@antoinePutmans
Copy link
Contributor

@fadeevab Hey, I tested the new feature, it works fine 👍
The only thing that I would say feels a bit weird when using the filter on the multiselect is that the selected items wont be sent if the filter does not match them.

Screen.Recording.2024-05-04.at.19.31.21.mov

For example here, Prettier wont be in the result even if he's selected.

@fadeevab
Copy link
Owner Author

fadeevab commented May 4, 2024

@fadeevab Hey, I tested the new feature, it works fine 👍 The only thing that I would say feels a bit weird when using the filter on the multiselect is that the selected items wont be sent if the filter does not match them.

Interesting, I haven't thought about it... I think a similar problem is in the select: it doesn't allow to select something invisible, and also it doesn't preserve the cursor once the filter was cleared.

@fadeevab
Copy link
Owner Author

fadeevab commented Jun 1, 2024

@antoinePutmans Okay, I did this: it holds the item selection for multi-select list even when they are filtered out
image

and after Enter it rendered the items that were actually selected:
image

@fadeevab
Copy link
Owner Author

fadeevab commented Jun 2, 2024

Superseded by PR #52

@fadeevab fadeevab closed this Jun 2, 2024
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.

None yet

3 participants