paste: use nvim_put()

This commit is contained in:
Justin M. Keyes 2019-08-20 01:21:27 +02:00
parent e1177be363
commit 5a2894d677
5 changed files with 82 additions and 296 deletions

View File

@ -94,26 +94,14 @@ local function _os_proc_children(ppid)
end end
-- Default paste function. -- Default paste function.
local function _paste(data) local function _paste(lines)
-- local eof = (lines == {''})
local call = vim.api.nvim_call_function local call = vim.api.nvim_call_function
local mode = call('mode', {}) local mode = call('mode', {})
if mode == 't' then
call('chansend',
{vim.api.nvim_buf_get_option(0, 'channel'), data})
return true
end
-- local eof = (data == {''})
local curline = call('line', {'.'}) local curline = call('line', {'.'})
vim.api.nvim_buf_set_lines( -- vim.api.nvim_set_option('paste', true)
0, vim.api.nvim_put(lines, 'c', false)
curline, -- vim.api.nvim_set_option('paste', false)
curline,
false,
data)
call(
'cursor',
{curline + #data, 9999999})
-- TODO: do not redraw (slow!) until paste is finished. -- TODO: do not redraw (slow!) until paste is finished.
-- if eof then -- if eof then
vim.api.nvim_command('redraw') vim.api.nvim_command('redraw')

View File

@ -100,7 +100,6 @@ static void tinput_done_event(void **argv)
input_done(); input_done();
} }
// TODO: send [''] to indicate EOF.
static Array string_to_array(const String input) static Array string_to_array(const String input)
{ {
Array ret = ARRAY_DICT_INIT; Array ret = ARRAY_DICT_INIT;

View File

@ -1,204 +0,0 @@
-- TUI tests for "bracketed paste" mode.
-- http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Bracketed-Paste-Mode
local helpers = require('test.functional.helpers')
local child_tui = require('test.functional.tui.child_session')
local Screen = require('test.functional.ui.screen')
local execute = helpers.execute
local nvim_dir = helpers.nvim_dir
local eval = helpers.eval
local eq = helpers.eq
local feed_tui = child_tui.feed_data
describe('tui paste', function()
local screen
before_each(function()
helpers.clear()
screen = child_tui.screen_setup(0, '["'..helpers.nvim_prog..
'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile"]')
-- Pasting can be really slow in the TUI, especially in ASAN.
screen.timeout = 5000
screen:expect([[
{1: } |
~ |
~ |
~ |
[No Name] |
|
-- TERMINAL -- |
]])
end)
after_each(function()
screen:detach()
end)
local function setup_harness()
-- Delete the default PastePre/PastePost autocmds.
feed_tui(":autocmd! PastePre,PastePost\n")
-- Set up test handlers.
feed_tui(":autocmd PastePre * "..
"call feedkeys('iPastePre mode:'.mode(),'n')\n")
feed_tui(":autocmd PastePost * "..
"call feedkeys('PastePost mode:'.mode(),'n')\n")
end
it('handles long bursts of input', function()
execute('set ruler')
local t = {}
for i = 1, 3000 do
t[i] = 'item ' .. tostring(i)
end
feed_tui('i\027[200~')
feed_tui(table.concat(t, '\n'))
feed_tui('\027[201~')
screen:expect([[
item 2997 |
item 2998 |
item 2999 |
item 3000{1: } |
[No Name] [+] 3000,10 Bot|
-- INSERT -- |
-- TERMINAL -- |
]])
end)
it('raises PastePre, PastePost in normal-mode', function()
setup_harness()
-- Send the "start paste" sequence.
feed_tui("\027[200~")
feed_tui("\npasted from terminal (1)\npasted from terminal (2)\n")
-- Send the "stop paste" sequence.
feed_tui("\027[201~")
screen:expect([[
PastePre mode:n |
pasted from terminal (1) |
pasted from terminal (2) |
PastePost mode:i{1: } |
[No Name] [+] |
-- INSERT -- |
-- TERMINAL -- |
]])
end)
it('forwards spurious "start paste" sequence', function()
setup_harness()
-- If multiple "start paste" sequences are sent without a corresponding
-- "stop paste" sequence, only the first occurrence should be consumed.
-- Send the "start paste" sequence.
feed_tui("\027[200~")
feed_tui("\npasted from terminal (1)\n")
-- Send spurious "start paste" sequence.
feed_tui("\027[200~")
feed_tui("\n")
-- Send the "stop paste" sequence.
feed_tui("\027[201~")
screen:expect([[
PastePre mode:n |
pasted from terminal (1) |
{1:^[}200~ |
PastePost mode:i{2: } |
[No Name] [+] |
-- INSERT -- |
-- TERMINAL -- |
]], {
[1] = {foreground = 4},
[2] = {reverse = true},
})
end)
it('ignores spurious "stop paste" sequence', function()
setup_harness()
-- If "stop paste" sequence is received without a preceding "start paste"
-- sequence, it should be ignored.
feed_tui("i")
-- Send "stop paste" sequence.
feed_tui("\027[201~")
screen:expect([[
{1: } |
~ |
~ |
~ |
[No Name] |
-- INSERT -- |
-- TERMINAL -- |
]])
end)
it('raises PastePre, PastePost in command-mode', function()
-- The default PastePre/PastePost handlers set the 'paste' option. To test,
-- we define a command-mode map, then assert that the mapping was ignored
-- during paste.
feed_tui(":cnoremap st XXX\n")
feed_tui(":not pasted")
-- Paste did not start, so the mapping _should_ apply.
screen:expect([[
|
~ |
~ |
~ |
[No Name] |
:not paXXXed{1: } |
-- TERMINAL -- |
]])
feed_tui("\003") -- CTRL-C
feed_tui(":")
feed_tui("\027[200~") -- Send the "start paste" sequence.
feed_tui("pasted")
-- Paste started, so the mapping should _not_ apply.
screen:expect([[
|
~ |
~ |
~ |
[No Name] |
:pasted{1: } |
-- TERMINAL -- |
]])
feed_tui("\003") -- CTRL-C
feed_tui(":")
feed_tui("\027[201~") -- Send the "stop paste" sequence.
feed_tui("not pasted")
-- Paste stopped, so the mapping _should_ apply.
screen:expect([[
|
~ |
~ |
~ |
[No Name] |
:not paXXXed{1: } |
-- TERMINAL -- |
]])
end)
-- TODO
it('sets undo-point after consecutive pastes', function()
end)
-- TODO
it('handles missing "stop paste" sequence', function()
end)
-- TODO: error when pasting into 'nomodifiable' buffer:
-- [error @ do_put:2656] 17043 - Failed to save undo information
it("handles 'nomodifiable' buffer gracefully", function()
end)
end)

View File

@ -1,5 +1,9 @@
-- TUI acceptance tests. -- TUI acceptance tests.
-- Uses :terminal as a way to send keys and assert screen state. -- Uses :terminal as a way to send keys and assert screen state.
--
-- "bracketed paste" terminal feature:
-- http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Bracketed-Paste-Mode
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local uname = helpers.uname local uname = helpers.uname
local thelpers = require('test.functional.terminal.helpers') local thelpers = require('test.functional.terminal.helpers')
@ -159,10 +163,10 @@ describe('TUI', function()
]]) ]])
feed_data('pasted from terminal') feed_data('pasted from terminal')
screen:expect([[ screen:expect([[
|
pasted from terminal{1: } | pasted from terminal{1: } |
{4:~ }| {4:~ }|
{4:~ }| {4:~ }|
{4:~ }|
{5:[No Name] [+] }| {5:[No Name] [+] }|
{3:-- INSERT --} | {3:-- INSERT --} |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
@ -170,10 +174,10 @@ describe('TUI', function()
feed_data('\027[201~') -- End paste. feed_data('\027[201~') -- End paste.
feed_data('\027\000') -- ESC: go to Normal mode. feed_data('\027\000') -- ESC: go to Normal mode.
screen:expect([[ screen:expect([[
|
pasted from termina{1:l} | pasted from termina{1:l} |
{4:~ }| {4:~ }|
{4:~ }| {4:~ }|
{4:~ }|
{5:[No Name] [+] }| {5:[No Name] [+] }|
| |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
@ -183,10 +187,10 @@ describe('TUI', function()
it('pasting a specific amount of text #10311', function() it('pasting a specific amount of text #10311', function()
feed_data('i\027[200~'..string.rep('z', 64)..'\027[201~') feed_data('i\027[200~'..string.rep('z', 64)..'\027[201~')
screen:expect([[ screen:expect([[
|
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz| zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz|
zzzzzzzzzzzzzz{1: } | zzzzzzzzzzzzzz{1: } |
{4:~ }| {4:~ }|
{4:~ }|
{5:[No Name] [+] }| {5:[No Name] [+] }|
{3:-- INSERT --} | {3:-- INSERT --} |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
@ -211,6 +215,76 @@ describe('TUI', function()
]]) ]])
end) end)
it('forwards spurious "start paste" sequence', function()
-- If multiple "start paste" sequences are sent without a corresponding
-- "stop paste" sequence, only the first occurrence should be consumed.
-- Send the "start paste" sequence.
feed_data('i\027[200~')
feed_data('\npasted from terminal (1)\n')
-- Send spurious "start paste" sequence.
feed_data('\027[200~')
feed_data('\n')
-- Send the "stop paste" sequence.
feed_data('\027[201~')
screen:expect{grid=[[
|
pasted from terminal (1) |
{6:^[}[200~{1: } |
{4:~ }|
{5:[No Name] [+] }|
{3:-- INSERT --} |
{3:-- TERMINAL --} |
]],
attr_ids={
[1] = {reverse = true},
[2] = {background = tonumber('0x00000b')},
[3] = {bold = true},
[4] = {foreground = tonumber('0x00000c')},
[5] = {bold = true, reverse = true},
[6] = {foreground = tonumber('0x000051')},
}}
end)
it('ignores spurious "stop paste" sequence', function()
-- If "stop paste" sequence is received without a preceding "start paste"
-- sequence, it should be ignored.
feed_data('i')
-- Send "stop paste" sequence.
feed_data('\027[201~')
screen:expect([[
{1: } |
{4:~ }|
{4:~ }|
{4:~ }|
{5:[No Name] }|
{3:-- INSERT --} |
{3:-- TERMINAL --} |
]])
end)
-- TODO
it('in normal-mode', function()
end)
-- TODO
it('in command-mode', function()
end)
-- TODO
it('sets undo-point after consecutive pastes', function()
end)
-- TODO
it('handles missing "stop paste" sequence', function()
end)
-- TODO: error when pasting into 'nomodifiable' buffer:
-- [error @ do_put:2656] 17043 - Failed to save undo information
it("handles 'nomodifiable' buffer gracefully", function()
end)
it('allows termguicolors to be set at runtime', function() it('allows termguicolors to be set at runtime', function()
screen:set_option('rgb', true) screen:set_option('rgb', true)
screen:set_default_attr_ids({ screen:set_default_attr_ids({

View File

@ -110,77 +110,6 @@ describe('mappings', function()
end) end)
end) end)
describe('feeding large chunks of input with <Paste>', function()
local screen
before_each(function()
clear()
screen = Screen.new()
screen:attach()
feed_command('set ruler')
end)
it('ok', function()
if helpers.skip_fragile(pending) then
return
end
local t = {}
for i = 1, 20000 do
t[i] = 'item ' .. tostring(i)
end
command('doautocmd PastePre')
screen:expect([[
^ |
~ |
~ |
~ |
~ |
~ |
~ |
~ |
~ |
~ |
~ |
~ |
~ |
-- INSERT (paste) -- |
]])
feed(table.concat(t, '<Enter>'))
screen:expect([[
item 19988 |
item 19989 |
item 19990 |
item 19991 |
item 19992 |
item 19993 |
item 19994 |
item 19995 |
item 19996 |
item 19997 |
item 19998 |
item 19999 |
item 20000^ |
-- INSERT (paste) -- |
]])
command('doautocmd PastePost')
screen:expect([[
item 19988 |
item 19989 |
item 19990 |
item 19991 |
item 19992 |
item 19993 |
item 19994 |
item 19995 |
item 19996 |
item 19997 |
item 19998 |
item 19999 |
item 2000^0 |
20000,10 Bot |
]])
end)
end)
describe('input utf sequences that contain CSI/K_SPECIAL', function() describe('input utf sequences that contain CSI/K_SPECIAL', function()
before_each(clear) before_each(clear)
it('ok', function() it('ok', function()