diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-09-01 19:12:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-01 19:12:13 -0700 |
commit | b10d703213da5699a176c7791a51a322f248dbd2 (patch) | |
tree | 72a8132da5e844284b9bc9e2947e9518e01f7395 | |
parent | 938be1e0ab1c3772f329f39225e651deb1cd6aca (diff) | |
parent | 8560bafc6cf7cfd301c1389a9e2562aeec592294 (diff) | |
download | rneovim-b10d703213da5699a176c7791a51a322f248dbd2.tar.gz rneovim-b10d703213da5699a176c7791a51a322f248dbd2.tar.bz2 rneovim-b10d703213da5699a176c7791a51a322f248dbd2.zip |
Merge #10896 'paste: one undo-block'
-rw-r--r-- | runtime/doc/api.txt | 7 | ||||
-rw-r--r-- | src/nvim/api/vim.c | 6 | ||||
-rw-r--r-- | src/nvim/lua/vim.lua | 12 | ||||
-rw-r--r-- | test/functional/api/vim_spec.lua | 29 | ||||
-rw-r--r-- | test/functional/terminal/tui_spec.lua | 2 |
5 files changed, 42 insertions, 14 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index 710ab0cf33..1af327e572 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -829,11 +829,12 @@ nvim_put({lines}, {type}, {after}, {follow}) *nvim_put()* Parameters: ~ {lines} |readfile()|-style list of lines. |channel-lines| - {type} Edit behavior: - • "b" |blockwise-visual| mode + {type} Edit behavior: any |getregtype()| result, or: + • "b" |blockwise-visual| mode (may include + width, e.g. "b3") • "c" |characterwise| mode • "l" |linewise| mode - • "" guess by contents + • "" guess by contents, see |setreg()| {after} Insert after cursor (like |p|), or before (like |P|). {follow} Place cursor at end of inserted text. diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 21cba96ba7..2034fea770 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1293,11 +1293,11 @@ theend: /// Compare |:put| and |p| which are always linewise. /// /// @param lines |readfile()|-style list of lines. |channel-lines| -/// @param type Edit behavior: -/// - "b" |blockwise-visual| mode +/// @param type Edit behavior: any |getregtype()| result, or: +/// - "b" |blockwise-visual| mode (may include width, e.g. "b3") /// - "c" |characterwise| mode /// - "l" |linewise| mode -/// - "" guess by contents +/// - "" guess by contents, see |setreg()| /// @param after Insert after cursor (like |p|), or before (like |P|). /// @param follow Place cursor at end of inserted text. /// @param[out] err Error details, if any diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua index fd34b8545d..99299c6073 100644 --- a/src/nvim/lua/vim.lua +++ b/src/nvim/lua/vim.lua @@ -175,13 +175,15 @@ end --@returns false if client should cancel the paste. local function paste(lines, phase) end -- luacheck: no unused paste = (function() - local tdots, tredraw, tick, got_line1 = 0, 0, 0, false + local tdots, tick, got_line1 = 0, 0, false return function(lines, phase) local call = vim.api.nvim_call_function local now = vim.loop.now() local mode = call('mode', {}):sub(1,1) if phase < 2 then -- Reset flags. - tdots, tredraw, tick, got_line1 = now, now, 0, false + tdots, tick, got_line1 = now, 0, false + elseif mode ~= 'c' then + vim.api.nvim_command('undojoin') end if mode == 'c' and not got_line1 then -- cmdline-mode: paste only 1 line. got_line1 = (#lines > 1) @@ -193,11 +195,6 @@ paste = (function() else vim.api.nvim_put(lines, 'c', true, true) end - if (now - tredraw >= 1000) or phase == -1 or phase > 2 then - tredraw = now - vim.api.nvim_command('redraw') - vim.api.nvim_command('redrawstatus') - end if phase ~= -1 and (now - tdots >= 100) then local dots = ('.'):rep(tick % 4) tdots = now @@ -207,6 +204,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_set_option('paste', false) end diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 02e83c4d58..851feddb54 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -373,6 +373,35 @@ describe('API', function() expect_err('Invalid phase: 4', request, 'nvim_paste', 'foo', true, 4) end) + it('stream: multiple chunks form one undo-block', function() + nvim('paste', '1/chunk 1 (start)\n', true, 1) + nvim('paste', '1/chunk 2 (end)\n', true, 3) + local expected1 = [[ + 1/chunk 1 (start) + 1/chunk 2 (end) + ]] + expect(expected1) + nvim('paste', '2/chunk 1 (start)\n', true, 1) + nvim('paste', '2/chunk 2\n', true, 2) + expect([[ + 1/chunk 1 (start) + 1/chunk 2 (end) + 2/chunk 1 (start) + 2/chunk 2 + ]]) + nvim('paste', '2/chunk 3\n', true, 2) + nvim('paste', '2/chunk 4 (end)\n', true, 3) + expect([[ + 1/chunk 1 (start) + 1/chunk 2 (end) + 2/chunk 1 (start) + 2/chunk 2 + 2/chunk 3 + 2/chunk 4 (end) + ]]) + feed('u') -- Undo. + expect(expected1) + end) it('non-streaming', function() -- With final "\n". nvim('paste', 'line 1\nline 2\nline 3\n', true, -1) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index cbf113d062..312e060a70 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -505,7 +505,7 @@ describe('TUI', function() | {4:~ }| {5: }| - {8:paste: Error executing lua: vim.lua:194: Vim:E21: }| + {8:paste: Error executing lua: vim.lua:196: Vim:E21: }| {8:Cannot make changes, 'modifiable' is off} | {10:Press ENTER or type command to continue}{1: } | {3:-- TERMINAL --} | |