mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
feat(eval)!: input() support any type for "cancelreturn" in a dict (#19357)
This commit is contained in:
parent
778541067a
commit
b93cb481a2
@ -350,7 +350,8 @@ Commands:
|
||||
Functions:
|
||||
|input()| and |inputdialog()| support for each other’s features (return on
|
||||
cancel and completion respectively) via dictionary argument (replaces all
|
||||
other arguments if used).
|
||||
other arguments if used), and "cancelreturn" can have any type if passed in
|
||||
a dictionary.
|
||||
|input()| and |inputdialog()| support user-defined cmdline highlighting.
|
||||
|
||||
Highlight groups:
|
||||
|
@ -6554,7 +6554,8 @@ void get_user_input(const typval_T *const argvars, typval_T *const rettv, const
|
||||
|
||||
const char *prompt = "";
|
||||
const char *defstr = "";
|
||||
const char *cancelreturn = NULL;
|
||||
typval_T *cancelreturn = NULL;
|
||||
typval_T cancelreturn_strarg2 = TV_INITIAL_VALUE;
|
||||
const char *xp_name = NULL;
|
||||
Callback input_callback = { .type = kCallbackNone };
|
||||
char prompt_buf[NUMBUFLEN];
|
||||
@ -6576,13 +6577,9 @@ void get_user_input(const typval_T *const argvars, typval_T *const rettv, const
|
||||
if (defstr == NULL) {
|
||||
return;
|
||||
}
|
||||
cancelreturn = tv_dict_get_string_buf_chk(dict, S_LEN("cancelreturn"),
|
||||
cancelreturn_buf, def);
|
||||
if (cancelreturn == NULL) { // error
|
||||
return;
|
||||
}
|
||||
if (*cancelreturn == NUL) {
|
||||
cancelreturn = NULL;
|
||||
dictitem_T *cancelreturn_di = tv_dict_find(dict, S_LEN("cancelreturn"));
|
||||
if (cancelreturn_di != NULL) {
|
||||
cancelreturn = &cancelreturn_di->di_tv;
|
||||
}
|
||||
xp_name = tv_dict_get_string_buf_chk(dict, S_LEN("completion"),
|
||||
xp_name_buf, def);
|
||||
@ -6606,15 +6603,16 @@ void get_user_input(const typval_T *const argvars, typval_T *const rettv, const
|
||||
return;
|
||||
}
|
||||
if (argvars[2].v_type != VAR_UNKNOWN) {
|
||||
const char *const arg2 = tv_get_string_buf_chk(&argvars[2],
|
||||
cancelreturn_buf);
|
||||
if (arg2 == NULL) {
|
||||
const char *const strarg2 = tv_get_string_buf_chk(&argvars[2], cancelreturn_buf);
|
||||
if (strarg2 == NULL) {
|
||||
return;
|
||||
}
|
||||
if (inputdialog) {
|
||||
cancelreturn = arg2;
|
||||
cancelreturn_strarg2.v_type = VAR_STRING;
|
||||
cancelreturn_strarg2.vval.v_string = (char *)strarg2;
|
||||
cancelreturn = &cancelreturn_strarg2;
|
||||
} else {
|
||||
xp_name = arg2;
|
||||
xp_name = strarg2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6662,7 +6660,7 @@ void get_user_input(const typval_T *const argvars, typval_T *const rettv, const
|
||||
callback_free(&input_callback);
|
||||
|
||||
if (rettv->vval.v_string == NULL && cancelreturn != NULL) {
|
||||
rettv->vval.v_string = xstrdup(cancelreturn);
|
||||
tv_copy(cancelreturn, rettv);
|
||||
}
|
||||
|
||||
xfree(xp_arg);
|
||||
|
@ -9,6 +9,7 @@ local source = helpers.source
|
||||
local command = helpers.command
|
||||
local exc_exec = helpers.exc_exec
|
||||
local nvim_async = helpers.nvim_async
|
||||
local NIL = helpers.NIL
|
||||
|
||||
local screen
|
||||
|
||||
@ -200,6 +201,15 @@ describe('input()', function()
|
||||
feed(':let var = input({"cancelreturn": "BAR"})<CR>')
|
||||
feed('<Esc>')
|
||||
eq('BAR', meths.get_var('var'))
|
||||
feed(':let var = input({"cancelreturn": []})<CR>')
|
||||
feed('<Esc>')
|
||||
eq({}, meths.get_var('var'))
|
||||
feed(':let var = input({"cancelreturn": v:false})<CR>')
|
||||
feed('<Esc>')
|
||||
eq(false, meths.get_var('var'))
|
||||
feed(':let var = input({"cancelreturn": v:null})<CR>')
|
||||
feed('<Esc>')
|
||||
eq(NIL, meths.get_var('var'))
|
||||
end)
|
||||
it('supports default string', function()
|
||||
feed(':let var = input("", "DEF1")<CR>')
|
||||
@ -219,8 +229,6 @@ describe('input()', function()
|
||||
exc_exec('call input("", "", [])'))
|
||||
eq('Vim(call):E730: using List as a String',
|
||||
exc_exec('call input({"prompt": []})'))
|
||||
eq('Vim(call):E730: using List as a String',
|
||||
exc_exec('call input({"cancelreturn": []})'))
|
||||
eq('Vim(call):E730: using List as a String',
|
||||
exc_exec('call input({"default": []})'))
|
||||
eq('Vim(call):E730: using List as a String',
|
||||
@ -417,8 +425,6 @@ describe('inputdialog()', function()
|
||||
exc_exec('call inputdialog("", "", [])'))
|
||||
eq('Vim(call):E730: using List as a String',
|
||||
exc_exec('call inputdialog({"prompt": []})'))
|
||||
eq('Vim(call):E730: using List as a String',
|
||||
exc_exec('call inputdialog({"cancelreturn": []})'))
|
||||
eq('Vim(call):E730: using List as a String',
|
||||
exc_exec('call inputdialog({"default": []})'))
|
||||
eq('Vim(call):E730: using List as a String',
|
||||
|
Loading…
Reference in New Issue
Block a user