]> granicus.if.org Git - vim/commitdiff
patch 8.1.2266: position unknown for a mouse click in a popup window v8.1.2266
authorBram Moolenaar <Bram@vim.org>
Wed, 6 Nov 2019 20:09:17 +0000 (21:09 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 6 Nov 2019 20:09:17 +0000 (21:09 +0100)
Problem:    Position unknown for a mouse click in a popup window.
Solution:   Set v:mouse_col and v:mouse_lnum. (closes #5171)

src/popupwin.c
src/testdir/test_popupwin.vim
src/version.c

index ce2f51da27ad479985dd0b69444a4f596960fa9b..a6e2e8726b2bfdb756a6aec47584a99987cac545 100644 (file)
@@ -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
index 0a45df4e1fd742ff1202495003573ef41f07ed5e..eab569fa9dfd10cda5cedb2c09c38831adcce102 100644 (file)
@@ -2166,6 +2166,44 @@ func Test_popupwin_filter_mode()
   delfunc MyPopupFilter
 endfunc
 
+func Test_popupwin_filter_mouse()
+  func MyPopupFilter(winid, c)
+    let g:got_mouse_col = v:mouse_col
+    let g:got_mouse_lnum = v:mouse_lnum
+    return 0
+  endfunc
+
+  let winid = popup_create(['short', 'long line that will wrap', 'short'], #{
+       \ line: 4,
+       \ col: 8,
+       \ maxwidth: 12,
+       \ filter: 'MyPopupFilter',
+       \ })
+  redraw
+  call test_setmouse(4, 8)
+  call feedkeys("\<LeftMouse>", 'xt')
+  call assert_equal(1, g:got_mouse_col)
+  call assert_equal(1, g:got_mouse_lnum)
+
+  call test_setmouse(5, 8)
+  call feedkeys("\<LeftMouse>", 'xt')
+  call assert_equal(1, g:got_mouse_col)
+  call assert_equal(2, g:got_mouse_lnum)
+
+  call test_setmouse(6, 8)
+  call feedkeys("\<LeftMouse>", 'xt')
+  call assert_equal(13, g:got_mouse_col)
+  call assert_equal(2, g:got_mouse_lnum)
+
+  call test_setmouse(7, 20)
+  call feedkeys("\<LeftMouse>", 'xt')
+  call assert_equal(13, g:got_mouse_col)
+  call assert_equal(3, g:got_mouse_lnum)
+
+  call popup_close(winid)
+  delfunc MyPopupFilter
+endfunc
+
 func Test_popupwin_with_buffer()
   call writefile(['some text', 'in a buffer'], 'XsomeFile')
   let buf = bufadd('XsomeFile')
index 73a0c1f41ae27f29d041292c3895f2f9f2c088e4..9bb1436c0f2e39dea33f22826c6a21727f1ebc1a 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2266,
 /**/
     2265,
 /**/