fix(paste): feed keys as typed in cmdline mode (#20959)

This commit is contained in:
zeertzjq 2022-11-06 12:43:05 +08:00 committed by GitHub
parent eb55eba7e5
commit 850d7146fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -167,7 +167,8 @@ do
local line1 = lines[1]:gsub('(%c)', '\022%1')
-- nvim_input() is affected by mappings,
-- so use nvim_feedkeys() with "n" flag to ignore mappings.
vim.api.nvim_feedkeys(line1, 'n', true)
-- "t" flag is also needed so the pasted text is saved in cmdline history.
vim.api.nvim_feedkeys(line1, 'nt', true)
end
return true
end

View File

@ -1108,6 +1108,14 @@ describe('API', function()
nvim('paste', 'a', true, -1)
eq('a', funcs.getcmdline())
end)
it('pasted text is saved in cmdline history when <CR> comes from mapping #20957', function()
command('cnoremap <CR> <CR>')
feed(':')
nvim('paste', 'echo', true, -1)
eq('', funcs.histget(':'))
feed('<CR>')
eq('echo', funcs.histget(':'))
end)
it('pasting with empty last chunk in Cmdline mode', function()
local screen = Screen.new(20, 4)
screen:attach()