mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
paste: one undo-block per stream
- All "chunks" in a paste-stream should form a single undo-block. Side effect of7a85792884
was to create an undo-block for each chunk. - Also: remove old :redraw force logic, irrelevant after7a85792884
.
This commit is contained in:
parent
801fe799ff
commit
976c6667e1
@ -829,11 +829,12 @@ nvim_put({lines}, {type}, {after}, {follow}) *nvim_put()*
|
|||||||
Parameters: ~
|
Parameters: ~
|
||||||
{lines} |readfile()|-style list of lines.
|
{lines} |readfile()|-style list of lines.
|
||||||
|channel-lines|
|
|channel-lines|
|
||||||
{type} Edit behavior:
|
{type} Edit behavior: any |getregtype()| result, or:
|
||||||
• "b" |blockwise-visual| mode
|
• "b" |blockwise-visual| mode (may include
|
||||||
|
width, e.g. "b3")
|
||||||
• "c" |characterwise| mode
|
• "c" |characterwise| mode
|
||||||
• "l" |linewise| mode
|
• "l" |linewise| mode
|
||||||
• "" guess by contents
|
• "" guess by contents, see |setreg()|
|
||||||
{after} Insert after cursor (like |p|), or before (like
|
{after} Insert after cursor (like |p|), or before (like
|
||||||
|P|).
|
|P|).
|
||||||
{follow} Place cursor at end of inserted text.
|
{follow} Place cursor at end of inserted text.
|
||||||
|
@ -1293,11 +1293,11 @@ theend:
|
|||||||
/// Compare |:put| and |p| which are always linewise.
|
/// Compare |:put| and |p| which are always linewise.
|
||||||
///
|
///
|
||||||
/// @param lines |readfile()|-style list of lines. |channel-lines|
|
/// @param lines |readfile()|-style list of lines. |channel-lines|
|
||||||
/// @param type Edit behavior:
|
/// @param type Edit behavior: any |getregtype()| result, or:
|
||||||
/// - "b" |blockwise-visual| mode
|
/// - "b" |blockwise-visual| mode (may include width, e.g. "b3")
|
||||||
/// - "c" |characterwise| mode
|
/// - "c" |characterwise| mode
|
||||||
/// - "l" |linewise| mode
|
/// - "l" |linewise| mode
|
||||||
/// - "" guess by contents
|
/// - "" guess by contents, see |setreg()|
|
||||||
/// @param after Insert after cursor (like |p|), or before (like |P|).
|
/// @param after Insert after cursor (like |p|), or before (like |P|).
|
||||||
/// @param follow Place cursor at end of inserted text.
|
/// @param follow Place cursor at end of inserted text.
|
||||||
/// @param[out] err Error details, if any
|
/// @param[out] err Error details, if any
|
||||||
|
@ -175,13 +175,15 @@ end
|
|||||||
--@returns false if client should cancel the paste.
|
--@returns false if client should cancel the paste.
|
||||||
local function paste(lines, phase) end -- luacheck: no unused
|
local function paste(lines, phase) end -- luacheck: no unused
|
||||||
paste = (function()
|
paste = (function()
|
||||||
local tdots, tredraw, tick, got_line1 = 0, 0, 0, false
|
local tdots, tick, got_line1 = 0, 0, false
|
||||||
return function(lines, phase)
|
return function(lines, phase)
|
||||||
local call = vim.api.nvim_call_function
|
local call = vim.api.nvim_call_function
|
||||||
local now = vim.loop.now()
|
local now = vim.loop.now()
|
||||||
local mode = call('mode', {}):sub(1,1)
|
local mode = call('mode', {}):sub(1,1)
|
||||||
if phase < 2 then -- Reset flags.
|
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
|
end
|
||||||
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)
|
||||||
@ -193,11 +195,6 @@ paste = (function()
|
|||||||
else
|
else
|
||||||
vim.api.nvim_put(lines, 'c', true, true)
|
vim.api.nvim_put(lines, 'c', true, true)
|
||||||
end
|
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
|
if phase ~= -1 and (now - tdots >= 100) then
|
||||||
local dots = ('.'):rep(tick % 4)
|
local dots = ('.'):rep(tick % 4)
|
||||||
tdots = now
|
tdots = now
|
||||||
|
@ -373,6 +373,35 @@ describe('API', function()
|
|||||||
expect_err('Invalid phase: 4', request,
|
expect_err('Invalid phase: 4', request,
|
||||||
'nvim_paste', 'foo', true, 4)
|
'nvim_paste', 'foo', true, 4)
|
||||||
end)
|
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()
|
it('non-streaming', function()
|
||||||
-- With final "\n".
|
-- With final "\n".
|
||||||
nvim('paste', 'line 1\nline 2\nline 3\n', true, -1)
|
nvim('paste', 'line 1\nline 2\nline 3\n', true, -1)
|
||||||
|
@ -505,7 +505,7 @@ describe('TUI', function()
|
|||||||
|
|
|
|
||||||
{4:~ }|
|
{4:~ }|
|
||||||
{5: }|
|
{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} |
|
{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 --} |
|
||||||
|
Loading…
Reference in New Issue
Block a user