jasonwilliams / vscode-helix

MIT License
167 stars 8 forks source link

Current motion limited on single line? #2

Closed taminhtienhai closed 8 months ago

taminhtienhai commented 9 months ago

Big thanks for making Helix possible in VSCode! I just wanted to flag a few bugs I ran into

jasonwilliams commented 9 months ago

@taminhtienhai could you be more specific with these keymaps? Which ones are you referring to for all of them (and which mode) https://docs.helix-editor.com/keymap.html

beeb commented 8 months ago

I can confirm that, e.g. when hitting x multiple times in normal mode, only a single line gets selected (contrary to the behavior in helix that selects as many lines as the key was pressed).

Xarakiri commented 8 months ago

Exactly the same problem as @beeb Plus, in addition to that, x selection does not work on an empty line ref: https://docs.helix-editor.com/keymap.html#selection-manipulation

jasonwilliams commented 8 months ago

Thanks for clarifying, I’ll take a look

jasonwilliams commented 8 months ago

Ok So I've taken a look at the code that handles this, its easy to implement in a naive way but it would cause some troubling memory issues on a large file. Ill explain:

Each time you hit w it falls into this handler: https://github.com/jasonwilliams/vscode-helix/blob/main/src/actions/operator_ranges.ts#L399-L414

This handler will grab all the text from the current line and load it into memory, it will then iterate through all the characters until it has a bunch of ranges to return representing words. This is fine in its current state, but if we remove the line limit we would be loading the entire contents of the file (or from your cursor tot he bottom) into memory. People work on large files and this would essentially slow things down.

This would need to be refactored into something like a generator that can return characters on demand. That way we're never loading the entire contents of the file into memory in order for this feature to work and it remains performant.

Implementation Details

I think instead of passing text into wordRanges here, we should pass a generator instead. That generator would return character by character and once it reaches the end of a line it loads the next line and continues, it will keep going until there's no more content left

I'm open for contributions to this.

jasonwilliams commented 8 months ago

https://github.com/jasonwilliams/vscode-helix/releases/tag/v0.4.0 is released and should have some of these fixes in