mirror of
https://github.com/neovim/neovim.git
synced 2025-10-06 01:46:29 +00:00
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().
0e5979a6d4
This commit is contained in:
@@ -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;
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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={},
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user