Shizcow / dmenu-rs

A pixel perfect port of dmenu, rewritten in Rust with extensive plugin support
GNU General Public License v3.0
200 stars 9 forks source link

Fuzzy matching without input string #61

Closed jbirnick closed 10 months ago

jbirnick commented 10 months ago

When using the fuzzy plugin, then when starting dmenu, without having typed anything yet, the entries are not sorted by their input order, but by their length. I guess that is because they are compared to the empty string as a search string.

It's probably not intended to have this behavior, as often the input order for e.g. menus or clipboard managers matters and shouldn't be disturbed just because fuzzy search is enabled.

Shizcow commented 10 months ago

I hadn't thought about this, but it does make sense that the original input order should be prioritized. This line is the reason that entries are default-sorted by their order. If I recall correctly (I did write this years ago) the fuzzy searcher will assign the same score to both "XYZW" and "XY" when searching for "XY", so this was added to prioritize exact matches.

I suppose the correct behavior would be:

If the search string is empty
    Order is preserved (aka no calls to sort_by_key)
If the search string is non-empty
    Sort first by fuzzy match score
    Then sort by length, smallest first
    Then sort by the order from the input

I believe the non-empty case is already addressed. To implement the empty case, we'd just need to place the sort_by_key calls in an if(searchterm.len()) (or similar).

@jbirnick I won't be near a development environment for few days. While I can't edit/test this, I can review a pull request if you can confirm that the suggested edit works. Otherwise I'll get to this when I can.

jbirnick commented 10 months ago

Thank you!

Unfortunately I can't work myself into your code so quickly, so I guess it has to wait until you want to work on it. :/ But it's actually not much of a problem for me, I just wanted to note it.