neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 2ab52bd9889790dc7e47a09e801751aada418727
parent 536dc391f64685afd452df0e4362396a7039e655
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Sat, 19 Mar 2022 21:56:47 +0800

refactor(tinput_wait_enqueue): use rbuffer_read() when pasting (#17754)

When pasting, all of key buffer can be consumed, and in case of phase 3
the paste event must be put exactly once, so using rbuffer_read() should
be better here.
Diffstat:
Msrc/nvim/tui/input.c | 48+++++++++++++++++++++---------------------------
1 file changed, 21 insertions(+), 27 deletions(-)

diff --git 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;