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

`<Esc>` during text input produces `null` #150

Closed xiaochuanyu closed 1 year ago

xiaochuanyu commented 2 years ago

Checklist

To reproduce

  1. Start with text "a" with cursor inside quotes.
  2. Do csqt<Esc> which cancels prompt.

Expected behavior

Text remains the same as "a".

Actual behavior

Text changed to <null>a</null>.

Additional context

Same problem with ysiwt<Esc>.

kylechui commented 2 years ago

What version of Neovim are you using? If you're using v0.7.2, this is an issue with vim.fn.input that was resolved in this upstream issue (requires nightly).

xiaochuanyu commented 2 years ago

Yea I'm using v0.7.2. Unfortunately I can't update to nightly for my work laptop :( I've instead made a hacky workaround which seems to work so far.

M lua/nvim-surround/config.lua
@@ -276,8 +276,8 @@ M.default_opts = {
 ---@return string? @The user input.
 M.get_input = function(prompt)
     -- Since `vim.fn.input()` does not handle keyboard interrupts, we use a protected call to detect <C-c>
-    local ok, result = pcall(vim.fn.input, { prompt = prompt, cancelreturn = vim.NIL })
-    if ok and result ~= vim.NIL then
+    local ok, result = pcall(vim.fn.input, { prompt = prompt, cancelreturn = "\a" })
+    if ok and result ~= "\a" then
         return result
     end
 end
kylechui commented 2 years ago

Yeah sorry about that one. I was initially thinking of doing a workaround by using some arbitrarily long hash string to denote cancelreturn, but then figured that I would just "do it right" once the patch was merged upstream. I'll leave this issue open and probably require v0.8 when the stable version drops, with limited support for 0.7+.

TheOmegaCarrot commented 1 year ago

It seems that basically the same thing happens with function names.

With cursor at :`bar Input is:ysiwf Result is:null(bar)`

xiaochuanyu commented 1 year ago

This is now fixed in nvim 0.8.

kylechui commented 1 year ago

Yep, I'll close this issue once I update the README to require Neovim 0.8+