]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0034: Window scrolls unexpectedly when 'scrollbind' is set v9.1.0034
authorChristian Brabandt <cb@256bit.org>
Tue, 16 Jan 2024 16:22:38 +0000 (17:22 +0100)
committerChristian Brabandt <cb@256bit.org>
Tue, 16 Jan 2024 16:22:38 +0000 (17:22 +0100)
Problem:  Window may unexpectedly scroll when 'scrollbind' is set
          and setting a buffer-local option using setbufvar()
          (Boris Staletic)
Solution: Save and restore the windows topline before opening the
          popup window.

fixes: #13863
closes: #13869

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/evalvars.c
src/testdir/test_popupwin.vim
src/version.c

index 8e42c5a307e403184ef191d699e6bb47c4bbf145..cbcf2a707ece39462f99642f1ef12d6ed20abc72 100644 (file)
@@ -4924,6 +4924,10 @@ f_setbufvar(typval_T *argvars, typval_T *rettv UNUSED)
     if (*varname == '&')
     {
        aco_save_T      aco;
+       // safe the current window position, it could
+       // change because of 'scrollbind' window-local
+       // options
+       linenr_T        old_topline = curwin->w_topline;
 
        // Set curbuf to be our buf, temporarily.
        aucmd_prepbuf(&aco, buf);
@@ -4935,6 +4939,7 @@ f_setbufvar(typval_T *argvars, typval_T *rettv UNUSED)
            // reset notion of buffer
            aucmd_restbuf(&aco);
        }
+       curwin->w_topline = old_topline;
     }
     else
     {
index c20ff48c6272b71c5fab406560104d0c881e31ad..a397f70752dd9b789a87da6f29e8d84edd72fe9f 100644 (file)
@@ -4215,4 +4215,22 @@ func Test_popup_close_callback_recursive()
   set maxfuncdepth&
 endfunc
 
+func Test_popupwin_setbufvar_changing_window_view()
+  " Test for Github Issue https://github.com/vim/vim/issues/13863
+  " using setbufvar(buf, '&option') should not scroll
+  " the current window
+  20new
+  call append(0, range(1, 25))
+  setlocal scrollbind
+  norm! G
+  let topline = winsaveview()['topline']
+  call setbufvar(winbufnr(popup_atcursor(['foobar'], {})), '&syntax', 'python')
+  " close popup
+  call popup_clear()
+  call assert_equal(topline, winsaveview()['topline'])
+
+  " clean up
+  bw!
+endfunc
+
 " vim: shiftwidth=2 sts=2
index 9f80e8276b007e1560dbd3bb0f1c3c8cf9ec4e57..425d609eb6679801fd5800c40af9cd1c38d61fc7 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    34,
 /**/
     33,
 /**/