diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2016-09-25 09:47:23 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2016-10-15 09:50:59 +0200 |
commit | 719dae2e010cea048084a4abd5a69b3cecc5eb2a (patch) | |
tree | f038b033af9bb31832e3a3b03e7efab40080dddc /src/nvim/eval.c | |
parent | 5a61ff188c60a9ce6cd6bfc7bfdf5ccbd7616523 (diff) | |
download | rneovim-719dae2e010cea048084a4abd5a69b3cecc5eb2a.tar.gz rneovim-719dae2e010cea048084a4abd5a69b3cecc5eb2a.tar.bz2 rneovim-719dae2e010cea048084a4abd5a69b3cecc5eb2a.zip |
events: allow event processing in getchar()
this is consistent with vim, and is necessary for plugins that implement
their own input modes using "getchar()" and still want to do async
event processing.
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r-- | src/nvim/eval.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index cae032f437..dce2f32707 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -9527,24 +9527,35 @@ static void f_getchar(typval_T *argvars, typval_T *rettv, FunPtr fptr) varnumber_T n; int error = FALSE; - /* Position the cursor. Needed after a message that ends in a space. */ - ui_cursor_goto(msg_row, msg_col); - ++no_mapping; ++allow_keys; for (;; ) { - if (argvars[0].v_type == VAR_UNKNOWN) - /* getchar(): blocking wait. */ + // Position the cursor. Needed after a message that ends in a space, + // or if event processing caused a redraw. + ui_cursor_goto(msg_row, msg_col); + + if (argvars[0].v_type == VAR_UNKNOWN) { + // getchar(): blocking wait. + if (!(char_avail() || using_script() || input_available())) { + input_enable_events(); + (void)os_inchar(NULL, 0, -1, 0); + input_disable_events(); + if (!multiqueue_empty(main_loop.events)) { + multiqueue_process_events(main_loop.events); + continue; + } + } n = safe_vgetc(); - else if (get_tv_number_chk(&argvars[0], &error) == 1) - /* getchar(1): only check if char avail */ + } else if (get_tv_number_chk(&argvars[0], &error) == 1) { + // getchar(1): only check if char avail n = vpeekc_any(); - else if (error || vpeekc_any() == NUL) - /* illegal argument or getchar(0) and no char avail: return zero */ + } else if (error || vpeekc_any() == NUL) { + // illegal argument or getchar(0) and no char avail: return zero n = 0; - else - /* getchar(0) and char avail: return char */ + } else { + // getchar(0) and char avail: return char n = safe_vgetc(); + } if (n == K_IGNORE) continue; |