TUI/paste: always flush on paste mode-change

Flush input before entering, not only when leaving, paste mode. Else
there could be pending input which will erroneously be sent to the paste
handler.
This commit is contained in:
Justin M. Keyes 2019-08-19 00:18:41 +02:00
parent 6d277f43a2
commit 68ea9a7c8a
3 changed files with 21 additions and 24 deletions

View File

@ -96,17 +96,19 @@ end
-- Default paste function. -- Default paste function.
local function _paste(data) local function _paste(data)
-- local eof = (data == {''}) -- local eof = (data == {''})
local curline = vim.api.nvim_call_function('line', {'.'}) local curline = vim.api.nvim_call_function('line', {'.'}) - 1
vim.api.nvim_buf_set_lines( vim.api.nvim_buf_set_lines(
0, 0,
curline, curline,
curline, curline,
false, false,
data) data)
vim.api.nvim_call_function('cursor', {curline + #data, 1}) vim.api.nvim_call_function(
'cursor',
{curline + #data, 9999999})
-- 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')
-- end
return 0 return 0
end end

View File

@ -16,8 +16,6 @@
#include "nvim/os/input.h" #include "nvim/os/input.h"
#include "nvim/event/rstream.h" #include "nvim/event/rstream.h"
#define PASTE_KEY "<Paste>"
#define PASTEPOST_KEY "<PastePost>"
#define KEY_BUFFER_SIZE 0xfff #define KEY_BUFFER_SIZE 0xfff
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
@ -401,9 +399,7 @@ static bool handle_bracketed_paste(TermInput *input)
return true; return true;
} }
if (!enable) { tinput_flush(input, true);
tinput_flush(input, true);
}
input->paste_enabled = enable; input->paste_enabled = enable;
return true; return true;
} }

View File

@ -146,10 +146,8 @@ describe('TUI', function()
]], attrs) ]], attrs)
end) end)
it('automatically sends <Paste> for bracketed paste sequences', function() it('bracketed Paste', function()
-- Pasting can be really slow in the TUI, specially in ASAN. -- Pasting can be really slow in the TUI, specially in ASAN.
-- This will be fixed later but for now we require a high timeout.
screen.timeout = 60000
feed_data('i\027[200~') feed_data('i\027[200~')
screen:expect([[ screen:expect([[
{1: } | {1: } |
@ -157,29 +155,30 @@ describe('TUI', function()
{4:~ }| {4:~ }|
{4:~ }| {4:~ }|
{5:[No Name] }| {5:[No Name] }|
{3:-- INSERT (paste) --} | {3:-- INSERT --} |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
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:~ }|
{5:[No Name] [+] }|
{3:-- INSERT (paste) --} |
{3:-- TERMINAL --} |
]])
feed_data('\027[201~')
screen:expect([[
pasted from terminal{1: } |
{4:~ }|
{4:~ }| {4:~ }|
{4:~ }| {4:~ }|
{5:[No Name] [+] }| {5:[No Name] [+] }|
{3:-- INSERT --} | {3:-- INSERT --} |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
feed_data('\027[201~') -- End paste.
feed_data('\027\000') -- ESC: go to Normal mode.
screen:expect([[
pasted from termina{1:l} |
|
{4:~ }|
{4:~ }|
{5:[No Name] [+] }|
|
{3:-- TERMINAL --} |
]])
end) end)
it('handles pasting a specific amount of text', function() it('handles pasting a specific amount of text', function()