helix icon indicating copy to clipboard operation
helix copied to clipboard

[BUG] Go to file is capturing surrounding single quotes

Open lukepighetti opened this issue 3 years ago • 3 comments

files

index.js
example.js

consider a file example.js that contains the line import './index.js' or import 'index.js'

You cannot navigate to index.js by using gf on either line

What's interesting is you can manually select index.js and hit gf and it works.

It looks like gf is capturing the surrounding single quotes. Neovim does not exhibit that behavior.

So in Helix you have to mi'gf and in Neovim you do gf

lukepighetti avatar Oct 06 '22 14:10 lukepighetti

Is removing quotes/double quotes from the selection an acceptable approach here?

I wonder if it makes sense to have something "smarter" at work here. In this example one could have import 'index' without the file extension, and with the current approach this would not open the correct file.

dariooddenino avatar Oct 18 '22 08:10 dariooddenino

In this particular case I think it's okay to Do It Like Neovim™. It's just too common to drop a cursor on the line import './index.js' hit gf and expect it to open ./index.js

lukepighetti avatar Oct 18 '22 11:10 lukepighetti

When there's only a single cursor with a selection width of 1, the current LONG word is considered as the filename, so it's similar to doing miWgf:

https://github.com/helix-editor/helix/blob/7f75458e6f29f2dc0717557a1072b70deee27acb/helix-term/src/commands.rs#L1028-L1044

We could trim surround character pairs like () and ' before trying to open the file like @dariooddenino suggested.

I wonder if it makes sense to have something "smarter" at work here. In this example one could have import 'index' without the file extension, and with the current approach this would not open the correct file.

Cases like these are better handled by the LSP that has the additional context at hand to resolve the path reliably.

sudormrfbin avatar Oct 18 '22 17:10 sudormrfbin