The problem persists: Included patches: 1-4557.
The problem seems to be that tabs are not taken into account when
calculating column.
With the line, like listmode, starts with 3 tabs
^I^I^Ix
click on the x and getmousepos return column 25
but with the cursor on 'x' "getpos('.')" returns 4
My goal is to intercept a mouse click, if it is in a special area, want
to do something special, otherwise set the cursor position to where
there there was a click, like default behavior.
def Click()
var d = getmousepos()
echo d['column']
win_gotoid(d['winid'])
cursor(d['line'], d['column'])
enddef
nnoremap <LeftMouse> :MyClick<CR>
command! -nargs=0 MyClick Click()
-ernie
On 3/13/22 5:08 AM, Bram Moolenaar wrote:
Patch 8.2.4555
Problem: getmousepos() returns the wrong column. (Ernie Rael)
Solution: Limit to the text size, not the number of bytes.
Files: src/mouse.c, src/testdir/test_functions.vim
*** ../vim-8.2.4554/src/mouse.c 2021-11-29 17:37:38.063265208 +0000
--- src/mouse.c 2022-03-13 11:54:16.919648342 +0000
***************
*** 3099,3115 ****
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);
if (col > count)
col = count;
-
column = col + 1;
}
}
--- 3099,3112 ----
col -= left_off;
if (row >= 0 && row < wp->w_height && col >= 0 && col < wp->w_width)
{
int count;
mouse_comp_pos(wp, &row, &col, &line, NULL);
! // limit to text size plus one
! count = linetabsize(ml_get_buf(wp->w_buffer, line, FALSE));
if (col > count)
col = count;
column = col + 1;
}
}
*** ../vim-8.2.4554/src/testdir/test_functions.vim 2022-02-20
19:05:06.359955597 +0000
--- src/testdir/test_functions.vim 2022-03-13 12:02:00.249657121 +0000
***************
*** 2750,2755 ****
--- 2750,2781 ----
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()))
*** ../vim-8.2.4554/src/version.c 2022-03-12 21:28:18.532257720 +0000
--- src/version.c 2022-03-13 12:00:39.170223010 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4555,
/**/
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/525474ce-cdc8-52c2-4a95-1b70cb8f0bef%40raelity.com.