]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1983: scrolling inactive window not possible with cursorbind v9.0.1983
authorzeertzjq <zeertzjq@outlook.com>
Wed, 4 Oct 2023 19:45:33 +0000 (21:45 +0200)
committerChristian Brabandt <cb@256bit.org>
Wed, 4 Oct 2023 19:45:33 +0000 (21:45 +0200)
Problem:  Scrolling non-current window using mouse is inconsistent
          depending on 'scrollbind'/'scrolloff' and different from GUI
          vertical scrollbar when 'cursorbind' is set.
Solution: Don't move cursor in non-current windows for 'cursorbind' if
          cursor in the current window didn't move.

closes: #13219
closes: #13210

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
src/move.c
src/testdir/test_scroll_opt.vim
src/version.c

index e5309df486a428d12c3d6f19ecab4f57c583f69e..46e4f358dcb6bfac6ca3d26a74b280baa5097d21 100644 (file)
@@ -3571,6 +3571,14 @@ halfpage(int flag, linenr_T Prenum)
     void
 do_check_cursorbind(void)
 {
+    static win_T       *prev_curwin = NULL;
+    static pos_T       prev_cursor = {0, 0, 0};
+
+    if (curwin == prev_curwin && EQUAL_POS(curwin->w_cursor, prev_cursor))
+       return;
+    prev_curwin = curwin;
+    prev_cursor = curwin->w_cursor;
+
     linenr_T   line = curwin->w_cursor.lnum;
     colnr_T    col = curwin->w_cursor.col;
     colnr_T    coladd = curwin->w_cursor.coladd;
index 81670cdd7a614e6823454b4f35e16bb496b23662..005e45bb5934eb9d58f22c23859f4335748f7056 100644 (file)
@@ -1,4 +1,4 @@
-" Test for reset 'scroll' and 'smoothscroll'
+" Test for 'scroll', 'scrolloff', 'smoothscroll', etc.
 
 source check.vim
 source screendump.vim
@@ -39,20 +39,74 @@ func Test_reset_scroll()
 endfunc
 
 func Test_scolloff_even_line_count()
-   new
-   resize 6
-   setlocal scrolloff=3
-   call setline(1, range(20))
-   normal 2j
-   call assert_equal(1, getwininfo(win_getid())[0].topline)
-   normal j
-   call assert_equal(1, getwininfo(win_getid())[0].topline)
-   normal j
-   call assert_equal(2, getwininfo(win_getid())[0].topline)
-   normal j
-   call assert_equal(3, getwininfo(win_getid())[0].topline)
-
-   bwipe!
+  new
+  resize 6
+  setlocal scrolloff=3
+  call setline(1, range(20))
+  normal 2j
+  call assert_equal(1, getwininfo(win_getid())[0].topline)
+  normal j
+  call assert_equal(1, getwininfo(win_getid())[0].topline)
+  normal j
+  call assert_equal(2, getwininfo(win_getid())[0].topline)
+  normal j
+  call assert_equal(3, getwininfo(win_getid())[0].topline)
+
+  bwipe!
+endfunc
+
+func Test_mouse_scroll_inactive_with_cursorbind()
+  for scb in [0, 1]
+    for so in [0, 1, 2]
+      let msg = $'scb={scb} so={so}'
+
+      new | only
+      let w1 = win_getid()
+      setlocal cursorbind
+      let &l:scb = scb
+      let &l:so = so
+      call setline(1, range(101, 109))
+      rightbelow vnew
+      let w2 = win_getid()
+      setlocal cursorbind
+      let &l:scb = scb
+      let &l:so = so
+      call setline(1, range(101, 109))
+
+      normal! $
+      call assert_equal(3, col('.', w1), msg)
+      call assert_equal(3, col('.', w2), msg)
+      call test_setmouse(1, 1)
+      call feedkeys("\<ScrollWheelDown>", 'xt')
+      call assert_equal(4, line('w0', w1), msg)
+      call assert_equal(4 + so, line('.', w1), msg)
+      call assert_equal(1, line('w0', w2), msg)
+      call assert_equal(1, line('.', w2), msg)
+      call feedkeys("\<ScrollWheelDown>", 'xt')
+      call assert_equal(7, line('w0', w1), msg)
+      call assert_equal(7 + so, line('.', w1), msg)
+      call assert_equal(1, line('w0', w2), msg)
+      call assert_equal(1, line('.', w2), msg)
+      call feedkeys("\<ScrollWheelUp>", 'xt')
+      call assert_equal(4, line('w0', w1), msg)
+      call assert_equal(7 + so, line('.', w1), msg)
+      call assert_equal(1, line('w0', w2), msg)
+      call assert_equal(1, line('.', w2), msg)
+      call feedkeys("\<ScrollWheelUp>", 'xt')
+      call assert_equal(1, line('w0', w1), msg)
+      call assert_equal(7 + so, line('.', w1), msg)
+      call assert_equal(1, line('w0', w2), msg)
+      call assert_equal(1, line('.', w2), msg)
+      normal! 0
+      call assert_equal(1, line('.', w1), msg)
+      call assert_equal(1, col('.', w1), msg)
+      call assert_equal(1, line('.', w2), msg)
+      call assert_equal(1, col('.', w2), msg)
+
+      bwipe!
+      bwipe!
+    endfor
+  endfor
 endfunc
 
 func Test_CtrlE_CtrlY_stop_at_end()
index 7fdb1e621d96502de4ef15b07056879d637b4ad1..32005545f3d27807855d1b5f90fce38ac6a19f88 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1983,
 /**/
     1982,
 /**/