SpartanJ / ecode

Lightweight multi-platform code editor designed for modern hardware with a focus on responsiveness and performance.
MIT License
940 stars 13 forks source link

Implement glob match for path and extension search in Locate bar #336

Closed Curculigo closed 3 weeks ago

Curculigo commented 2 months ago

I want to list all files that have .txt extension in an opened folder.

SpartanJ commented 2 months ago

How? All at once? How would you do it in other editor? If you just want to search for a file use the universal locator... CTRL+K or Alt+1.

Curculigo commented 2 months ago

Sorry. I mean listing them, not opening them all at once. I will choose which ones to open in the list.

SpartanJ commented 2 months ago

Go To Locate (Ctrl+k or Alt+1 or click in "Locate" below -> write: .txt. It should be enough.

Curculigo commented 2 months ago

Will it do a search recursively in all sub-directories of the opened folder?

SpartanJ commented 2 months ago

Yes, exactly. When you open a folder it generates the complete list of files from the extensions supported and you can find any file from the locator.

Curculigo commented 2 months ago

Can I tell it to search only in a specific sub-directory? I don't want to open that directory as the new folder.

SpartanJ commented 2 months ago

You can filter from path, so if you need to search some sub-directory you write the partial path: root/subdir/etc and it will list files from there.

Curculigo commented 2 months ago

Will something like root/subdir/etc/.txt work?

SpartanJ commented 2 months ago

Yes, it's a fuzzy search, it will try to approximate the result: Screenshot_20240924_171229

Curculigo commented 2 months ago

I don't think the feature works as intended. Do you still have llvm-mingw? Try opening llvm-mingw-20240917-ucrt-x86_64 as a folder and listing all header files (.h extension) in the include directory. The list is definitely not complete.

Curculigo commented 2 months ago

I found another quirk. Try to list all files in the bin directory with bin\. It will not list all files in bin as intended and will also list files not in bin, e.g: files in lib. Btw, I think forward slash should be used instead of backward slash. I tried with forward slash (bin/) and it doesn't work.

SpartanJ commented 2 months ago

I don't think you understood how the feature works, it's a fuzzy search, given low density information like .h won't give you good results, it's not trying to filter directories or files, it's just doing a quick string matching, some improvements can be done to have better approximations for your use case: for example, I could give more weight to recognized extensions if written, or try to prioritize filtering folders if a folder separator is used (/ or \). Fuzzy search is more oriented to do file search than what you're trying to achieve, it's a very common feature in modern editors. I'll change the feature request title to "improve fuzzy search for path and extension matching".

Curculigo commented 2 months ago

This is the first time I hear about fuzzy search. Is it the same thing as the search suggestions in the address bar of Firefox? It will suggest to you the URLs in history or bookmarks based on what you have typed.

SpartanJ commented 2 months ago

I'm simply using this feature wrong. There is no enhancement needed.

Understood, but I do think it's a good idea to have a mode where filtering works the way you're looking for, I'm thinking I can add and extra mode as these ones and filter with a glob pattern match.

This is the first time I hear about fuzzy search. Is it the same thing as the search suggestions in the address bar of Firefox? It will suggest to you the URLs in history or bookmarks based on what you have typed.

They use a fuzzy search too, probably different because they match against different kind of information but yes.

Curculigo commented 2 months ago

I'm simply using this feature wrong. There is no enhancement needed.

Understood, but I do think it's a good idea to have a mode where filtering works the way you're looking for, I'm thinking I can add and extra mode as these ones and filter with a glob pattern match.

I found more quirks of the feature. This is the reason why I deleted my previous comments. It's really weird. For example, it can't provide suggestions for the x86_64-w64-mingw32 directory. I typed x86 and it suggested some header files whose names started with x86 to me. But immediately after I typed _, it started to suggest nonsense. Why can't it handle x86_ correctly?

SpartanJ commented 2 months ago

It's just a probabilistic algorithm, it will assign some score based on the consequent matches found in a string and sort the list by score. If it was nonsense to you it's probably because there are no good matches with _. The idea is that approximate a result based on what the user wrote even if it's not exactly that. It's a veeery simple algorithm, it can be improved, there are many fuzzy match implementations.

SpartanJ commented 2 months ago

I ended up implementing it for me, it can be useful having the possibility of glob matching the directory tree:

https://github.com/user-attachments/assets/6420cad2-f2bb-4243-a25c-79cdb5beb377