diff src/popupwin.c @ 18544:a6dbbedddce1 v8.1.2266

patch 8.1.2266: position unknown for a mouse click in a popup window Commit: https://github.com/vim/vim/commit/f8b036bcae27014e4cbbdceec262b0a4c6dc2d9c Author: Bram Moolenaar <Bram@vim.org> Date: Wed Nov 6 21:09:17 2019 +0100 patch 8.1.2266: position unknown for a mouse click in a popup window Problem: Position unknown for a mouse click in a popup window. Solution: Set v:mouse_col and v:mouse_lnum. (closes https://github.com/vim/vim/issues/5171)
author Bram Moolenaar <Bram@vim.org>
date Wed, 06 Nov 2019 21:15:03 +0100
parents 244b336b94ce
children e5ef5d820b5b
line wrap: on
line diff
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -2862,12 +2862,31 @@ invoke_popup_filter(win_T *wp, int c)
 
     argv[2].v_type = VAR_UNKNOWN;
 
+    if (is_mouse_key(c))
+    {
+	int		row = mouse_row - wp->w_winrow;
+	int		col = mouse_col - wp->w_wincol;
+	linenr_T	lnum;
+
+	if (row >= 0 && col >= 0)
+	{
+	    (void)mouse_comp_pos(wp, &row, &col, &lnum, NULL);
+	    set_vim_var_nr(VV_MOUSE_LNUM, lnum);
+	    set_vim_var_nr(VV_MOUSE_COL, col + 1);
+	}
+    }
+
     // NOTE: The callback might close the popup and make "wp" invalid.
     call_callback(&wp->w_filter_cb, -1, &rettv, 2, argv);
     if (win_valid_popup(wp) && old_lnum != wp->w_cursor.lnum)
 	popup_highlight_curline(wp);
-
     res = tv_get_number(&rettv);
+
+    if (is_mouse_key(c))
+    {
+	set_vim_var_nr(VV_MOUSE_LNUM, 0);
+	set_vim_var_nr(VV_MOUSE_COL, 0);
+    }
     vim_free(argv[1].vval.v_string);
     clear_tv(&rettv);
     return res;
@@ -2891,8 +2910,6 @@ popup_do_filter(int c)
 	return FALSE;
     recursive = TRUE;
 
-    popup_reset_handled();
-
     if (c == K_LEFTMOUSE)
     {
 	int row = mouse_row;
@@ -2903,6 +2920,7 @@ popup_do_filter(int c)
 	    res = TRUE;
     }
 
+    popup_reset_handled();
     state = get_real_state();
     while (!res && (wp = find_next_popup(FALSE)) != NULL)
 	if (wp->w_filter_cb.cb_name != NULL