lightspeed.nvim icon indicating copy to clipboard operation
lightspeed.nvim copied to clipboard

Fix error when special_keys doesn't contain both match groups

Open vanaigr opened this issue 2 years ago • 0 comments

When setting up lightspeed, if special_keys does not contain both prev_match_group and next_match_group, then 'sneaking' when there is more than 18 matches errors when typing the third character errors with:

E5108: Error executing lua: ...ite\pack\packer\start\lightspeed.nvim/lua/lightspeed.lua:2246: Expected lua string
stack traceback:
	[C]: in function '__index'
	...ite\pack\packer\start\lightspeed.nvim/lua/lightspeed.lua:2246: in function '_438_'
	...ite\pack\packer\start\lightspeed.nvim/lua/lightspeed.lua:2248: in function 'get_last_input'
	...ite\pack\packer\start\lightspeed.nvim/lua/lightspeed.lua:2594: in function 'go'
	...a\site\pack\packer\start\lightspeed.nvim\plugin\init.lua:3: in function <...a\site\pack\packer\start\lightspeed.nvim\plugin\init.lua:3>

When the third character is being processed, logic on line 2246 of the generated script checks if the input is equal to the keycodes of one of the special keys, and the function that maps the special_keys keys to keycodes doesn't check if the property doesn't exist and eventually calls vim.api.nvim_replace_termcodes with nil, which causes the error.

To check that you can run neovim with:

vim.cmd 'packadd packer.nvim'

require('packer').startup(function(use)  
    use{ 'ggandor/lightspeed.nvim' }
end)

require('lightspeed').setup{ special_keys = {} }

and type

19iab<cr><esc>ggO<esc>sab[[the next character causes the error]]

This pull requests adds the nil check and makes the function return nil in case the property doesn't exist.

vanaigr avatar Oct 25 '23 00:10 vanaigr