diff src/move.c @ 29024:9f25e0ed831d v8.2.5034

patch 8.2.5034: there is no way to get the byte index from a virtual column Commit: https://github.com/vim/vim/commit/5a6ec10cc80ab02eeff644ab19b82312630ea855 Author: Bram Moolenaar <Bram@vim.org> Date: Fri May 27 21:58:00 2022 +0100 patch 8.2.5034: there is no way to get the byte index from a virtual column Problem: There is no way to get the byte index from a virtual column. Solution: Add virtcol2col(). (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/10477, closes #10098)
author Bram Moolenaar <Bram@vim.org>
date Fri, 27 May 2022 23:00:03 +0200
parents d0241e74bfdb
children 755ab148288b
line wrap: on
line diff
--- a/src/move.c
+++ b/src/move.c
@@ -1322,6 +1322,39 @@ f_screenpos(typval_T *argvars UNUSED, ty
     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
 
 /*