I’m trying to write a telescope.nvim version of :tselect
that uses the current word or visual selection as the search target.
To do this I need to determine what mode we were in just before the picker was invoked. The typical approach would be to define two functions and map them separately for visual and normal mode. However, in the case of implementing a telescope.nvim picker this won’t work because I don’t want to have two separate pickers one specific to visual mode and one specific to normal mode. Obviously I could pass which mode we’re coming from as a parameter to the picker to get around having two pickers, but I’m trying to avoid this whole mess.
In order to do this I need to be able to determine if there was a visual selection when the picker got invoked and if so the text that was selected. I’m thinking that I could do this by using the [range]
argument to :[range]lua <expr>
. When typing a command when we start out in visual mode we get the prepopulated :'<,'>lua <expr>
so we could write our code so that it assumes that if we have a range specified we should use that range to determine what name to search for, and if there is no current range specified we could assume that the name to search for should be the current word.
Unfortunately as far as I can tell the information in [range]
isn’t exposed to the lua code at all. Have I overlooked something, or would it take a feature request to neovim to be able to inspect that information.