kylechui / nvim-surround

Add/change/delete surrounding delimiter pairs with ease. Written with :heart: in Lua.
MIT License
3.09k stars 61 forks source link

Typing `ds` in command preview callback moves cursor in commandline #95

Closed smjonas closed 2 years ago

smjonas commented 2 years ago

Checklist

Describe the bug Now that #84 has been solved, I found another issue ^^

To Reproduce Create the following user command, then type :Test ds:

vim.api.nvim_create_user_command("Test", "", { preview =  function(opts, _, _)
  vim.cmd("norm " .. opts.args)
  return 2
end})

Expected behavior The cursor should not move in the command line.

nvim-surround_cmdline_expected

Actual behavior The cursor moves to the very left column in the command line:

nvim-surround_cmdline

Additional context This causes lots of flickers when typing dssssssss. This issue does not occur with a plugin like vim-sandwich. So maybe the cursor is moved too early. However, I didn't look at the way cursor positions are handled in the code, so it would be nice if you could clarify a few things here.

This issue does not occur with ys btw.

kylechui commented 2 years ago

Could this perhaps be a 0.8 issue? It seems that preview is undefined for v0.7.2

smjonas commented 2 years ago

Yes, command preview is only available on Neovim nightly (0.8). Though it has been available for about 2 months now.

Maybe this is even a Neovim issue but to report this upstream, I would first need to create minimal reproduction steps that do not directly involve this plugin. Maybe you have a hunch where it might be caused.

kylechui commented 2 years ago

I'm still using v0.7.2, so I don't actually know what preview does; I'll look into it and give my 2 cents in a bit.

Edit: Ah, incremental command preview.

Edit 2: Bug has been reproduced.

kylechui commented 2 years ago

@smjonas I reckon it has to do with how the built-in vim.fn.getchar() (used in utils.get_char()) function works? Whenever it receives input, the cursor "moves" to the beginning of the command line, even though typing more characters after will "move" the cursor back to the end of the command line (it visually moves, but practically it stays at the end of the command line, if that makes sense).

smjonas commented 2 years ago

Thank you, seems like we'll have to wait until https://github.com/neovim/neovim/pull/19035 is merged.

kylechui commented 2 years ago

Glad it's already been found/reported! I'll be closing this as it seems the issue is upstream.