Mercurial > vim
diff src/mouse.c @ 18623:3089b422b9dc v8.1.2304
patch 8.1.2304: cannot get the mouse position when getting a mouse click
Commit: https://github.com/vim/vim/commit/db3a205147ce2c335d5c2181c1f789277f8775b0
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Nov 16 18:22:41 2019 +0100
patch 8.1.2304: cannot get the mouse position when getting a mouse click
Problem: Cannot get the mouse position when getting a mouse click.
Solution: Add getmousepos().
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 16 Nov 2019 18:30:04 +0100 |
parents | fa995154904e |
children | e00e8fbbec4a |
line wrap: on
line diff
--- a/src/mouse.c +++ b/src/mouse.c @@ -2822,6 +2822,7 @@ mouse_comp_pos( int retval = FALSE; int off; int count; + char_u *p; #ifdef FEAT_RIGHTLEFT if (win->w_p_rl) @@ -2881,6 +2882,11 @@ mouse_comp_pos( col += row * (win->w_width - off); // add skip column (for long wrapping line) col += win->w_skipcol; + // limit to text length plus one + p = ml_get_buf(win->w_buffer, lnum, FALSE); + count = STRLEN(p); + if (col > count) + col = count; } if (!win->w_p_wrap) @@ -3001,3 +3007,61 @@ vcol2col(win_T *wp, linenr_T lnum, int v return (int)(ptr - line); } #endif + +#if defined(FEAT_EVAL) || defined(PROTO) + void +f_getmousepos(typval_T *argvars UNUSED, typval_T *rettv) +{ + dict_T *d; + win_T *wp; + int row = mouse_row; + int col = mouse_col; + varnumber_T winid = 0; + varnumber_T winrow = 0; + varnumber_T wincol = 0; + varnumber_T line = 0; + varnumber_T column = 0; + + if (rettv_dict_alloc(rettv) != OK) + return; + d = rettv->vval.v_dict; + + dict_add_number(d, "screenrow", (varnumber_T)mouse_row + 1); + dict_add_number(d, "screencol", (varnumber_T)mouse_col + 1); + + wp = mouse_find_win(&row, &col, FIND_POPUP); + if (wp != NULL) + { + int top_off = 0; + int left_off = 0; + int height = wp->w_height + wp->w_status_height; + +#ifdef FEAT_TEXT_PROP + if (WIN_IS_POPUP(wp)) + { + top_off = popup_top_extra(wp); + left_off = popup_left_extra(wp); + height = popup_height(wp); + } +#endif + if (row < height) + { + winid = wp->w_id; + winrow = row + 1; + wincol = col + 1; + row -= top_off; + col -= left_off; + if (row >= 0 && row < wp->w_height && col >= 0 && col < wp->w_width) + { + mouse_comp_pos(wp, &row, &col, &line, NULL); + column = col + 1; + } + } + } + dict_add_number(d, "winid", winid); + dict_add_number(d, "winrow", winrow); + dict_add_number(d, "wincol", wincol); + dict_add_number(d, "line", line); + dict_add_number(d, "column", column); +} +#endif