abhinav / git-spice

Manage stacked Git branches
https://abhinav.github.io/git-spice/
GNU General Public License v3.0
247 stars 17 forks source link

request: branch selector auto-focuses on the most relevant branch when searching #430

Closed snokpok closed 1 month ago

snokpok commented 1 month ago

Hi! I have been daily driving git-spice for a while and noticed that when I do gs branch checkout or anything that opens the branch selector widget, and then I try to search for a branch name, the cursor does not focus on the most relevant branch matching my search term -- it focuses on the very top branch or the current branch in the selector widget instead, which is fine for the most part, but I expect for, say, the most relevant one to appear first (e.g matched by prefix)

For instance, I have this stack tree, and I'm currently on branch marketing:

main <- marketing (current) <- marketing-2

If I search for "main", it would be like this (the [..] are the characters that get highlighted):

[main] <- [ma]rket[in]g (current) <- [ma]rket[in]g-2

But my cursor is still on marketing, meanwhile the main branch matched my search term completely; I would expect in that case the main branch should be focused i.e:

[main] (current) <- [ma]rket[in]g <- [ma]rket[in]g-2

It also doesn't have to be an exact match to be focused; something like if I search for "mai", then I should expect main to be focused because "mai" is a prefix of main, as opposed to the other two branches marketing and marketing-2.

Let me know if this is something we can implement; I'm open to work on this.

abhinav commented 1 month ago

Hello! Yes, this is a limitation in the current logic and worth fixing.

Context: fuzzy matching and prioritization logic for the widget is super naive. It's just an in-order subsequence match, prioritizing either the passed-in default (usually current branch), or the first entry if the default is filtered out.

I've been meaning to switch to https://github.com/sahilm/fuzzy or similar for this logic, but haven't gotten around to it. If you're up for it, a PR doing this will be welcome. Otherwise, I expect I'll get to it at some point in the future now that there's an issue for it.

snokpok commented 1 month ago

Awesome, I'll check out that library and send in a PR