paste: reset 'paste' option immediately #10974

- Workaround #10966: 'paste' option is not always reset.
- In any case there's not much reason to wait until phase=3, because
  pasting in cmdline-mode skips lines after the first line (thus the
  `:set paste .. :set nopaste` dance happens only ~once).
This commit is contained in:
Justin M. Keyes 2019-09-08 14:58:47 -07:00 committed by GitHub
parent 77a93957d3
commit d91f4cd7d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -188,8 +188,9 @@ paste = (function()
if mode == 'c' and not got_line1 then -- cmdline-mode: paste only 1 line. if mode == 'c' and not got_line1 then -- cmdline-mode: paste only 1 line.
got_line1 = (#lines > 1) got_line1 = (#lines > 1)
vim.api.nvim_set_option('paste', true) -- For nvim_input(). vim.api.nvim_set_option('paste', true) -- For nvim_input().
local line1, _ = string.gsub(lines[1], '[\r\n\012\027]', ' ') local line1, _ = string.gsub(lines[1], '[\r\n\012\027]', ' ') -- Scrub.
vim.api.nvim_input(line1) -- Scrub "\r". vim.api.nvim_input(line1)
vim.api.nvim_set_option('paste', false)
elseif mode == 'i' or mode == 'R' then elseif mode == 'i' or mode == 'R' then
vim.api.nvim_put(lines, 'c', false, true) vim.api.nvim_put(lines, 'c', false, true)
else else
@ -206,7 +207,6 @@ paste = (function()
if phase == -1 or phase == 3 then if phase == -1 or phase == 3 then
vim.api.nvim_command('redraw') vim.api.nvim_command('redraw')
vim.api.nvim_command('echo ""') vim.api.nvim_command('echo ""')
vim.api.nvim_set_option('paste', false)
end end
return true -- Paste will not continue if not returning `true`. return true -- Paste will not continue if not returning `true`.
end end

View File

@ -505,7 +505,7 @@ describe('TUI', function()
| |
{4:~ }| {4:~ }|
{5: }| {5: }|
{8:paste: Error executing lua: vim.lua:196: Vim:E21: }| {8:paste: Error executing lua: vim.lua:197: Vim:E21: }|
{8:Cannot make changes, 'modifiable' is off} | {8:Cannot make changes, 'modifiable' is off} |
{10:Press ENTER or type command to continue}{1: } | {10:Press ENTER or type command to continue}{1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |