summaryrefslogtreecommitdiff
path: root/src/mouse.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-11-16 18:22:41 +0100
committerBram Moolenaar <Bram@vim.org>2019-11-16 18:22:41 +0100
commitdb3a205147ce2c335d5c2181c1f789277f8775b0 (patch)
tree1bb6a6d5158fee1d79718053ffa167396acf2970 /src/mouse.c
parent08f23636aef595f4cc061dfee8248dca97df16b3 (diff)
downloadvim-git-db3a205147ce2c335d5c2181c1f789277f8775b0.tar.gz
patch 8.1.2304: cannot get the mouse position when getting a mouse clickv8.1.2304
Problem: Cannot get the mouse position when getting a mouse click. Solution: Add getmousepos().
Diffstat (limited to 'src/mouse.c')
-rw-r--r--src/mouse.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/mouse.c b/src/mouse.c
index 3e1741f98..f215d3d99 100644
--- 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 vcol)
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