nvim-surround icon indicating copy to clipboard operation
nvim-surround copied to clipboard

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

Open xiaochuanyu opened this issue 1 year ago • 4 comments

Checklist

  • [X] Have you updated the plugin to the latest version on main branch?
  • [X] Have you checked the Breaking Changes issue?
  • [X] Have you read through :h nvim-surround to see if there might be any relevant information there?

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>.

xiaochuanyu avatar Sep 04 '22 16:09 xiaochuanyu

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).

kylechui avatar Sep 04 '22 20:09 kylechui

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

xiaochuanyu avatar Sep 05 '22 20:09 xiaochuanyu

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+.

kylechui avatar Sep 05 '22 21:09 kylechui

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

With cursor at *:b*ar Input is: ysiwf<esc> Result is: null(bar)

TheOmegaCarrot avatar Sep 12 '22 12:09 TheOmegaCarrot

This is now fixed in nvim 0.8.

xiaochuanyu avatar Oct 06 '22 18:10 xiaochuanyu

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

kylechui avatar Oct 06 '22 19:10 kylechui