Patch 9.0.0915
Problem:    WinScrolled may trigger immediately when defined.
Solution:   Initialize the fields in all windows. (closes #11582)
Files:      src/autocmd.c, src/window.c, src/proto/window.pro,
            src/testdir/test_autocmd.vim,
            src/testdir/dumps/Test_winscrolled_not_when_defined_1.dump,
            src/testdir/dumps/Test_winscrolled_not_when_defined_2.dump


*** ../vim-9.0.0914/src/autocmd.c       2022-11-13 17:53:42.283417583 +0000
--- src/autocmd.c       2022-11-20 12:10:13.844729626 +0000
***************
*** 1264,1277 ****
                    get_mode(last_mode);
  #endif
                // Initialize the fields checked by the WinScrolled trigger to
!               // stop it from firing right after the first autocmd is defined.
                if (event == EVENT_WINSCROLLED && !has_winscrolled())
                {
!                   curwin->w_last_topline = curwin->w_topline;
!                   curwin->w_last_leftcol = curwin->w_leftcol;
!                   curwin->w_last_skipcol = curwin->w_skipcol;
!                   curwin->w_last_width = curwin->w_width;
!                   curwin->w_last_height = curwin->w_height;
                }
  
                if (is_buflocal)
--- 1264,1283 ----
                    get_mode(last_mode);
  #endif
                // Initialize the fields checked by the WinScrolled trigger to
!               // prevent it from firing right after the first autocmd is
!               // defined.
                if (event == EVENT_WINSCROLLED && !has_winscrolled())
                {
!                   tabpage_T *save_curtab = curtab;
!                   tabpage_T *tp;
!                   FOR_ALL_TABPAGES(tp)
!                   {
!                       unuse_tabpage(curtab);
!                       use_tabpage(tp);
!                       snapshot_windows_scroll_size();
!                   }
!                   unuse_tabpage(curtab);
!                   use_tabpage(save_curtab);
                }
  
                if (is_buflocal)
*** ../vim-9.0.0914/src/window.c        2022-11-19 21:17:48.841226535 +0000
--- src/window.c        2022-11-20 12:01:47.440641805 +0000
***************
*** 2846,2852 ****
   * Make a snapshot of all the window scroll positions and sizes of the current
   * tab page.
   */
!     static void
  snapshot_windows_scroll_size(void)
  {
      win_T *wp;
--- 2846,2852 ----
   * Make a snapshot of all the window scroll positions and sizes of the current
   * tab page.
   */
!     void
  snapshot_windows_scroll_size(void)
  {
      win_T *wp;
***************
*** 3864,3869 ****
--- 3864,3896 ----
  }
  
  /*
+  * Store the relevant window pointers for tab page "tp".  To be used before
+  * use_tabpage().
+  */
+     void
+ unuse_tabpage(tabpage_T *tp)
+ {
+     tp->tp_topframe = topframe;
+     tp->tp_firstwin = firstwin;
+     tp->tp_lastwin = lastwin;
+     tp->tp_curwin = curwin;
+ }
+ 
+ /*
+  * Set the relevant pointers to use tab page "tp".  May want to call
+  * unuse_tabpage() first.
+  */
+     void
+ use_tabpage(tabpage_T *tp)
+ {
+     curtab = tp;
+     topframe = curtab->tp_topframe;
+     firstwin = curtab->tp_firstwin;
+     lastwin = curtab->tp_lastwin;
+     curwin = curtab->tp_curwin;
+ }
+ 
+ /*
   * Allocate the first window and put an empty buffer in it.
   * Called from main().
   * Return FAIL when something goes wrong (out of memory).
***************
*** 3877,3887 ****
      first_tabpage = alloc_tabpage();
      if (first_tabpage == NULL)
        return FAIL;
-     first_tabpage->tp_topframe = topframe;
      curtab = first_tabpage;
!     curtab->tp_firstwin = firstwin;
!     curtab->tp_lastwin = lastwin;
!     curtab->tp_curwin = curwin;
  
      return OK;
  }
--- 3904,3911 ----
      first_tabpage = alloc_tabpage();
      if (first_tabpage == NULL)
        return FAIL;
      curtab = first_tabpage;
!     unuse_tabpage(first_tabpage);
  
      return OK;
  }
***************
*** 4389,4398 ****
      win_T     *next_prevwin = tp->tp_prevwin;
      tabpage_T *last_tab = curtab;
  
!     curtab = tp;
!     firstwin = tp->tp_firstwin;
!     lastwin = tp->tp_lastwin;
!     topframe = tp->tp_topframe;
  
      // We would like doing the TabEnter event first, but we don't have a
      // valid current window yet, which may break some commands.
--- 4413,4419 ----
      win_T     *next_prevwin = tp->tp_prevwin;
      tabpage_T *last_tab = curtab;
  
!     use_tabpage(tp);
  
      // We would like doing the TabEnter event first, but we don't have a
      // valid current window yet, which may break some commands.
*** ../vim-9.0.0914/src/proto/window.pro        2022-11-19 21:17:48.841226535 
+0000
--- src/proto/window.pro        2022-11-20 11:53:02.444550244 +0000
***************
*** 18,29 ****
--- 18,32 ----
  void close_windows(buf_T *buf, int keep_curwin);
  int one_window(void);
  int win_close(win_T *win, int free_buf);
+ void snapshot_windows_scroll_size(void);
  void may_make_initial_scroll_size_snapshot(void);
  void may_trigger_winscrolled(void);
  void win_close_othertab(win_T *win, int free_buf, tabpage_T *tp);
  void win_free_all(void);
  win_T *winframe_remove(win_T *win, int *dirp, tabpage_T *tp);
  void close_others(int message, int forceit);
+ void unuse_tabpage(tabpage_T *tp);
+ void use_tabpage(tabpage_T *tp);
  int win_alloc_first(void);
  win_T *win_alloc_popup_win(void);
  void win_init_popup_win(win_T *wp, buf_T *buf);
*** ../vim-9.0.0914/src/testdir/test_autocmd.vim        2022-11-19 
21:17:48.841226535 +0000
--- src/testdir/test_autocmd.vim        2022-11-20 12:08:33.392712207 +0000
***************
*** 439,444 ****
--- 439,470 ----
    call StopVimInTerminal(buf)
  endfunc
  
+ " Check that WinScrolled is not triggered immediately when defined and there
+ " are split windows.
+ func Test_WinScrolled_not_when_defined()
+   CheckRunVimInTerminal
+ 
+   let lines =<< trim END
+       call setline(1, ['aaa', 'bbb'])
+       echo 'nothing happened'
+       func ShowTriggered(id)
+         echo 'triggered'
+       endfunc
+   END
+   call writefile(lines, 'Xtest_winscrolled_not', 'D')
+   let buf = RunVimInTerminal('-S Xtest_winscrolled_not', #{rows: 10, cols: 
60, statusoff: 2})
+   call term_sendkeys(buf, ":split\<CR>")
+   call TermWait(buf)
+   " use a timer to show the message after redrawing
+   call term_sendkeys(buf, ":au WinScrolled * call timer_start(100, 
'ShowTriggered')\<CR>")
+   call VerifyScreenDump(buf, 'Test_winscrolled_not_when_defined_1', {})
+ 
+   call term_sendkeys(buf, "\<C-E>")
+   call VerifyScreenDump(buf, 'Test_winscrolled_not_when_defined_2', {})
+ 
+   call StopVimInTerminal(buf)
+ endfunc
+ 
  func Test_WinScrolled_long_wrapped()
    CheckRunVimInTerminal
  
*** ../vim-9.0.0914/src/testdir/dumps/Test_winscrolled_not_when_defined_1.dump  
2022-11-20 12:09:51.876725807 +0000
--- src/testdir/dumps/Test_winscrolled_not_when_defined_1.dump  2022-11-20 
12:07:27.268700746 +0000
***************
*** 0 ****
--- 1,10 ----
+ >a+0&#ffffff0@2| @56
+ |b@2| @56
+ |~+0#4040ff13&| @58
+ |~| @58
+ |[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @28|1|,|1| @11|A|l@1
+ |a+0&&@2| @56
+ |b@2| @56
+ |~+0#4040ff13&| @58
+ |[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @28|1|,|1| @11|A|l@1
+ |:+0&&|a|u| |W|i|n|S|c|r|o|l@1|e|d| |*| |c|a|l@1| 
|t|i|m|e|r|_|s|t|a|r|t|(|1|0@1|,| |'|S|h|o|w|T|r|i|g@1|e|r|e|d|'|)| @3
*** ../vim-9.0.0914/src/testdir/dumps/Test_winscrolled_not_when_defined_2.dump  
2022-11-20 12:09:51.880725806 +0000
--- src/testdir/dumps/Test_winscrolled_not_when_defined_2.dump  2022-11-20 
12:08:38.124713026 +0000
***************
*** 0 ****
--- 1,10 ----
+ >b+0&#ffffff0@2| @56
+ |~+0#4040ff13&| @58
+ |~| @58
+ |~| @58
+ |[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @28|2|,|1| @11|B|o|t
+ |a+0&&@2| @56
+ |b@2| @56
+ |~+0#4040ff13&| @58
+ |[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @28|1|,|1| @11|A|l@1
+ |t+0&&|r|i|g@1|e|r|e|d| @50
*** ../vim-9.0.0914/src/version.c       2022-11-20 11:13:12.120192315 +0000
--- src/version.c       2022-11-20 12:03:13.576656751 +0000
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     915,
  /**/

-- 
>From "know your smileys":
 :-| :-|   Deja' vu!

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20221120121222.9AAE21C12B9%40moolenaar.net.

Raspunde prin e-mail lui