diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-10-15 17:19:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-15 17:19:01 +0800 |
commit | d974a3dcbb3757ebeb78fa64054c795ab7acdf1a (patch) | |
tree | d505cf88bb6f17fc3dcf33f96f811174b5b51d7e /src | |
parent | a350fb2976d9b1e8b5753f557645a905f6da0d74 (diff) | |
download | rneovim-d974a3dcbb3757ebeb78fa64054c795ab7acdf1a.tar.gz rneovim-d974a3dcbb3757ebeb78fa64054c795ab7acdf1a.tar.bz2 rneovim-d974a3dcbb3757ebeb78fa64054c795ab7acdf1a.zip |
vim-patch:9.0.2032: cannot get mouse click pos for tab or virt text (#25653)
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: vim/vim#13335
https://github.com/vim/vim/commit/f5a94d5165bb9e390797da50a1fa7a87df3fbee4
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.lua | 2 | ||||
-rw-r--r-- | src/nvim/mouse.c | 15 | ||||
-rw-r--r-- | src/nvim/move.c | 2 |
3 files changed, 12 insertions, 7 deletions
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 6ba5a171f9..46d17d8c03 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -4034,6 +4034,8 @@ M.funcs = { wincol column inside "winid" line text line inside "winid" column text column inside "winid" + coladd offset (in screen columns) from the + start of the clicked char All numbers are 1-based. If not over a window, e.g. when in the command line, then only diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index 75c399bcad..a76e4b7e53 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -243,9 +243,7 @@ static int get_fpos_of_mouse(pos_T *mpos) return IN_UNKNOWN; } - mpos->col = vcol2col(wp, mpos->lnum, col); - - mpos->coladd = 0; + mpos->col = vcol2col(wp, mpos->lnum, col, &mpos->coladd); return IN_BUFFER; } @@ -1755,8 +1753,8 @@ static win_T *mouse_find_grid_win(int *gridp, int *rowp, int *colp) /// Convert a virtual (screen) column to a character column. /// The first column is zero. -colnr_T vcol2col(win_T *const wp, const linenr_T lnum, const colnr_T vcol) - FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT +colnr_T vcol2col(win_T *wp, linenr_T lnum, colnr_T vcol, colnr_T *coladdp) + FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT { // try to advance to the specified column char *line = ml_get_buf(wp->w_buffer, lnum); @@ -1772,6 +1770,9 @@ colnr_T vcol2col(win_T *const wp, const linenr_T lnum, const colnr_T vcol) } clear_chartabsize_arg(&cts); + if (coladdp != NULL) { + *coladdp = vcol - cts.cts_vcol; + } return (colnr_T)(cts.cts_ptr - line); } @@ -1927,6 +1928,7 @@ void f_getmousepos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) varnumber_T wincol = 0; linenr_T lnum = 0; varnumber_T column = 0; + colnr_T coladd = 0; tv_dict_alloc_ret(rettv); dict_T *d = rettv->vval.v_dict; @@ -1945,7 +1947,7 @@ void f_getmousepos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) wincol = col + 1 + wp->w_wincol_off; // Adjust by 1 for left border if (row >= 0 && row < wp->w_height && col >= 0 && col < wp->w_width) { (void)mouse_comp_pos(wp, &row, &col, &lnum); - col = vcol2col(wp, lnum, col); + col = vcol2col(wp, lnum, col, &coladd); column = col + 1; } } @@ -1955,4 +1957,5 @@ void f_getmousepos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) tv_dict_add_nr(d, S_LEN("wincol"), wincol); tv_dict_add_nr(d, S_LEN("line"), (varnumber_T)lnum); tv_dict_add_nr(d, S_LEN("column"), column); + tv_dict_add_nr(d, S_LEN("coladd"), coladd); } diff --git a/src/nvim/move.c b/src/nvim/move.c index dfd2bf795d..8be05aaa24 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -1142,7 +1142,7 @@ void f_screenpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// returned. static int virtcol2col(win_T *wp, linenr_T lnum, int vcol) { - int offset = vcol2col(wp, lnum, vcol - 1); + int offset = vcol2col(wp, lnum, vcol - 1, NULL); char *line = ml_get_buf(wp->w_buffer, lnum); char *p = line + offset; |