mirror of
https://github.com/neovim/neovim.git
synced 2025-10-06 01:46:29 +00:00
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.
This commit is contained in:
@@ -115,34 +115,28 @@ static void tinput_done_event(void **argv)
|
|||||||
static void tinput_wait_enqueue(void **argv)
|
static void tinput_wait_enqueue(void **argv)
|
||||||
{
|
{
|
||||||
TermInput *input = argv[0];
|
TermInput *input = argv[0];
|
||||||
if (rbuffer_size(input->key_buffer) == 0 && input->paste == 3) {
|
if (input->paste) { // produce exactly one paste event
|
||||||
// End streamed paste with an empty string.
|
const size_t len = rbuffer_size(input->key_buffer);
|
||||||
const String keys = { .data = "", .size = 0 };
|
String keys = { .data = xmallocz(len), .size = len };
|
||||||
String copy = copy_string(keys);
|
rbuffer_read(input->key_buffer, keys.data, len);
|
||||||
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) {
|
if (ui_client_channel_id) {
|
||||||
Array args = ARRAY_DICT_INIT;
|
Array args = ARRAY_DICT_INIT;
|
||||||
ADD(args, STRING_OBJ(copy_string(keys))); // 'data'
|
ADD(args, STRING_OBJ(keys)); // 'data'
|
||||||
ADD(args, BOOLEAN_OBJ(true)); // 'crlf'
|
ADD(args, BOOLEAN_OBJ(true)); // 'crlf'
|
||||||
ADD(args, INTEGER_OBJ(input->paste)); // 'phase'
|
ADD(args, INTEGER_OBJ(input->paste)); // 'phase'
|
||||||
rpc_send_event(ui_client_channel_id, "nvim_paste", args);
|
rpc_send_event(ui_client_channel_id, "nvim_paste", args);
|
||||||
} else {
|
} else {
|
||||||
multiqueue_put(main_loop.events, tinput_paste_event, 3,
|
multiqueue_put(main_loop.events, tinput_paste_event, 3,
|
||||||
copy.data, copy.size, (intptr_t)input->paste);
|
keys.data, keys.size, (intptr_t)input->paste);
|
||||||
}
|
}
|
||||||
if (input->paste == 1) {
|
if (input->paste == 1) {
|
||||||
// Paste phase: "continue"
|
// Paste phase: "continue"
|
||||||
input->paste = 2;
|
input->paste = 2;
|
||||||
}
|
}
|
||||||
rbuffer_consumed(input->key_buffer, len);
|
|
||||||
rbuffer_reset(input->key_buffer);
|
rbuffer_reset(input->key_buffer);
|
||||||
} else {
|
} 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;
|
size_t consumed;
|
||||||
if (ui_client_channel_id) {
|
if (ui_client_channel_id) {
|
||||||
Array args = ARRAY_DICT_INIT;
|
Array args = ARRAY_DICT_INIT;
|
||||||
|
Reference in New Issue
Block a user