]> granicus.if.org Git - vim/commitdiff
patch 8.2.4568: getmousepos() does not compute the column below the last line v8.2.4568
authorSean Dewar <seandewar@users.noreply.github.com>
Tue, 15 Mar 2022 09:46:54 +0000 (09:46 +0000)
committerBram Moolenaar <Bram@vim.org>
Tue, 15 Mar 2022 09:46:54 +0000 (09:46 +0000)
Problem:    getmousepos() does not compute the column below the last line.
Solution:   Also compute the column when the mouse is below the last line.
            (Sean Dewar, closes #9946)

src/mouse.c
src/testdir/test_functions.vim
src/version.c

index 25d6fa89a1c9404c4754ca60abeda183ba77183c..ffbe84219f4540960f31f6e4f419bbd86a6730dc 100644 (file)
@@ -3099,8 +3099,8 @@ f_getmousepos(typval_T *argvars UNUSED, typval_T *rettv)
            col -= left_off;
            if (row >= 0 && row < wp->w_height && col >= 0 && col < wp->w_width)
            {
-               if (!mouse_comp_pos(wp, &row, &col, &lnum, NULL))
-                   col = vcol2col(wp, lnum, col);
+               (void)mouse_comp_pos(wp, &row, &col, &lnum, NULL);
+               col = vcol2col(wp, lnum, col);
                column = col + 1;
            }
        }
index d97522a37d20518d31612391fb351da75e0354f0..fddf4aeb6393e5348c8aafa3d860811f548f0eae 100644 (file)
@@ -2783,6 +2783,29 @@ 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 assert_equal(#{
+        \ screenrow: 2,
+        \ screencol: 25,
+        \ winid: win_getid(),
+        \ winrow: 2,
+        \ wincol: 25,
+        \ line: 1,
+        \ column: 4,
+        \ }, getmousepos())
+  call test_setmouse(2, 50)
+  call assert_equal(#{
+        \ screenrow: 2,
+        \ screencol: 50,
+        \ winid: win_getid(),
+        \ winrow: 2,
+        \ wincol: 50,
+        \ line: 1,
+        \ column: 8,
+        \ }, getmousepos())
   bwipe!
 endfunc
 
index 4a4aa75fea09772f5f89782c20af922208d85d72..c4a65f3414c271613d2fca925ef219492891f10e 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4568,
 /**/
     4567,
 /**/