textual icon indicating copy to clipboard operation
textual copied to clipboard

Add sorting to command palette

Open willmcgugan opened this issue 1 year ago • 2 comments

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.

willmcgugan avatar Aug 23 '24 16:08 willmcgugan

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 avatar Aug 23 '24 17:08 TomJGooding

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
      ^^    ^

TomJGooding avatar Aug 23 '24 18:08 TomJGooding

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

github-actions[bot] avatar Sep 16 '24 09:09 github-actions[bot]

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.

TomJGooding avatar Sep 17 '24 20:09 TomJGooding

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 avatar Sep 17 '24 20:09 darrenburns

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

darrenburns avatar Sep 17 '24 21:09 darrenburns