0
0
mirror of https://github.com/vim/vim.git synced 2025-09-26 04:04:07 -04:00

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>
This commit is contained in:
zeertzjq
2023-10-15 10:03:30 +02:00
committed by Christian Brabandt
parent 3c81f47a05
commit f5a94d5165
8 changed files with 51 additions and 14 deletions

View File

@@ -172,9 +172,7 @@ get_fpos_of_mouse(pos_T *mpos)
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 @@ mouse_find_win(int *rowp, int *colp, mouse_find_T popup UNUSED)
* 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 @@ vcol2col(win_T *wp, linenr_T lnum, int vcol)
}
clear_chartabsize_arg(&cts);
if (coladdp != NULL)
*coladdp = vcol - cts.cts_vcol;
return (int)(cts.cts_ptr - line);
}
#endif
@@ -3242,6 +3242,7 @@ f_getmousepos(typval_T *argvars UNUSED, typval_T *rettv)
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 @@ f_getmousepos(typval_T *argvars UNUSED, typval_T *rettv)
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 @@ f_getmousepos(typval_T *argvars UNUSED, typval_T *rettv)
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