Skip to content

Commit 2cd1ff7

Browse files
committed
paste: Select-mode, Visual-mode neovim#11360
fix neovim#11344
1 parent 941dc1b commit 2cd1ff7

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

src/nvim/api/vim.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ Boolean nvim_paste(String data, Boolean crlf, Integer phase, Error *err)
12661266
draining = true;
12671267
goto theend;
12681268
}
1269-
if (!(State & CMDLINE) && !(State & INSERT) && (phase == -1 || phase == 1)) {
1269+
if (!(State & (CMDLINE | INSERT)) && (phase == -1 || phase == 1)) {
12701270
ResetRedobuff();
12711271
AppendCharToRedobuff('a'); // Dot-repeat.
12721272
}
@@ -1284,7 +1284,7 @@ Boolean nvim_paste(String data, Boolean crlf, Integer phase, Error *err)
12841284
}
12851285
}
12861286
}
1287-
if (!(State & CMDLINE) && !(State & INSERT) && (phase == -1 || phase == 3)) {
1287+
if (!(State & (CMDLINE | INSERT)) && (phase == -1 || phase == 3)) {
12881288
AppendCharToRedobuff(ESC); // Dot-repeat.
12891289
}
12901290
theend:

src/nvim/lua/vim.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,11 @@ paste = (function()
192192
local line1 = lines[1]:gsub('<', '<lt>'):gsub('[\r\n\012\027]', ' ') -- Scrub.
193193
vim.api.nvim_input(line1)
194194
vim.api.nvim_set_option('paste', false)
195-
elseif mode ~= 'c' then -- Else: discard remaining cmdline-mode chunks.
196-
if phase < 2 and mode ~= 'i' and mode ~= 'R' and mode ~= 't' then
195+
elseif mode ~= 'c' then
196+
if phase < 2 and mode:find('^[vV\22sS\19]') then
197+
vim.api.nvim_command([[exe "normal! \<Del>"]])
198+
vim.api.nvim_put(lines, 'c', false, true)
199+
elseif phase < 2 and not mode:find('^[iRt]') then
197200
vim.api.nvim_put(lines, 'c', true, true)
198201
-- XXX: Normal-mode: workaround bad cursor-placement after first chunk.
199202
vim.api.nvim_command('normal! a')

test/functional/terminal/tui_spec.lua

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,49 @@ describe('TUI', function()
306306
expect_child_buf_lines({''})
307307
end)
308308

309+
it('paste: select-mode', function()
310+
feed_data('ithis is line 1\nthis is line 2\nline 3 is here\n\027')
311+
wait_for_mode('n')
312+
screen:expect{grid=[[
313+
this is line 1 |
314+
this is line 2 |
315+
line 3 is here |
316+
{1: } |
317+
{5:[No Name] [+] }|
318+
|
319+
{3:-- TERMINAL --} |
320+
]]}
321+
-- Select-mode. Use <C-n> to move down.
322+
feed_data('gg04lgh\14\14')
323+
wait_for_mode('s')
324+
feed_data('\027[200~')
325+
feed_data('just paste it™')
326+
feed_data('\027[201~')
327+
screen:expect{grid=[[
328+
thisjust paste it™{1:3} is here |
329+
|
330+
{4:~ }|
331+
{4:~ }|
332+
{5:[No Name] [+] }|
333+
|
334+
{3:-- TERMINAL --} |
335+
]]}
336+
-- Undo.
337+
feed_data('u')
338+
expect_child_buf_lines{
339+
'this is line 1',
340+
'this is line 2',
341+
'line 3 is here',
342+
'',
343+
}
344+
-- Redo.
345+
feed_data('\18') -- <C-r>
346+
expect_child_buf_lines{
347+
'thisjust paste it™3 is here',
348+
'',
349+
}
350+
end)
351+
309352
it('paste: terminal mode', function()
310353
feed_data(':set statusline=^^^^^^^\n')
311354
feed_data(':terminal '..nvim_dir..'/tty-test\n')
@@ -539,7 +582,7 @@ describe('TUI', function()
539582
|
540583
{4:~ }|
541584
{5: }|
542-
{8:paste: Error executing lua: vim.lua:197: Vim:E21: }|
585+
{8:paste: Error executing lua: vim.lua:200: Vim:E21: }|
543586
{8:Cannot make changes, 'modifiable' is off} |
544587
{10:Press ENTER or type command to continue}{1: } |
545588
{3:-- TERMINAL --} |

0 commit comments

Comments
 (0)