mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 14:38:32 +00:00
feat(prompt): prompt_getinput() gets current input #34491
Problem: Not easy to get user-input in prompt-buffer before the user submits the input. Under the current system user/plugin needs to read the buffer contents, figure out where the prompt is, then extract the text. Solution: - Add prompt_getinput(). - Extract prompt text extraction logic to a separate function
This commit is contained in:
@@ -5364,6 +5364,26 @@ static void f_prompt_setprompt(typval_T *argvars, typval_T *rettv, EvalFuncData
|
||||
buf->b_prompt_text = xstrdup(text);
|
||||
}
|
||||
|
||||
/// "prompt_getinput({buffer})" function
|
||||
static void f_prompt_getinput(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
// return an empty string by default, e.g. it's not a prompt buffer
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = NULL;
|
||||
|
||||
buf_T *const buf = tv_get_buf_from_arg(&argvars[0]);
|
||||
if (buf == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bt_prompt(buf)) {
|
||||
return;
|
||||
}
|
||||
|
||||
rettv->vval.v_string = prompt_get_input(buf);
|
||||
}
|
||||
|
||||
/// "pum_getpos()" function
|
||||
static void f_pum_getpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
{
|
||||
|
Reference in New Issue
Block a user