diff options
-rw-r--r-- | src/nvim/eval/funcs.c | 5 | ||||
-rw-r--r-- | src/nvim/testdir/test_functions.vim | 27 |
2 files changed, 29 insertions, 3 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index edb254e15f..738ed7f85e 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -3753,9 +3753,8 @@ static void f_getmousepos(typval_T *argvars, typval_T *rettv, FunPtr fptr) winrow = row + 1 + wp->w_border_adj[0]; // Adjust by 1 for top border wincol = col + 1 + wp->w_border_adj[3]; // Adjust by 1 for left border if (row >= 0 && row < wp->w_height && col >= 0 && col < wp->w_width) { - if (!mouse_comp_pos(wp, &row, &col, &lnum)) { - col = vcol2col(wp, lnum, col); - } + (void)mouse_comp_pos(wp, &row, &col, &lnum); + col = vcol2col(wp, lnum, col); column = col + 1; } } diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index d83606882c..c2b5653a29 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1801,6 +1801,33 @@ func Test_getmousepos() \ line: 1, \ column: 8, \ }, getmousepos()) + + " If the mouse is positioned past the last buffer line, "line" and "column" + " should act like it's positioned on the last buffer line. + " call test_setmouse(2, 25) + call nvim_input_mouse('left', 'press', '', 0, 1, 24) + call getchar() " wait for and consume the mouse press + call assert_equal(#{ + \ screenrow: 2, + \ screencol: 25, + \ winid: win_getid(), + \ winrow: 2, + \ wincol: 25, + \ line: 1, + \ column: 4, + \ }, getmousepos()) + " call test_setmouse(2, 50) + call nvim_input_mouse('left', 'press', '', 0, 1, 49) + call getchar() " wait for and consume the mouse press + call assert_equal(#{ + \ screenrow: 2, + \ screencol: 50, + \ winid: win_getid(), + \ winrow: 2, + \ wincol: 50, + \ line: 1, + \ column: 8, + \ }, getmousepos()) bwipe! endfunc |