aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/tui/input.c48
1 files changed, 21 insertions, 27 deletions
diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c
index 917847608a..24958ce041 100644
--- a/src/nvim/tui/input.c
+++ b/src/nvim/tui/input.c
@@ -115,34 +115,28 @@ static void tinput_done_event(void **argv)
static void tinput_wait_enqueue(void **argv)
{
TermInput *input = argv[0];
- if (rbuffer_size(input->key_buffer) == 0 && input->paste == 3) {
- // End streamed paste with an empty string.
- const String keys = { .data = "", .size = 0 };
- String copy = copy_string(keys);
- multiqueue_put(main_loop.events, tinput_paste_event, 3,
- copy.data, copy.size, (intptr_t)input->paste);
- }
- RBUFFER_UNTIL_EMPTY(input->key_buffer, buf, len) {
- const String keys = { .data = buf, .size = len };
- if (input->paste) {
- String copy = copy_string(keys);
- if (ui_client_channel_id) {
- Array args = ARRAY_DICT_INIT;
- ADD(args, STRING_OBJ(copy_string(keys))); // 'data'
- ADD(args, BOOLEAN_OBJ(true)); // 'crlf'
- ADD(args, INTEGER_OBJ(input->paste)); // 'phase'
- rpc_send_event(ui_client_channel_id, "nvim_paste", args);
- } else {
- multiqueue_put(main_loop.events, tinput_paste_event, 3,
- copy.data, copy.size, (intptr_t)input->paste);
- }
- if (input->paste == 1) {
- // Paste phase: "continue"
- input->paste = 2;
- }
- rbuffer_consumed(input->key_buffer, len);
- rbuffer_reset(input->key_buffer);
+ if (input->paste) { // produce exactly one paste event
+ const size_t len = rbuffer_size(input->key_buffer);
+ String keys = { .data = xmallocz(len), .size = len };
+ rbuffer_read(input->key_buffer, keys.data, len);
+ if (ui_client_channel_id) {
+ Array args = ARRAY_DICT_INIT;
+ ADD(args, STRING_OBJ(keys)); // 'data'
+ ADD(args, BOOLEAN_OBJ(true)); // 'crlf'
+ ADD(args, INTEGER_OBJ(input->paste)); // 'phase'
+ rpc_send_event(ui_client_channel_id, "nvim_paste", args);
} else {
+ multiqueue_put(main_loop.events, tinput_paste_event, 3,
+ keys.data, keys.size, (intptr_t)input->paste);
+ }
+ if (input->paste == 1) {
+ // Paste phase: "continue"
+ input->paste = 2;
+ }
+ rbuffer_reset(input->key_buffer);
+ } else { // enqueue input for the main thread or Nvim server
+ RBUFFER_UNTIL_EMPTY(input->key_buffer, buf, len) {
+ const String keys = { .data = buf, .size = len };
size_t consumed;
if (ui_client_channel_id) {
Array args = ARRAY_DICT_INIT;