aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-03-19 21:56:47 +0800
committerGitHub <noreply@github.com>2022-03-19 21:56:47 +0800
commit2ab52bd9889790dc7e47a09e801751aada418727 (patch)
treee44ab90e6daa359d32ecdc1fc10b35bb35bac2aa
parent536dc391f64685afd452df0e4362396a7039e655 (diff)
downloadrneovim-2ab52bd9889790dc7e47a09e801751aada418727.tar.gz
rneovim-2ab52bd9889790dc7e47a09e801751aada418727.tar.bz2
rneovim-2ab52bd9889790dc7e47a09e801751aada418727.zip
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.
-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;