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

Add sorting to command palette #4927

Closed
willmcgugan opened this issue Aug 23, 2024 · 6 comments · Fixed by #4994
Closed

Add sorting to command palette #4927

willmcgugan opened this issue Aug 23, 2024 · 6 comments · Fixed by #4994
Assignees
Labels
bug Something isn't working

Comments

@willmcgugan
Copy link
Collaborator

The command palette doesn't sort the matches other than alphabetically.

There does seem to be code in there to rate matches, and the docs do say the score is used in sorting. But no sorting occurs.

You can see this with the current system commands. If I type hel I get two results: Quit the application and show keys and help panel, in that order. I would expect the help panel to be on top as it is a better match according to the code in fuzzy.py.

@TomJGooding
Copy link
Contributor

This might be an issue with the matcher scoring?

from textual.fuzzy import Matcher


def test_match():
    matcher = Matcher("hel")
    help_match = matcher.match("Show keys and help panel")
    quit_match = matcher.match("Quit the application")

    assert help_match > quit_match

@TomJGooding
Copy link
Contributor

I don't fully understand the scoring, but I suspect the problem is the first character match:

Show keys and help panel
 ^    ^         ^

Quit the application
      ^^    ^

@darrenburns darrenburns self-assigned this Sep 12, 2024
@darrenburns darrenburns added the bug Something isn't working label Sep 12, 2024
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

@TomJGooding
Copy link
Contributor

Sorry just to clarify for future reference, I'm a bit confused why this issue is closed? The command palette sorting described in the original issue is still the same on main?

If I type hel I get two results: Quit the application and show keys and help panel, in that order. I would expect the help panel to be on top as it is a better match according to the code in fuzzy.py.

@darrenburns
Copy link
Member

I made it sort using the match score (I believe!), but never looked into any deficiencies in the scoring algorithm itself, as it seemed to give better results and I never checked the specific example in the original issue.

@darrenburns
Copy link
Member

Shall we create a separate issue to cover improving the scoring and link to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants