focus-editor / focus

A simple and fast text editor
GNU General Public License v3.0
1.76k stars 98 forks source link

Feature request: word completion #48

Open luis-reyes-a opened 1 year ago

luis-reyes-a commented 1 year ago

A feature I really can't live without from emacs/vim is a basic way to complete text. The way it works is you type something like "get_" and then you press tab (or whatever keybinding) to cycle between different options like "get_entity", "get_string", "get_thing", etc. I think this feature fits in with focus's style since it's very basic and easy to understand and it's not annoying and in-your-way as IDE-style dropdown word completions.

Emacs also prioritizes completions from the current file that are nearest to the cursor and then searches for completions in the most recently opened files, which I find works extremely well.

This is what it looks like. After it cycles through all the completions it returns back to the original text that was typed in. 4ed_1veXRW79TC

You could have settings that sets a max count of all the completions focus can find and you could also have a setting if you prefer the word completion to be case sensitive or not (or maybe make two separate commands for each one).

mathaou commented 1 year ago

Pour one out for whoever has to implement this bad boy

https://en.m.wikipedia.org/wiki/Radix_tree

luis-reyes-a commented 1 year ago

I wouldn't bother doing anything complicated like that. The thing is for word completion to be useful you don't really need more than 12 completions because otherwise just typing out the full text would be faster than cycling through all the options.

A simple regex search would work. Here's an implementation of this I made for sublime and it works great: https://gist.github.com/starradian/3a0afed430e9959f744cb1a99b76c363