diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-04-25 22:22:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-25 22:22:26 +0800 |
commit | bfa92d3861e425b59f9b1793c08247965a8e53f5 (patch) | |
tree | 349d8b96c0f34a37589ecc787e3c33a901dee85d /src/nvim/eval/funcs.c | |
parent | 43c49746d9cf82dba0d56b07d39722f9ebeecf90 (diff) | |
download | rneovim-bfa92d3861e425b59f9b1793c08247965a8e53f5.tar.gz rneovim-bfa92d3861e425b59f9b1793c08247965a8e53f5.tar.bz2 rneovim-bfa92d3861e425b59f9b1793c08247965a8e53f5.zip |
vim-patch:8.2.5019: cannot get the first screen column of a character (#23312)
Problem: Cannot get the first screen column of a character.
Solution: Let virtcol() optionally return a list. (closes vim/vim#10482,
closes vim/vim#7964)
https://github.com/vim/vim/commit/0f7a3e1de6f71e8e1423fe594890d6aa7f94e132
Co-authored-by: LemonBoy <thatlemon@gmail.com>
Diffstat (limited to 'src/nvim/eval/funcs.c')
-rw-r--r-- | src/nvim/eval/funcs.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 2a5f1cb720..72e25411ff 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -9275,10 +9275,11 @@ static void f_undotree(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) tv_dict_add_list(dict, S_LEN("entries"), u_eval_tree(curbuf->b_u_oldhead)); } -/// "virtcol(string)" function +/// "virtcol(string, bool)" function static void f_virtcol(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - colnr_T vcol = 0; + colnr_T vcol_start = 0; + colnr_T vcol_end = 0; int fnum = curbuf->b_fnum; pos_T *fp = var2fpos(&argvars[0], false, &fnum, false); @@ -9293,11 +9294,18 @@ static void f_virtcol(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) fp->col = (colnr_T)len; } } - getvvcol(curwin, fp, NULL, NULL, &vcol); - vcol++; + getvvcol(curwin, fp, &vcol_start, NULL, &vcol_end); + vcol_start++; + vcol_end++; } - rettv->vval.v_number = vcol; + if (argvars[1].v_type != VAR_UNKNOWN && tv_get_bool(&argvars[1])) { + tv_list_alloc_ret(rettv, 2); + tv_list_append_number(rettv->vval.v_list, vcol_start); + tv_list_append_number(rettv->vval.v_list, vcol_end); + } else { + rettv->vval.v_number = vcol_end; + } } /// "visualmode()" function |