patch 8.1.2304: cannot get the mouse position when getting a mouse click
Problem: Cannot get the mouse position when getting a mouse click.
Solution: Add getmousepos().
diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim
index 4f39d87..e7b81da 100644
--- a/src/testdir/test_functions.vim
+++ b/src/testdir/test_functions.vim
@@ -1331,6 +1331,7 @@
call feedkeys('a', '')
call assert_equal(char2nr('a'), getchar())
+ call setline(1, 'xxxx')
call test_setmouse(1, 3)
let v:mouse_win = 9
let v:mouse_winid = 9
@@ -1342,6 +1343,7 @@
call assert_equal(win_getid(1), v:mouse_winid)
call assert_equal(1, v:mouse_lnum)
call assert_equal(3, v:mouse_col)
+ enew!
endfunc
func Test_libcall_libcallnr()
diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim
index 44e1819..041d834 100644
--- a/src/testdir/test_popupwin.vim
+++ b/src/testdir/test_popupwin.vim
@@ -2205,42 +2205,106 @@
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
- let g:got_mouse_winid = v:mouse_winid
+ let g:got_mousepos = getmousepos()
return 0
endfunc
- let winid = popup_create(['short', 'long line that will wrap', 'short'], #{
- \ line: 4,
- \ col: 8,
+ call setline(1, ['.'->repeat(25)]->repeat(10))
+ let winid = popup_create(['short', 'long line that will wrap', 'other'], #{
+ \ line: 2,
+ \ col: 4,
\ maxwidth: 12,
+ \ padding: [],
+ \ border: [],
\ 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 assert_equal(winid, g:got_mouse_winid)
+ " 123456789012345678901
+ " 1 .....................
+ " 2 ...+--------------+..
+ " 3 ...| |..
+ " 4 ...| short |..
+ " 5 ...| long line th |..
+ " 6 ...| at will wrap |..
+ " 7 ...| other |..
+ " 8 ...| |..
+ " 9 ...+--------------+..
+ " 10 .....................
+ let tests = []
- 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)
+ func AddItemOutsidePopup(tests, row, col)
+ eval a:tests->add(#{clickrow: a:row, clickcol: a:col, result: #{
+ \ screenrow: a:row, screencol: a:col,
+ \ winid: win_getid(), winrow: a:row, wincol: a:col,
+ \ line: a:row, column: a:col,
+ \ }})
+ endfunc
+ func AddItemInPopupBorder(tests, winid, row, col)
+ eval a:tests->add(#{clickrow: a:row, clickcol: a:col, result: #{
+ \ screenrow: a:row, screencol: a:col,
+ \ winid: a:winid, winrow: a:row - 1, wincol: a:col - 3,
+ \ line: 0, column: 0,
+ \ }})
+ endfunc
+ func AddItemInPopupText(tests, winid, row, col, textline, textcol)
+ eval a:tests->add(#{clickrow: a:row, clickcol: a:col, result: #{
+ \ screenrow: a:row, screencol: a:col,
+ \ winid: a:winid, winrow: a:row - 1, wincol: a:col - 3,
+ \ line: a:textline, column: a:textcol,
+ \ }})
+ endfunc
- 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)
+ " above and below popup
+ for c in range(1, 21)
+ call AddItemOutsidePopup(tests, 1, c)
+ call AddItemOutsidePopup(tests, 10, c)
+ endfor
+ " left and right of popup
+ for r in range(1, 10)
+ call AddItemOutsidePopup(tests, r, 3)
+ call AddItemOutsidePopup(tests, r, 20)
+ endfor
+ " top and bottom in popup
+ for c in range(4, 19)
+ call AddItemInPopupBorder(tests, winid, 2, c)
+ call AddItemInPopupBorder(tests, winid, 3, c)
+ call AddItemInPopupBorder(tests, winid, 8, c)
+ call AddItemInPopupBorder(tests, winid, 9, c)
+ endfor
+ " left and right margin in popup
+ for r in range(2, 9)
+ call AddItemInPopupBorder(tests, winid, r, 4)
+ call AddItemInPopupBorder(tests, winid, r, 5)
+ call AddItemInPopupBorder(tests, winid, r, 18)
+ call AddItemInPopupBorder(tests, winid, r, 19)
+ endfor
+ " text "short"
+ call AddItemInPopupText(tests, winid, 4, 6, 1, 1)
+ call AddItemInPopupText(tests, winid, 4, 10, 1, 5)
+ call AddItemInPopupText(tests, winid, 4, 11, 1, 6)
+ call AddItemInPopupText(tests, winid, 4, 17, 1, 6)
+ " text "long line th"
+ call AddItemInPopupText(tests, winid, 5, 6, 2, 1)
+ call AddItemInPopupText(tests, winid, 5, 10, 2, 5)
+ call AddItemInPopupText(tests, winid, 5, 17, 2, 12)
+ " text "at will wrap"
+ call AddItemInPopupText(tests, winid, 6, 6, 2, 13)
+ call AddItemInPopupText(tests, winid, 6, 10, 2, 17)
+ call AddItemInPopupText(tests, winid, 6, 17, 2, 24)
+ " text "other"
+ call AddItemInPopupText(tests, winid, 7, 6, 3, 1)
+ call AddItemInPopupText(tests, winid, 7, 10, 3, 5)
+ call AddItemInPopupText(tests, winid, 7, 11, 3, 6)
+ call AddItemInPopupText(tests, winid, 7, 17, 3, 6)
- 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 assert_equal(winid, g:got_mouse_winid)
+ for item in tests
+ call test_setmouse(item.clickrow, item.clickcol)
+ call feedkeys("\<LeftMouse>", 'xt')
+ call assert_equal(item.result, g:got_mousepos)
+ endfor
call popup_close(winid)
+ enew!
delfunc MyPopupFilter
endfunc