diff options
| author | Björn Linse <bjorn.linse@gmail.com> | 2019-08-31 11:18:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-31 11:18:35 +0200 |
| commit | 25e0a449bb6619fc534fa862c2f591657be1e1d5 (patch) | |
| tree | bf3d8beff647c8e1e5b39c746088843d629338ef /src/nvim/tui/input.c | |
| parent | 8a03acb8dad4abaf507d502b11a66bd5a2b5e51e (diff) | |
| parent | 2c605d1f22a243bc34b680f69c7c8cfe01b80887 (diff) | |
| download | rneovim-25e0a449bb6619fc534fa862c2f591657be1e1d5.tar.gz rneovim-25e0a449bb6619fc534fa862c2f591657be1e1d5.tar.bz2 rneovim-25e0a449bb6619fc534fa862c2f591657be1e1d5.zip | |
Merge pull request #10878 from bfredl/pastedefer
TUI: defer nvim_paste event properly
Diffstat (limited to 'src/nvim/tui/input.c')
| -rw-r--r-- | src/nvim/tui/input.c | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index 1f67e6ce13..ed9b410a19 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -106,17 +106,15 @@ static void tinput_wait_enqueue(void **argv) RBUFFER_UNTIL_EMPTY(input->key_buffer, buf, len) { const String keys = { .data = buf, .size = len }; if (input->paste) { - Error err = ERROR_INIT; - // Paste phase: "continue" (unless handler canceled). - input->paste = !nvim_paste(keys, true, input->paste, &err) - ? 0 : (1 == input->paste ? 2 : input->paste); + String copy = copy_string(keys); + 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 (ERROR_SET(&err)) { - // TODO(justinmk): emsgf() does not display, why? - msg_printf_attr(HL_ATTR(HLF_E)|MSG_HIST, "paste: %s", err.msg); - api_clear_error(&err); - } } else { const size_t consumed = input_enqueue(keys); if (consumed) { @@ -134,12 +132,27 @@ static void tinput_wait_enqueue(void **argv) uv_mutex_unlock(&input->key_buffer_mutex); } +static void tinput_paste_event(void **argv) +{ + String keys = { .data = argv[0], .size = (size_t)argv[1] }; + intptr_t phase = (intptr_t)argv[2]; + + Error err = ERROR_INIT; + nvim_paste(keys, true, phase, &err); + if (ERROR_SET(&err)) { + emsgf("paste: %s", err.msg); + api_clear_error(&err); + } + + api_free_string(keys); +} + static void tinput_flush(TermInput *input, bool wait_until_empty) { size_t drain_boundary = wait_until_empty ? 0 : 0xff; do { uv_mutex_lock(&input->key_buffer_mutex); - loop_schedule(&main_loop, event_create(tinput_wait_enqueue, 1, input)); + loop_schedule_fast(&main_loop, event_create(tinput_wait_enqueue, 1, input)); input->waiting = true; while (input->waiting) { uv_cond_wait(&input->key_buffer_cond, &input->key_buffer_mutex); @@ -497,7 +510,7 @@ static void tinput_read_cb(Stream *stream, RBuffer *buf, size_t count_, TermInput *input = data; if (eof) { - loop_schedule(&main_loop, event_create(tinput_done_event, 0)); + loop_schedule_fast(&main_loop, event_create(tinput_done_event, 0)); return; } |