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

feat: add search functionality to select and checkbox prompt, based on #42 #374

Merged
merged 6 commits into from
Jul 24, 2024

Conversation

mario-dg
Copy link
Contributor

This commit is heavily inspired by gbataille's PR

What is the problem that this PR addresses?

Continued on the work mentioned above to integrate a search functionality to the select and checkbox prompt.
Should fix #33 and #42.

How did you solve it?

Taken the code from the previous PR, modified a bit to fit the latest updates, corrected type checking and linting.

Checklist

  • I have read the Contributor's Guide.
  • I will check that all automated PR checks pass before the PR gets reviewed.

mario-dg and others added 4 commits May 29, 2024 21:27
Instead of a prefix filter, the search filter is now searched within all entries. This seems to be more common than a prefix search.

Using the search functionality disabled the ability to select all options or invert the selection in the checkbox control. If the search filter is enabled, these two functionalities can now be used with the key modifier ctrl.

Updated the displayed instructions to match the changes made.
@kiancross
Copy link
Collaborator

@mario-dg Thanks for this PR. Please can you merge latest changes into this branch, then I will run the CI and review.

@mario-dg
Copy link
Contributor Author

mario-dg commented Jul 9, 2024

@kiancross, done 😄

Copy link
Collaborator

@kiancross kiancross left a comment

Choose a reason for hiding this comment

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

This PR is fantastic - thank you. I have tested it on my machine, and it all appears to work as expected.

I have left a couple of comments below, just to check you are happy with all the design decisions, but I think it is almost ready to merge (once the version numbers are fixed).

Thanks again.

@@ -179,8 +194,9 @@ def get_prompt_tokens() -> List[Tuple[str, str]]:
"class:instruction",
"(Use arrow keys to move, "
"<space> to select, "
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we happy to say that space can't be used in the search?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have to exclude it, since space is used to select an entry from the list. Otherwise we would have to come up with a rather complex solution to allow (de-)selection of an entry when the search is enabled.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Makes sense

if not self.search_filter:
return self.choices
filtered = [
c for c in self.choices if self.search_filter.lower() in c.title.lower()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm ok with this search mechanism, but it is not a prefix search like #42. Does this matter? Are there any downsides to searching for any occurrence of the substring? I suppose in the future, we can make the filter customisable, so it doesn't matter too much...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After using the prefix search for a few days it felt unnatural and not intuitive. I personally don't know any application that prefers a prefix search above a substring search.

A fuzzy search would probably be the best, but add unnecessary complexity and/or dependencies to this library.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for explaining

pyproject.toml Outdated Show resolved Hide resolved
questionary/version.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@kiancross kiancross left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks!

@kiancross kiancross merged commit 07f5c1a into tmbo:master Jul 24, 2024
30 checks passed
This was referenced Jul 24, 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.

Add prefix filter search in select control
2 participants