diff options
-rw-r--r-- | src/nvim/lua/vim.lua | 22 | ||||
-rw-r--r-- | src/nvim/tui/input.c | 1 | ||||
-rw-r--r-- | test/functional/terminal/paste_spec.lua | 204 | ||||
-rw-r--r-- | test/functional/terminal/tui_spec.lua | 80 | ||||
-rw-r--r-- | test/functional/ui/input_spec.lua | 71 |
5 files changed, 82 insertions, 296 deletions
diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua index 49eb99c81a..6759e4436b 100644 --- a/src/nvim/lua/vim.lua +++ b/src/nvim/lua/vim.lua @@ -94,26 +94,14 @@ local function _os_proc_children(ppid) end -- Default paste function. -local function _paste(data) +local function _paste(lines) + -- local eof = (lines == {''}) local call = vim.api.nvim_call_function 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', {'.'}) - vim.api.nvim_buf_set_lines( - 0, - curline, - curline, - false, - data) - call( - 'cursor', - {curline + #data, 9999999}) + -- vim.api.nvim_set_option('paste', true) + vim.api.nvim_put(lines, 'c', false) + -- vim.api.nvim_set_option('paste', false) -- TODO: do not redraw (slow!) until paste is finished. -- if eof then vim.api.nvim_command('redraw') diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index 163bc41dae..79615e30da 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -100,7 +100,6 @@ static void tinput_done_event(void **argv) input_done(); } -// TODO: send [''] to indicate EOF. static Array string_to_array(const String input) { Array ret = ARRAY_DICT_INIT; diff --git a/test/functional/terminal/paste_spec.lua b/test/functional/terminal/paste_spec.lua deleted file mode 100644 index 1c1f57246c..0000000000 --- a/test/functional/terminal/paste_spec.lua +++ /dev/null @@ -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) - diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 127cd69975..0aa9dace0e 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1,5 +1,9 @@ -- TUI acceptance tests. -- 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 uname = helpers.uname local thelpers = require('test.functional.terminal.helpers') @@ -159,10 +163,10 @@ describe('TUI', function() ]]) feed_data('pasted from terminal') screen:expect([[ - | pasted from terminal{1: } | {4:~ }| {4:~ }| + {4:~ }| {5:[No Name] [+] }| {3:-- INSERT --} | {3:-- TERMINAL --} | @@ -170,10 +174,10 @@ describe('TUI', function() feed_data('\027[201~') -- End paste. feed_data('\027\000') -- ESC: go to Normal mode. screen:expect([[ - | pasted from termina{1:l} | {4:~ }| {4:~ }| + {4:~ }| {5:[No Name] [+] }| | {3:-- TERMINAL --} | @@ -183,10 +187,10 @@ describe('TUI', function() it('pasting a specific amount of text #10311', function() feed_data('i\027[200~'..string.rep('z', 64)..'\027[201~') screen:expect([[ - | zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz| zzzzzzzzzzzzzz{1: } | {4:~ }| + {4:~ }| {5:[No Name] [+] }| {3:-- INSERT --} | {3:-- TERMINAL --} | @@ -211,6 +215,76 @@ describe('TUI', function() ]]) 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() screen:set_option('rgb', true) screen:set_default_attr_ids({ diff --git a/test/functional/ui/input_spec.lua b/test/functional/ui/input_spec.lua index 7b5c6aa29d..12d0e4f40b 100644 --- a/test/functional/ui/input_spec.lua +++ b/test/functional/ui/input_spec.lua @@ -110,77 +110,6 @@ describe('mappings', function() 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() before_each(clear) it('ok', function() |