Textualize / textual

The lean application framework for Python. Build sophisticated user interfaces with a simple Python API. Run your apps in the terminal and a web browser.
https://textual.textualize.io/
MIT License
25.08k stars 767 forks source link

Add sorting to command palette #4927

Closed willmcgugan closed 1 day ago

willmcgugan commented 3 weeks ago

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 commented 3 weeks ago

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 commented 3 weeks ago

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
      ^^    ^
github-actions[bot] commented 1 day ago

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

TomJGooding commented 11 hours ago

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 commented 11 hours ago

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 commented 10 hours ago

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