diff options
author | erw7 <erw7.github@gmail.com> | 2019-05-23 06:38:02 +0900 |
---|---|---|
committer | erw7 <erw7.github@gmail.com> | 2020-02-12 15:30:06 +0900 |
commit | fe395ae210914eeec0f8592268b1960cb1b819b8 (patch) | |
tree | a4957f0f313a279b164036e70c0b4427ead27977 /src | |
parent | 783aecd501de2719f3059252e8444ef00c7c3d4a (diff) | |
download | rneovim-fe395ae210914eeec0f8592268b1960cb1b819b8.tar.gz rneovim-fe395ae210914eeec0f8592268b1960cb1b819b8.tar.bz2 rneovim-fe395ae210914eeec0f8592268b1960cb1b819b8.zip |
vim-patch:8.1.0069: cannot handle pressing CTRL-C in a prompt buffer
Problem: Cannot handle pressing CTRL-C in a prompt buffer.
Solution: Add prompt_setinterrupt().
https://github.com/vim/vim/commit/0e5979a6d491f68c4a8c86fab489016919329a6b
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/buffer.c | 2 | ||||
-rw-r--r-- | src/nvim/edit.c | 10 | ||||
-rw-r--r-- | src/nvim/eval.c | 17 | ||||
-rw-r--r-- | src/nvim/eval.lua | 1 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 25 |
5 files changed, 55 insertions, 0 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index a9b37af917..790609ab94 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -765,6 +765,7 @@ static void free_buffer(buf_T *buf) tv_dict_unref(buf->additional_data); xfree(buf->b_prompt_text); callback_free(&buf->b_prompt_callback); + callback_free(&buf->b_prompt_interrupt); clear_fmark(&buf->b_last_cursor); clear_fmark(&buf->b_last_insert); clear_fmark(&buf->b_last_change); @@ -1879,6 +1880,7 @@ buf_T * buflist_new(char_u *ffname, char_u *sfname, linenr_T lnum, int flags) } buf->b_prompt_callback.type = kCallbackNone; + buf->b_prompt_interrupt.type = kCallbackNone; buf->b_prompt_text = NULL; return buf; diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 40d34bd0b7..cebd08af28 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -823,6 +823,16 @@ static int insert_handle_key(InsertState *s) s->nomove = true; return 0; // exit insert mode } + if (s->c == Ctrl_C && bt_prompt(curbuf)) { + if (invoke_prompt_interrupt()) { + if (!bt_prompt(curbuf)) { + // buffer changed to a non-prompt buffer, get out of + // Insert mode + return 0; + } + break; + } + } // when 'insertmode' set, and not halfway through a mapping, don't leave // Insert mode diff --git a/src/nvim/eval.c b/src/nvim/eval.c index b330e7161d..7b5845e18b 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -13718,3 +13718,20 @@ void invoke_prompt_callback(void) tv_clear(&argv[0]); tv_clear(&rettv); } + +// Return true When the interrupt callback was invoked. +bool invoke_prompt_interrupt(void) +{ + typval_T rettv; + typval_T argv[1]; + + if (curbuf->b_prompt_interrupt.type == kCallbackNone) { + return false; + } + argv[0].v_type = VAR_UNKNOWN; + + got_int = false; // don't skip executing commands + callback_call(&curbuf->b_prompt_interrupt, 0, argv, &rettv); + tv_clear(&rettv); + return true; +} diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index fb72402f0d..1ca6b75b7e 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -244,6 +244,7 @@ return { prevnonblank={args=1}, printf={args=varargs(1)}, prompt_setcallback={args={2, 2}}, + prompt_setinterrupt={args={2, 2}}, prompt_setprompt={args={2, 2}}, pum_getpos={}, pumvisible={}, diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index a89d62fdfd..48e2ef8c51 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -6101,6 +6101,31 @@ static void f_prompt_setcallback(typval_T *argvars, buf->b_prompt_callback = prompt_callback; } +// "prompt_setinterrupt({buffer}, {callback})" function +static void f_prompt_setinterrupt(typval_T *argvars, + typval_T *rettv, FunPtr fptr) +{ + buf_T *buf; + Callback interrupt_callback = { .type = kCallbackNone }; + + if (check_secure()) { + return; + } + buf = tv_get_buf(&argvars[0], false); + if (buf == NULL) { + return; + } + + if (argvars[1].v_type != VAR_STRING || *argvars[1].vval.v_string != NUL) { + if (!callback_from_typval(&interrupt_callback, &argvars[1])) { + return; + } + } + + callback_free(&buf->b_prompt_interrupt); + buf->b_prompt_interrupt= interrupt_callback; +} + // "prompt_setprompt({buffer}, {text})" function static void f_prompt_setprompt(typval_T *argvars, typval_T *rettv, FunPtr fptr) |