From 0dea44f93ce925baedf0f2d39d799f36671986b6 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 8 Sep 2019 13:48:46 -0700 Subject: [PATCH 1/3] paste/cmdline: discard all chunks after first line Problem: If multiple paste "chunks" are streamed, chunks after the first line are pasted into the buffer. Solution: Check for cmdline-mode for all chunks in a paste-stream. --- src/nvim/lua/vim.lua | 6 ++---- test/functional/terminal/tui_spec.lua | 7 +++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua index e76dd9d062..7d5dc0bffc 100644 --- a/src/nvim/lua/vim.lua +++ b/src/nvim/lua/vim.lua @@ -191,10 +191,8 @@ paste = (function() local line1, _ = string.gsub(lines[1], '[\r\n\012\027]', ' ') -- Scrub. vim.api.nvim_input(line1) vim.api.nvim_set_option('paste', false) - elseif mode == 'i' or mode == 'R' then - vim.api.nvim_put(lines, 'c', false, true) - else - vim.api.nvim_put(lines, 'c', true, true) + elseif mode ~= 'c' then + vim.api.nvim_put(lines, 'c', (mode ~= 'i' and mode ~= 'R'), true) end if phase ~= -1 and (now - tdots >= 100) then local dots = ('.'):rep(tick % 4) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index e0d29d27ff..8fa7442087 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -363,7 +363,10 @@ describe('TUI', function() feed_data('\027[D') -- to place cursor between quotes. wait_for_mode('c') -- "bracketed paste" - feed_data('\027[200~line 1\nline 2\n\027[201~') + feed_data('\027[200~line 1\nline 2\n') + wait_for_mode('c') + feed_data('line 3\nline 4\n\027[201~') + wait_for_mode('c') screen:expect{grid=[[ foo | | @@ -505,7 +508,7 @@ describe('TUI', function() | {4:~ }| {5: }| - {8:paste: Error executing lua: vim.lua:197: Vim:E21: }| + {8:paste: Error executing lua: vim.lua:195: Vim:E21: }| {8:Cannot make changes, 'modifiable' is off} | {10:Press ENTER or type command to continue}{1: } | {3:-- TERMINAL --} | From acd2729573171995e8a66be7e09ba4e2fc5d9c69 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 8 Sep 2019 15:37:24 -0700 Subject: [PATCH 2/3] paste: do not clobber msg area for small pastes --- src/nvim/lua/vim.lua | 3 +-- test/functional/terminal/tui_spec.lua | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua index 7d5dc0bffc..cc10118906 100644 --- a/src/nvim/lua/vim.lua +++ b/src/nvim/lua/vim.lua @@ -203,8 +203,7 @@ paste = (function() vim.api.nvim_command(('echo "%s"'):format(dots)) end if phase == -1 or phase == 3 then - vim.api.nvim_command('redraw') - vim.api.nvim_command('echo ""') + vim.api.nvim_command('redraw'..(tick > 1 and '|echo ""' or '')) end return true -- Paste will not continue if not returning `true`. end diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 8fa7442087..01e73a2378 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -319,7 +319,7 @@ describe('TUI', function() {1:x} | {4:~ }| {5:[No Name] [+] 3,1 All}| - | + :set ruler | {3:-- TERMINAL --} | ]] local expected_attr = { @@ -353,7 +353,11 @@ describe('TUI', function() expect_child_buf_lines({''}) -- CRLF input feed_data('\027[200~'..table.concat(expected_lf,'\r\n')..'\027[201~') - screen:expect{grid=expected_grid1, attr_ids=expected_attr} + screen:expect{ + grid=expected_grid1:gsub( + ':set ruler *', + '3 fewer lines; before #1 0 seconds ago '), + attr_ids=expected_attr} expect_child_buf_lines(expected_crlf) end) From a9e2bae0eb6942829dbedfc9c422060da020d8e4 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 8 Sep 2019 16:39:06 -0700 Subject: [PATCH 3/3] paste: insert before cursor always Inserting "after" the cursor in Normal-mode, for big paste-streams, is not reliable: sometimes the text "after" the cursor ends up in the middle of the pasted text. Maybe the cursor position is not updated? To avoid weird behavior, always paste "before". Maybe nvim_put() or vim.paste() can be fixed more properly later. --- runtime/doc/provider.txt | 2 +- src/nvim/lua/vim.lua | 2 +- test/functional/terminal/tui_spec.lua | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/doc/provider.txt b/runtime/doc/provider.txt index 0083bb63a4..6fa3377a14 100644 --- a/runtime/doc/provider.txt +++ b/runtime/doc/provider.txt @@ -239,7 +239,7 @@ GUIs can paste by calling |nvim_paste()|. PASTE BEHAVIOR ~ -Paste inserts text after the cursor. Lines break at , , and . +Paste inserts text before the cursor. Lines break at , and . When pasting a huge amount of text, screen-updates are throttled and the message area shows a "..." pulse. diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua index cc10118906..010c3b98ee 100644 --- a/src/nvim/lua/vim.lua +++ b/src/nvim/lua/vim.lua @@ -192,7 +192,7 @@ paste = (function() vim.api.nvim_input(line1) vim.api.nvim_set_option('paste', false) elseif mode ~= 'c' then - vim.api.nvim_put(lines, 'c', (mode ~= 'i' and mode ~= 'R'), true) + vim.api.nvim_put(lines, 'c', false, true) end if phase ~= -1 and (now - tdots >= 100) then local dots = ('.'):rep(tick % 4) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 01e73a2378..2bd114b505 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -485,9 +485,9 @@ describe('TUI', function() feed_data('\n') -- screen:expect{grid=[[ foo | - typed input...line A | + typed input..line A | line B | - {1: } | + {1:.} | {5:[No Name] [+] }| | {3:-- TERMINAL --} |