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

Filter selection prompt items with search #1797

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

DanBiscotti
Copy link

@DanBiscotti DanBiscotti commented Apr 8, 2025

fixes #1546

  • I have read the Contribution Guidelines
  • I have commented on the issue above and discussed the intended changes
  • A maintainer has signed off on the changes and the issue was assigned to me
  • All newly added code is adequately covered by tests
  • All existing tests are still running without errors
  • The documentation was modified to reflect the changes OR no documentation changes are required.

Changes

I changed the code so that now when a user searches, the list is filtered down to only those items which match the search term

ListPromptState.cs

There are now 3 lists which hold the current state of the prompt:

  • Items This existed before and contains all the items
  • VisibleItems This list contains only items which match the search term, or any groups which contain a child which matches the search term
  • _selectableItems This list contains only the subset of VisibleItems which are selectable (ie. not a group if in leaf mode, following the same logic as before with _leafIndexes). it is a list of SelectableItem which contains the ListPromptItem and also the index of the item in VisibleItems.

VisibleItems and _selectableItems are updated every time the search term changes, when the user is navigates the list the only the index of the item in _selectableItems is updated (which is stored in _selectableIndex).

ListPrompt.cs

  • BuildRenderable now uses VisibleItems
  • added argument for filterOnSearch

SelectionPrompt.cs

  • added FilterOnSearch property
  • Removed the spacebar as a key which submits, to allow the search to contain spaces
  • Added null check for when state.Current == null. This happens when the VisibleItems is filtered to the point it contains no items
  • removed skipUnselectableItems argument as it wasn't being used

SelectionPromptExtensions.cs

  • Added optional bool to the EnableSearch method to set FilterOnSearch

MultiSelectionPrompt.cs

  • added argument for filterOnSearch
  • removed skipUnselectableItems argument as it wasn't being used

IListPromptStrategy

  • removed skipUnselectableItems argument as it wasn't being used

Please upvote 👍 this pull request if you are interested in it.

@DanBiscotti
Copy link
Author

I realize it's not perfect yet, but would be good to hear what you think of the idea, I haven't made a PR in the repo before so apologies if I've missed something!

@DanBiscotti
Copy link
Author

@microsoft-github-policy-service agree

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.

Allow for multiple matching search result items with the SelectionPrompt
1 participant