patch 9.0.2032: cannot get mouse click pos for tab or virt text
Problem: Cannot accurately get mouse clicking position when clicking on
a TAB or with virtual text.
Solution: Add a "coladd" field to getmousepos() result.
closes: #13335
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
diff --git a/src/mouse.c b/src/mouse.c
index fe5c14c..f895779 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -172,9 +172,7 @@
if (mouse_comp_pos(curwin, &row, &col, &mpos->lnum, NULL))
return IN_STATUS_LINE; // past bottom
- mpos->col = vcol2col(wp, mpos->lnum, col);
-
- mpos->coladd = 0;
+ mpos->col = vcol2col(wp, mpos->lnum, col, &mpos->coladd);
return IN_BUFFER;
}
#endif
@@ -3204,7 +3202,7 @@
* The first column is zero.
*/
int
-vcol2col(win_T *wp, linenr_T lnum, int vcol)
+vcol2col(win_T *wp, linenr_T lnum, int vcol, colnr_T *coladdp)
{
char_u *line;
chartabsize_T cts;
@@ -3222,6 +3220,8 @@
}
clear_chartabsize_arg(&cts);
+ if (coladdp != NULL)
+ *coladdp = vcol - cts.cts_vcol;
return (int)(cts.cts_ptr - line);
}
#endif
@@ -3242,6 +3242,7 @@
varnumber_T wincol = 0;
linenr_T lnum = 0;
varnumber_T column = 0;
+ colnr_T coladd = 0;
if (rettv_dict_alloc(rettv) == FAIL)
return;
@@ -3275,7 +3276,7 @@
if (row >= 0 && row < wp->w_height && col >= 0 && col < wp->w_width)
{
(void)mouse_comp_pos(wp, &row, &col, &lnum, NULL);
- col = vcol2col(wp, lnum, col);
+ col = vcol2col(wp, lnum, col, &coladd);
column = col + 1;
}
}
@@ -3285,5 +3286,6 @@
dict_add_number(d, "wincol", wincol);
dict_add_number(d, "line", (varnumber_T)lnum);
dict_add_number(d, "column", column);
+ dict_add_number(d, "coladd", coladd);
}
#endif