diff options
Diffstat (limited to 'src/nvim/os/input.c')
-rw-r--r-- | src/nvim/os/input.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 745b888b5e..9ee2f57b3d 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -98,7 +98,7 @@ static void create_cursorhold_event(bool events_enabled) /// Low level input function /// -/// wait until either the input buffer is non-empty or , if `events` is not NULL +/// wait until either the input buffer is non-empty or, if `events` is not NULL /// until `events` is non-empty. int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt, MultiQueue *events) { @@ -106,6 +106,11 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt, MultiQueue *e return (int)rbuffer_read(input_buffer, (char *)buf, (size_t)maxlen); } + // No risk of a UI flood, so disable CTRL-C "interrupt" behavior if it's mapped. + if ((mapped_ctrl_c | curbuf->b_mapped_ctrl_c) & get_real_state()) { + ctrl_c_interrupts = false; + } + InbufPollResult result; if (ms >= 0) { if ((result = inbuf_poll(ms, events)) == kInputNone) { @@ -127,6 +132,8 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt, MultiQueue *e } } + ctrl_c_interrupts = true; + // If input was put directly in typeahead buffer bail out here. if (typebuf_changed(tb_change_cnt)) { return 0; @@ -238,9 +245,9 @@ size_t input_enqueue(String keys) // but since the keys are UTF-8, so the first byte cannot be // K_SPECIAL(0x80). uint8_t buf[19] = { 0 }; + // Do not simplify the keys here. Simplification will be done later. unsigned int new_size - = trans_special((const uint8_t **)&ptr, (size_t)(end - ptr), buf, true, - false); + = trans_special((const uint8_t **)&ptr, (size_t)(end - ptr), buf, FSK_KEYCODE, NULL); if (new_size) { new_size = handle_mouse_event(&ptr, buf, new_size); @@ -275,7 +282,7 @@ size_t input_enqueue(String keys) } size_t rv = (size_t)(ptr - keys.data); - process_interrupts(); + process_ctrl_c(); return rv; } @@ -413,7 +420,7 @@ size_t input_enqueue_mouse(int code, uint8_t modifier, int grid, int row, int co mouse_row = row; mouse_col = col; - size_t written = 3 + (size_t)(p-buf); + size_t written = 3 + (size_t)(p - buf); rbuffer_write(input_buffer, (char *)buf, written); return written; } @@ -480,15 +487,20 @@ static void input_read_cb(Stream *stream, RBuffer *buf, size_t c, void *data, bo } } -static void process_interrupts(void) +static void process_ctrl_c(void) { - if ((mapped_ctrl_c | curbuf->b_mapped_ctrl_c) & get_real_state()) { + if (!ctrl_c_interrupts) { return; } size_t consume_count = 0; RBUFFER_EACH_REVERSE(input_buffer, c, i) { - if ((uint8_t)c == Ctrl_C) { + if ((uint8_t)c == Ctrl_C + || ((uint8_t)c == 'C' && i >= 3 + && (uint8_t)(*rbuffer_get(input_buffer, i - 3)) == K_SPECIAL + && (uint8_t)(*rbuffer_get(input_buffer, i - 2)) == KS_MODIFIER + && (uint8_t)(*rbuffer_get(input_buffer, i - 1)) == MOD_MASK_CTRL)) { + *rbuffer_get(input_buffer, i) = Ctrl_C; got_int = true; consume_count = i; break; |