@@ -2205,42 +2205,106 @@ endfunc
22052205
22062206func Test_popupwin_filter_mouse ()
22072207 func MyPopupFilter (winid, c )
2208- let g: got_mouse_col = v: mouse_col
2209- let g: got_mouse_lnum = v: mouse_lnum
2210- let g: got_mouse_winid = v: mouse_winid
2208+ let g: got_mousepos = getmousepos ()
22112209 return 0
22122210 endfunc
22132211
2214- let winid = popup_create ([' short' , ' long line that will wrap' , ' short' ], #{
2215- \ line : 4 ,
2216- \ col : 8 ,
2212+ call setline (1 , [' .' - >repeat (25 )]- >repeat (10 ))
2213+ let winid = popup_create ([' short' , ' long line that will wrap' , ' other' ], #{
2214+ \ line : 2 ,
2215+ \ col : 4 ,
22172216 \ maxwidth: 12 ,
2217+ \ padding: [],
2218+ \ border: [],
22182219 \ filter : ' MyPopupFilter' ,
22192220 \ })
22202221 redraw
2221- call test_setmouse (4 , 8 )
2222- call feedkeys (" \<LeftMouse> " , ' xt' )
2223- call assert_equal (1 , g: got_mouse_col )
2224- call assert_equal (1 , g: got_mouse_lnum )
2225- call assert_equal (winid, g: got_mouse_winid )
2226-
2227- call test_setmouse (5 , 8 )
2228- call feedkeys (" \<LeftMouse> " , ' xt' )
2229- call assert_equal (1 , g: got_mouse_col )
2230- call assert_equal (2 , g: got_mouse_lnum )
2231-
2232- call test_setmouse (6 , 8 )
2233- call feedkeys (" \<LeftMouse> " , ' xt' )
2234- call assert_equal (13 , g: got_mouse_col )
2235- call assert_equal (2 , g: got_mouse_lnum )
2222+ " 123456789012345678901
2223+ " 1 .....................
2224+ " 2 ...+--------------+..
2225+ " 3 ...| |..
2226+ " 4 ...| short |..
2227+ " 5 ...| long line th |..
2228+ " 6 ...| at will wrap |..
2229+ " 7 ...| other |..
2230+ " 8 ...| |..
2231+ " 9 ...+--------------+..
2232+ " 10 .....................
2233+ let tests = []
2234+
2235+ func AddItemOutsidePopup (tests, row, col )
2236+ eval a: tests- >add (#{clickrow: a: row , clickcol: a: col , result: #{
2237+ \ screenrow : a: row , screencol : a: col ,
2238+ \ winid: win_getid (), winrow: a: row , wincol : a: col ,
2239+ \ line : a: row , column: a: col ,
2240+ \ }})
2241+ endfunc
2242+ func AddItemInPopupBorder (tests, winid, row, col )
2243+ eval a: tests- >add (#{clickrow: a: row , clickcol: a: col , result: #{
2244+ \ screenrow : a: row , screencol : a: col ,
2245+ \ winid: a: winid , winrow: a: row - 1 , wincol : a: col - 3 ,
2246+ \ line : 0 , column: 0 ,
2247+ \ }})
2248+ endfunc
2249+ func AddItemInPopupText (tests, winid, row, col , textline, textcol)
2250+ eval a: tests- >add (#{clickrow: a: row , clickcol: a: col , result: #{
2251+ \ screenrow : a: row , screencol : a: col ,
2252+ \ winid: a: winid , winrow: a: row - 1 , wincol : a: col - 3 ,
2253+ \ line : a: textline , column: a: textcol ,
2254+ \ }})
2255+ endfunc
22362256
2237- call test_setmouse (7 , 20 )
2238- call feedkeys (" \<LeftMouse> " , ' xt' )
2239- call assert_equal (13 , g: got_mouse_col )
2240- call assert_equal (3 , g: got_mouse_lnum )
2241- call assert_equal (winid, g: got_mouse_winid )
2257+ " above and below popup
2258+ for c in range (1 , 21 )
2259+ call AddItemOutsidePopup (tests, 1 , c )
2260+ call AddItemOutsidePopup (tests, 10 , c )
2261+ endfor
2262+ " left and right of popup
2263+ for r in range (1 , 10 )
2264+ call AddItemOutsidePopup (tests, r , 3 )
2265+ call AddItemOutsidePopup (tests, r , 20 )
2266+ endfor
2267+ " top and bottom in popup
2268+ for c in range (4 , 19 )
2269+ call AddItemInPopupBorder (tests, winid, 2 , c )
2270+ call AddItemInPopupBorder (tests, winid, 3 , c )
2271+ call AddItemInPopupBorder (tests, winid, 8 , c )
2272+ call AddItemInPopupBorder (tests, winid, 9 , c )
2273+ endfor
2274+ " left and right margin in popup
2275+ for r in range (2 , 9 )
2276+ call AddItemInPopupBorder (tests, winid, r , 4 )
2277+ call AddItemInPopupBorder (tests, winid, r , 5 )
2278+ call AddItemInPopupBorder (tests, winid, r , 18 )
2279+ call AddItemInPopupBorder (tests, winid, r , 19 )
2280+ endfor
2281+ " text "short"
2282+ call AddItemInPopupText (tests, winid, 4 , 6 , 1 , 1 )
2283+ call AddItemInPopupText (tests, winid, 4 , 10 , 1 , 5 )
2284+ call AddItemInPopupText (tests, winid, 4 , 11 , 1 , 6 )
2285+ call AddItemInPopupText (tests, winid, 4 , 17 , 1 , 6 )
2286+ " text "long line th"
2287+ call AddItemInPopupText (tests, winid, 5 , 6 , 2 , 1 )
2288+ call AddItemInPopupText (tests, winid, 5 , 10 , 2 , 5 )
2289+ call AddItemInPopupText (tests, winid, 5 , 17 , 2 , 12 )
2290+ " text "at will wrap"
2291+ call AddItemInPopupText (tests, winid, 6 , 6 , 2 , 13 )
2292+ call AddItemInPopupText (tests, winid, 6 , 10 , 2 , 17 )
2293+ call AddItemInPopupText (tests, winid, 6 , 17 , 2 , 24 )
2294+ " text "other"
2295+ call AddItemInPopupText (tests, winid, 7 , 6 , 3 , 1 )
2296+ call AddItemInPopupText (tests, winid, 7 , 10 , 3 , 5 )
2297+ call AddItemInPopupText (tests, winid, 7 , 11 , 3 , 6 )
2298+ call AddItemInPopupText (tests, winid, 7 , 17 , 3 , 6 )
2299+
2300+ for item in tests
2301+ call test_setmouse (item.clickrow, item.clickcol)
2302+ call feedkeys (" \<LeftMouse> " , ' xt' )
2303+ call assert_equal (item.result, g: got_mousepos )
2304+ endfor
22422305
22432306 call popup_close (winid)
2307+ enew !
22442308 delfunc MyPopupFilter
22452309endfunc
22462310
0 commit comments