]> granicus.if.org Git - vim/commitdiff
patch 8.2.4555: getmousepos() returns the wrong column v8.2.4555
authorBram Moolenaar <Bram@vim.org>
Sun, 13 Mar 2022 12:06:07 +0000 (12:06 +0000)
committerBram Moolenaar <Bram@vim.org>
Sun, 13 Mar 2022 12:06:07 +0000 (12:06 +0000)
Problem:    getmousepos() returns the wrong column. (Ernie Rael)
Solution:   Limit to the text size, not the number of bytes.

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

index 6a32cac9d0b06c314d2763e8bf9994b834be064c..a094df6bbbf05f74d5e1c5b9d22555cd4cb1e15c 100644 (file)
@@ -3099,17 +3099,14 @@ 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)
            {
-               char_u  *p;
                int     count;
 
                mouse_comp_pos(wp, &row, &col, &line, NULL);
 
-               // limit to text length plus one
-               p = ml_get_buf(wp->w_buffer, line, FALSE);
-               count = (int)STRLEN(p);
+               // limit to text size plus one
+               count = linetabsize(ml_get_buf(wp->w_buffer, line, FALSE));
                if (col > count)
                    col = count;
-
                column = col + 1;
            }
        }
index e22a0c6ba4c49b89deb46d79ac98401a8d7da23e..ce868c20a6816c0e93be54b2a4f24c02aa1a26d7 100644 (file)
@@ -2750,6 +2750,32 @@ func Test_getcurpos_setpos()
   call assert_equal([0, 0, 0, 0, 0], getcurpos(1999))
 endfunc
 
+func Test_getmousepos()
+  enew!
+  call setline(1, "\t\t\t1234")
+  call test_setmouse(1, 25)
+  call assert_equal(#{
+        \ screenrow: 1,
+        \ screencol: 25,
+        \ winid: win_getid(),
+        \ winrow: 1,
+        \ wincol: 25,
+        \ line: 1,
+        \ column: 25,
+        \ }, getmousepos())
+  call test_setmouse(1, 50)
+  call assert_equal(#{
+        \ screenrow: 1,
+        \ screencol: 50,
+        \ winid: win_getid(),
+        \ winrow: 1,
+        \ wincol: 50,
+        \ line: 1,
+        \ column: 29,
+        \ }, getmousepos())
+  bwipe!
+endfunc
+
 " Test for glob()
 func Test_glob()
   call assert_equal('', glob(test_null_string()))
index bdd9dd8f3539c2426f18f1e010a5d0417407b6bb..20b5a03a3c0adc6727304042d01868dbd2a41133 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4555,
 /**/
     4554,
 /**/