Patch 8.2.4868
Problem:    When closing help window autocmds triggered for the wrong window.
Solution:   Figure out the new current window earlier. (closes #10348)
Files:      src/window.c, src/testdir/test_help.vim


*** ../vim-8.2.4867/src/window.c        2022-04-12 11:32:41.424327323 +0100
--- src/window.c        2022-05-04 22:08:03.494090593 +0100
***************
*** 57,62 ****
--- 57,63 ----
  static void clear_snapshot_rec(frame_T *fr);
  static int check_snapshot_rec(frame_T *sn, frame_T *fr);
  static win_T *restore_snapshot_rec(frame_T *sn, frame_T *fr);
+ static win_T *get_snapshot_curwin(int idx);
  
  static int frame_check_height(frame_T *topfrp, int height);
  static int frame_check_width(frame_T *topfrp, int width);
***************
*** 2667,2672 ****
--- 2668,2683 ----
      // the screen space.
      wp = win_free_mem(win, &dir, NULL);
  
+     if (help_window)
+     {
+       // Closing the help window moves the cursor back to the current window
+       // of the snapshot.
+       win_T *prev_win = get_snapshot_curwin(SNAP_HELP_IDX);
+ 
+       if (win_valid(prev_win))
+           wp = prev_win;
+     }
+ 
      // Make sure curwin isn't invalid.  It can cause severe trouble when
      // printing an error message.  For win_equal() curbuf needs to be valid
      // too.
***************
*** 6861,6866 ****
--- 6872,6911 ----
  }
  
  /*
+  * Traverse a snapshot to find the previous curwin.
+  */
+     static win_T *
+ get_snapshot_curwin_rec(frame_T *ft)
+ {
+     win_T     *wp;
+ 
+     if (ft->fr_next != NULL)
+     {
+       if ((wp = get_snapshot_curwin_rec(ft->fr_next)) != NULL)
+           return wp;
+     }
+     if (ft->fr_child != NULL)
+     {
+       if ((wp = get_snapshot_curwin_rec(ft->fr_child)) != NULL)
+           return wp;
+     }
+ 
+     return ft->fr_win;
+ }
+ 
+ /*
+  * Return the current window stored in the snapshot or NULL.
+  */
+     static win_T *
+ get_snapshot_curwin(int idx)
+ {
+     if (curtab->tp_snapshot[idx] == NULL)
+       return NULL;
+ 
+     return get_snapshot_curwin_rec(curtab->tp_snapshot[idx]);
+ }
+ 
+ /*
   * Restore a previously created snapshot, if there is any.
   * This is only done if the screen size didn't change and the window layout is
   * still the same.
*** ../vim-8.2.4867/src/testdir/test_help.vim   2022-03-02 20:49:43.472155195 
+0000
--- src/testdir/test_help.vim   2022-05-04 22:04:47.222198147 +0100
***************
*** 12,17 ****
--- 12,41 ----
    helpclose
  endfunc
  
+ func Test_help_restore_snapshot_split()
+   " Squeeze the unnamed buffer, Xfoo and the help one side-by-side and focus
+   " the first one before calling :help.
+   let bnr = bufnr()
+   botright vsp Xfoo
+   wincmd h
+   help
+   wincmd L
+   let g:did_bufenter = v:false
+   augroup T
+     au!
+     au BufEnter Xfoo let g:did_bufenter = v:true
+   augroup END
+   helpclose
+   augroup! T
+   " We're back to the unnamed buffer.
+   call assert_equal(bnr, bufnr())
+   " No BufEnter was triggered for Xfoo.
+   call assert_equal(v:false, g:did_bufenter)
+ 
+   close!
+   bwipe!
+ endfunc
+ 
  func Test_help_errors()
    call assert_fails('help doesnotexist', 'E149:')
    call assert_fails('help!', 'E478:')
*** ../vim-8.2.4867/src/version.c       2022-05-04 18:51:38.178683646 +0100
--- src/version.c       2022-05-04 22:02:37.782269110 +0100
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     4868,
  /**/

-- 
Common sense is what tells you that the world is flat.

 /// 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/20220504211437.7A7221C19BB%40moolenaar.net.

Raspunde prin e-mail lui