@@ -235,7 +235,7 @@ static int get_fpos_of_mouse(pos_T *mpos)
235235 }
236236
237237 // find the window where the row is in
238- win_T * wp = mouse_find_win (& grid , & row , & col );
238+ win_T * wp = mouse_find_win_inner (& grid , & row , & col );
239239 if (wp == NULL ) {
240240 return IN_UNKNOWN ;
241241 }
@@ -663,7 +663,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, int count, bool fixindent)
663663 int click_grid = mouse_grid ;
664664 int click_row = mouse_row ;
665665 int click_col = mouse_col ;
666- win_T * wp = mouse_find_win (& click_grid , & click_row , & click_col );
666+ win_T * wp = mouse_find_win_inner (& click_grid , & click_row , & click_col );
667667 if (wp == NULL ) {
668668 return false;
669669 }
@@ -1093,7 +1093,7 @@ void ins_mousescroll(int dir)
10931093 int grid = mouse_grid ;
10941094 int row = mouse_row ;
10951095 int col = mouse_col ;
1096- curwin = mouse_find_win (& grid , & row , & col );
1096+ curwin = mouse_find_win_inner (& grid , & row , & col );
10971097 if (curwin == NULL ) {
10981098 curwin = old_curwin ;
10991099 return ;
@@ -1263,8 +1263,8 @@ int jump_to_mouse(int flags, bool *inclusive, int which_button)
12631263 }
12641264
12651265 // find the window where the row is in and adjust "row" and "col" to be
1266- // relative to top-left of the window
1267- win_T * wp = mouse_find_win (& grid , & row , & col );
1266+ // relative to top-left of the window inner area
1267+ win_T * wp = mouse_find_win_inner (& grid , & row , & col );
12681268 if (wp == NULL ) {
12691269 return IN_UNKNOWN ;
12701270 }
@@ -1581,7 +1581,7 @@ void nv_mousescroll(cmdarg_T *cap)
15811581 int grid = mouse_grid ;
15821582 int row = mouse_row ;
15831583 int col = mouse_col ;
1584- curwin = mouse_find_win (& grid , & row , & col );
1584+ curwin = mouse_find_win_inner (& grid , & row , & col );
15851585 if (curwin == NULL ) {
15861586 curwin = old_curwin ;
15871587 return ;
@@ -1695,10 +1695,10 @@ bool mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump)
16951695}
16961696
16971697/// Find the window at "grid" position "*rowp" and "*colp". The positions are
1698- /// updated to become relative to the top-left of the window.
1698+ /// updated to become relative to the top-left of the window inner area .
16991699///
17001700/// @return NULL when something is wrong.
1701- win_T * mouse_find_win (int * gridp , int * rowp , int * colp )
1701+ win_T * mouse_find_win_inner (int * gridp , int * rowp , int * colp )
17021702{
17031703 win_T * wp_grid = mouse_find_grid_win (gridp , rowp , colp );
17041704 if (wp_grid ) {
@@ -1740,6 +1740,20 @@ win_T *mouse_find_win(int *gridp, int *rowp, int *colp)
17401740 return NULL ;
17411741}
17421742
1743+ /// Find the window at "grid" position "*rowp" and "*colp". The positions are
1744+ /// updated to become relative to the top-left of the window.
1745+ ///
1746+ /// @return NULL when something is wrong.
1747+ win_T * mouse_find_win_outer (int * gridp , int * rowp , int * colp )
1748+ {
1749+ win_T * wp = mouse_find_win_inner (gridp , rowp , colp );
1750+ if (wp ) {
1751+ * rowp += wp -> w_winrow_off ;
1752+ * colp += wp -> w_wincol_off ;
1753+ }
1754+ return wp ;
1755+ }
1756+
17431757static win_T * mouse_find_grid_win (int * gridp , int * rowp , int * colp )
17441758{
17451759 if (* gridp == msg_grid .handle ) {
@@ -1755,18 +1769,26 @@ static win_T *mouse_find_grid_win(int *gridp, int *rowp, int *colp)
17551769 }
17561770 } else if (* gridp == 0 ) {
17571771 ScreenGrid * grid = ui_comp_mouse_focus (* rowp , * colp );
1758- FOR_ALL_WINDOWS_IN_TAB (wp , curtab ) {
1759- if (& wp -> w_grid_alloc != grid ) {
1760- continue ;
1761- }
1772+ if (grid == & pum_grid ) {
17621773 * gridp = grid -> handle ;
1763- * rowp -= grid -> comp_row + wp -> w_grid .row_offset ;
1764- * colp -= grid -> comp_col + wp -> w_grid .col_offset ;
1765- return wp ;
1774+ * rowp -= grid -> comp_row ;
1775+ * colp -= grid -> comp_col ;
1776+ // The popup menu doesn't have a window, so return NULL
1777+ return NULL ;
1778+ } else {
1779+ FOR_ALL_WINDOWS_IN_TAB (wp , curtab ) {
1780+ if (& wp -> w_grid_alloc != grid ) {
1781+ continue ;
1782+ }
1783+ * gridp = grid -> handle ;
1784+ * rowp -= wp -> w_winrow + wp -> w_grid .row_offset ;
1785+ * colp -= wp -> w_wincol + wp -> w_grid .col_offset ;
1786+ return wp ;
1787+ }
17661788 }
17671789
1768- // no float found, click on the default grid
1769- // TODO(bfredl): grid can be &pum_grid, allow select pum items by mouse?
1790+ // No grid found, return the default grid. With multigrid this happens for split separators for
1791+ // example.
17701792 * gridp = DEFAULT_GRID_HANDLE ;
17711793 }
17721794 return NULL ;
@@ -1877,7 +1899,7 @@ static void mouse_check_grid(colnr_T *vcolp, int *flagsp)
18771899 int click_col = mouse_col ;
18781900
18791901 // XXX: this doesn't change click_grid if it is 1, even with multigrid
1880- if (mouse_find_win (& click_grid , & click_row , & click_col ) != curwin
1902+ if (mouse_find_win_inner (& click_grid , & click_row , & click_col ) != curwin
18811903 // Only use vcols[] after the window was redrawn. Mainly matters
18821904 // for tests, a user would not click before redrawing.
18831905 || curwin -> w_redr_type != 0 ) {
@@ -1931,7 +1953,7 @@ void f_getmousepos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
19311953 tv_dict_add_nr (d , S_LEN ("screenrow" ), (varnumber_T )mouse_row + 1 );
19321954 tv_dict_add_nr (d , S_LEN ("screencol" ), (varnumber_T )mouse_col + 1 );
19331955
1934- win_T * wp = mouse_find_win (& grid , & row , & col );
1956+ win_T * wp = mouse_find_win_inner (& grid , & row , & col );
19351957 if (wp != NULL ) {
19361958 int height = wp -> w_height + wp -> w_hsep_height + wp -> w_status_height ;
19371959 // The height is adjusted by 1 when there is a bottom border. This is not
0 commit comments