# HG changeset patch # User Christian Brabandt # Date 1703014209 -3600 # Node ID 63341afcd32969e974e816d63d4a57d14de53c08 # Parent 00a926acf8d7e78259864b73ef1496cac9c93d44 patch 9.0.2177: Wrong cursor position when dragging out of window Commit: https://github.com/vim/vim/commit/ec14924368e23f2430815c009bd554f88de9c57f Author: zeertzjq Date: Tue Dec 19 20:28:31 2023 +0100 patch 9.0.2177: Wrong cursor position when dragging out of window Problem: Wrong cursor position when dragging out of window. Solution: Don't use ScreenCols[] when mouse is not in current window. closes: #13717 Signed-off-by: zeertzjq Signed-off-by: Christian Brabandt diff --git a/src/mouse.c b/src/mouse.c --- a/src/mouse.c +++ b/src/mouse.c @@ -2050,7 +2050,9 @@ retnomove: } } - if (prev_row >= 0 && prev_row < Rows && prev_col >= 0 && prev_col <= Columns + if (prev_row >= W_WINROW(curwin) + && prev_row < W_WINROW(curwin) + curwin->w_height + && prev_col >= curwin->w_wincol && prev_col < W_ENDCOL(curwin) && ScreenLines != NULL) { int off = LineOffset[prev_row] + prev_col; diff --git a/src/testdir/test_visual.vim b/src/testdir/test_visual.vim --- a/src/testdir/test_visual.vim +++ b/src/testdir/test_visual.vim @@ -1585,6 +1585,41 @@ func Test_Visual_r_CTRL_C() call feedkeys("\$gr\", 'tx') call assert_equal([''], getline(1, 1)) bw! -endfu +endfunc + +func Test_visual_drag_out_of_window() + rightbelow vnew + call setline(1, '123456789') + set mouse=a + func ClickExpr(off) + call test_setmouse(1, getwininfo(win_getid())[0].wincol + a:off) + return "\" + endfunc + func DragExpr(off) + call test_setmouse(1, getwininfo(win_getid())[0].wincol + a:off) + return "\" + endfunc + + nnoremap ClickExpr(5) + nnoremap DragExpr(-1) + redraw + call feedkeys("\\\", 'tx') + call assert_equal([1, 6], [col('.'), col('v')]) + call feedkeys("\", 'tx') + + nnoremap ClickExpr(6) + nnoremap DragExpr(-2) + redraw + call feedkeys("\\\", 'tx') + call assert_equal([1, 7], [col('.'), col('v')]) + call feedkeys("\", 'tx') + + nunmap + nunmap + delfunc ClickExpr + delfunc DragExpr + set mouse& + bwipe! +endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -705,6 +705,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2177, +/**/ 2176, /**/ 2175,