Skip to content

Commit

Permalink
patch 9.0.0177: cursor position wrong with 'virtualedit' and mouse click
Browse files Browse the repository at this point in the history
Problem:    Cursor position wrong with 'virtualedit' and mouse click after end
            of the line. (Hermann Mayer)
Solution:   Do not use ScreenCols[] when 'virtualedit' is active.
            (closes #10868)
  • Loading branch information
brammool committed Aug 9, 2022
1 parent 8ca29b6 commit 8f49e69
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1967,7 +1967,8 @@ jump_to_mouse(

// Only use ScreenCols[] after the window was redrawn. Mainly matters
// for tests, a user would not click before redrawing.
if (curwin->w_redr_type <= VALID_NO_UPDATE)
// Do not use when 'virtualedit' is active.
if (curwin->w_redr_type <= VALID_NO_UPDATE && !virtual_active())
col_from_screen = ScreenCols[off];
#ifdef FEAT_FOLDING
// Remember the character under the mouse, it might be a '-' or '+' in
Expand Down
35 changes: 35 additions & 0 deletions src/testdir/test_virtualedit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -537,4 +537,39 @@ func Test_global_local_virtualedit()
set virtualedit&
endfunc

func Test_virtualedit_mouse()
let save_mouse = &mouse
set mouse=a
set virtualedit=all
new

call setline(1, ["text\tword"])
redraw
call test_setmouse(1, 4)
call feedkeys("\<LeftMouse>", "xt")
call assert_equal([0, 1, 4, 0, 4], getcurpos())
call test_setmouse(1, 5)
call feedkeys("\<LeftMouse>", "xt")
call assert_equal([0, 1, 5, 0, 5], getcurpos())
call test_setmouse(1, 6)
call feedkeys("\<LeftMouse>", "xt")
call assert_equal([0, 1, 5, 1, 6], getcurpos())
call test_setmouse(1, 7)
call feedkeys("\<LeftMouse>", "xt")
call assert_equal([0, 1, 5, 2, 7], getcurpos())
call test_setmouse(1, 8)
call feedkeys("\<LeftMouse>", "xt")
call assert_equal([0, 1, 5, 3, 8], getcurpos())
call test_setmouse(1, 9)
call feedkeys("\<LeftMouse>", "xt")
call assert_equal([0, 1, 6, 0, 9], getcurpos())
call test_setmouse(1, 15)
call feedkeys("\<LeftMouse>", "xt")
call assert_equal([0, 1, 10, 2, 15], getcurpos())

bwipe!
let &mouse = save_mouse
set virtualedit&
endfunc

" vim: shiftwidth=2 sts=2 expandtab
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
177,
/**/
176,
/**/
Expand Down

0 comments on commit 8f49e69

Please sign in to comment.