Re: Patch 8.2.4555 (getmousepos)
On 3/13/22 8:51 AM, Bram Moolenaar wrote: Ernie Rael wrote: 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 :MyClick command! -nargs=0 MyClick Click() Hmm, reading the help text for getmousepos() again, it looks like the intention for "column" was to actually get the byte index of where the mouse is. But it currently is set to the screen column. And then it was limited to the number of bytes, which doesn't work. I fixed that last problem, but that goes against what the help says. I can change it to return the byte index, which will make it work for you. It is not backwards compatible, but considering that it was not returning the correct value, I doubt that someone depended on it. Works ok now. There was probably use of column when screencol or wincol was intended, so there might be issues... -- -- 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 vim_dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/560d3974-dc82-7cca-c5a7-69c4e34af606%40raelity.com.
Re: Patch 8.2.4555 (getmousepos)
Ernie Rael wrote: > 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 :MyClick > command! -nargs=0 MyClick Click() Hmm, reading the help text for getmousepos() again, it looks like the intention for "column" was to actually get the byte index of where the mouse is. But it currently is set to the screen column. And then it was limited to the number of bytes, which doesn't work. I fixed that last problem, but that goes against what the help says. I can change it to return the byte index, which will make it work for you. It is not backwards compatible, but considering that it was not returning the correct value, I doubt that someone depended on it. -- hundred-and-one symptoms of being an internet addict: 250. You've given up the search for the "perfect woman" and instead, sit in front of the PC until you're just too tired to care. /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\help me help AIDS victims -- http://ICCF-Holland.org/// -- -- 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 vim_dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/20220313155150.D3C511C79E4%40moolenaar.net.
Re: Patch 8.2.4555 (getmousepos)
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 :MyClick 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 + --- src/mouse.c 2022-03-13 11:54:16.919648342 + *** *** 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, , , , 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, , , , 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 + --- src/testdir/test_functions.vim 2022-03-13 12:02:00.249657121 + *** *** 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 + --- src/version.c 2022-03-13 12:00:39.170223010 + *** *** 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 vim_dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/525474ce-cdc8-52c2-4a95-1b70cb8f0bef%40raelity.com.