diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-05-27 21:58:00 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-05-27 21:58:00 +0100 |
commit | 5a6ec10cc80ab02eeff644ab19b82312630ea855 (patch) | |
tree | 5014800ed4c174f1abe451009e6d3ab86261a698 /src/move.c | |
parent | 968443efb5a2a1ed7e1084f2aff65a95f2d0a17b (diff) |
patch 8.2.5034: there is no way to get the byte index from a virtual columnv8.2.5034
Problem: There is no way to get the byte index from a virtual column.
Solution: Add virtcol2col(). (Yegappan Lakshmanan, closes #10477,
closes #10098)
Diffstat (limited to 'src/move.c')
-rw-r--r-- | src/move.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/move.c b/src/move.c index 58bd97fe04..5c78d6ce05 100644 --- a/src/move.c +++ b/src/move.c @@ -1322,6 +1322,39 @@ f_screenpos(typval_T *argvars UNUSED, typval_T *rettv) dict_add_number(dict, "curscol", ccol); dict_add_number(dict, "endcol", ecol); } + +/* + * "virtcol2col({winid}, {lnum}, {col})" function + */ + void +f_virtcol2col(typval_T *argvars UNUSED, typval_T *rettv) +{ + win_T *wp; + linenr_T lnum; + int screencol; + int error = FALSE; + + rettv->vval.v_number = -1; + + if (check_for_number_arg(argvars, 0) == FAIL + || check_for_number_arg(argvars, 1) == FAIL + || check_for_number_arg(argvars, 2) == FAIL) + return; + + wp = find_win_by_nr_or_id(&argvars[0]); + if (wp == NULL) + return; + + lnum = tv_get_number_chk(&argvars[1], &error); + if (error || lnum < 0 || lnum > wp->w_buffer->b_ml.ml_line_count) + return; + + screencol = tv_get_number_chk(&argvars[2], &error); + if (error || screencol < 0) + return; + + rettv->vval.v_number = vcol2col(wp, lnum, screencol); +} #endif /* |