zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
47.36k stars 2.75k forks source link

Better sorting of files in Command-P dialog #16379

Open brandondrew opened 1 month ago

brandondrew commented 1 month ago

Check for existing issues

Describe the feature

As can be seen in the attached video, a simple search can result in all of the relevant results being buried at the bottom, while everything in a nearly-irrelevant directory with deeply nested subdirectories appears at the top.

I believe the simplest and most general-purpose solution involves one primary fix and possibly another related fix.

First, the percentage of the query that is matched by the file path should be treated as important. If the query covers 80% of the full path (including file name) of one file, that should be placed way above something for which the query matches only 20%.

The second thing (which could be seen as a separate problem but is slightly related) is to treat contiguous characters as far more important than discontiguous characters. I'm not 100% sure this is currently a problem with Zed, but if memory serves me well I've seen this occur in Zed (and definitely other apps like Alfred, where searching is a central feature) where I type a word and first am presented with things that don't look remotely like matches but which have very long names and therefore will match just about anything that is typed.

In the example I gave, one might argue that those files belong at the bottom because what I typed is in the directory path rather than the file name, and I would agree that file name should be more important than directory path, but not to such an extreme that dozens of irrelevant results take precendence over the far more important results that are the part of my project that I actually personally edit. (I'm not expecting Zed to know that the vendor directory is full of stuff I don't care about, which is why I'm offering a general-purpose proposal to solve not just this case but many others.)

If applicable, add mockups / screenshots to help present your vision of the feature

https://github.com/user-attachments/assets/087f3a7e-721f-4b2f-ab95-60f62f67fa60

notpeter commented 1 month ago

See also: