]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.2177: Wrong cursor position when dragging out of window v9.0.2177
authorzeertzjq <zeertzjq@outlook.com>
Tue, 19 Dec 2023 19:28:31 +0000 (20:28 +0100)
committerChristian Brabandt <cb@256bit.org>
Tue, 19 Dec 2023 19:28:31 +0000 (20:28 +0100)
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 <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/mouse.c
src/testdir/test_visual.vim
src/version.c

index f895779ac56b9346d4918ae069b7c277c4f5e04d..b283c6479a5d4c8acdca2ace417809c457ce66c1 100644 (file)
@@ -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;
index 290641e1df71a7e3cddb0d240e0645d32b48bdcb..401a3504ae0473bad6bdc64addc1c8dd8c42ff77 100644 (file)
@@ -1585,6 +1585,41 @@ func Test_Visual_r_CTRL_C()
   call feedkeys("\<c-v>$gr\<c-c>", 'tx')
   call assert_equal(['\ 3\ 3\ 3'], 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 "\<LeftMouse>"
+  endfunc
+  func DragExpr(off)
+    call test_setmouse(1, getwininfo(win_getid())[0].wincol + a:off)
+    return "\<LeftDrag>"
+  endfunc
+
+  nnoremap <expr> <F2> ClickExpr(5)
+  nnoremap <expr> <F3> DragExpr(-1)
+  redraw
+  call feedkeys("\<F2>\<F3>\<LeftRelease>", 'tx')
+  call assert_equal([1, 6], [col('.'), col('v')])
+  call feedkeys("\<Esc>", 'tx')
+
+  nnoremap <expr> <F2> ClickExpr(6)
+  nnoremap <expr> <F3> DragExpr(-2)
+  redraw
+  call feedkeys("\<F2>\<F3>\<LeftRelease>", 'tx')
+  call assert_equal([1, 7], [col('.'), col('v')])
+  call feedkeys("\<Esc>", 'tx')
+
+  nunmap <F2>
+  nunmap <F3>
+  delfunc ClickExpr
+  delfunc DragExpr
+  set mouse&
+  bwipe!
+endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
index e65c2310cd3dd85e6923fa629229cc000469e584..b8dfc98a2ce0f46e0c4fe627251ec70fb503b398 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2177,
 /**/
     2176,
 /**/