mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.2.4555: getmousepos() returns the wrong column
Problem: getmousepos() returns the wrong column. (Ernie Rael) Solution: Limit to the text size, not the number of bytes.
This commit is contained in:
@@ -3099,17 +3099,14 @@ f_getmousepos(typval_T *argvars UNUSED, typval_T *rettv)
|
|||||||
col -= left_off;
|
col -= left_off;
|
||||||
if (row >= 0 && row < wp->w_height && col >= 0 && col < wp->w_width)
|
if (row >= 0 && row < wp->w_height && col >= 0 && col < wp->w_width)
|
||||||
{
|
{
|
||||||
char_u *p;
|
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
mouse_comp_pos(wp, &row, &col, &line, NULL);
|
mouse_comp_pos(wp, &row, &col, &line, NULL);
|
||||||
|
|
||||||
// limit to text length plus one
|
// limit to text size plus one
|
||||||
p = ml_get_buf(wp->w_buffer, line, FALSE);
|
count = linetabsize(ml_get_buf(wp->w_buffer, line, FALSE));
|
||||||
count = (int)STRLEN(p);
|
|
||||||
if (col > count)
|
if (col > count)
|
||||||
col = count;
|
col = count;
|
||||||
|
|
||||||
column = col + 1;
|
column = col + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2750,6 +2750,32 @@ func Test_getcurpos_setpos()
|
|||||||
call assert_equal([0, 0, 0, 0, 0], getcurpos(1999))
|
call assert_equal([0, 0, 0, 0, 0], getcurpos(1999))
|
||||||
endfunc
|
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()
|
" Test for glob()
|
||||||
func Test_glob()
|
func Test_glob()
|
||||||
call assert_equal('', glob(test_null_string()))
|
call assert_equal('', glob(test_null_string()))
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
4555,
|
||||||
/**/
|
/**/
|
||||||
4554,
|
4554,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user