comparison src/window.c @ 28688:264fa41e6704 v8.2.4868

patch 8.2.4868: when closing help window autocmds triggered for wrong window Commit: https://github.com/vim/vim/commit/2a2707d03337d0bb7d5fd1770238809618653d4a Author: LemonBoy <thatlemon@gmail.com> Date: Wed May 4 22:13:47 2022 +0100 patch 8.2.4868: when closing help window autocmds triggered for wrong window Problem: When closing help window autocmds triggered for the wrong window. Solution: Figure out the new current window earlier. (closes https://github.com/vim/vim/issues/10348)
author Bram Moolenaar <Bram@vim.org>
date Wed, 04 May 2022 23:15:02 +0200
parents aa9720c76412
children d770568e6c98
comparison
equal deleted inserted replaced
28687:b7aa8a9e166a 28688:264fa41e6704
55 static void make_snapshot_rec(frame_T *fr, frame_T **frp); 55 static void make_snapshot_rec(frame_T *fr, frame_T **frp);
56 static void clear_snapshot(tabpage_T *tp, int idx); 56 static void clear_snapshot(tabpage_T *tp, int idx);
57 static void clear_snapshot_rec(frame_T *fr); 57 static void clear_snapshot_rec(frame_T *fr);
58 static int check_snapshot_rec(frame_T *sn, frame_T *fr); 58 static int check_snapshot_rec(frame_T *sn, frame_T *fr);
59 static win_T *restore_snapshot_rec(frame_T *sn, frame_T *fr); 59 static win_T *restore_snapshot_rec(frame_T *sn, frame_T *fr);
60 static win_T *get_snapshot_curwin(int idx);
60 61
61 static int frame_check_height(frame_T *topfrp, int height); 62 static int frame_check_height(frame_T *topfrp, int height);
62 static int frame_check_width(frame_T *topfrp, int width); 63 static int frame_check_width(frame_T *topfrp, int width);
63 64
64 static win_T *win_alloc(win_T *after, int hidden); 65 static win_T *win_alloc(win_T *after, int hidden);
2665 2666
2666 // Free the memory used for the window and get the window that received 2667 // Free the memory used for the window and get the window that received
2667 // the screen space. 2668 // the screen space.
2668 wp = win_free_mem(win, &dir, NULL); 2669 wp = win_free_mem(win, &dir, NULL);
2669 2670
2671 if (help_window)
2672 {
2673 // Closing the help window moves the cursor back to the current window
2674 // of the snapshot.
2675 win_T *prev_win = get_snapshot_curwin(SNAP_HELP_IDX);
2676
2677 if (win_valid(prev_win))
2678 wp = prev_win;
2679 }
2680
2670 // Make sure curwin isn't invalid. It can cause severe trouble when 2681 // Make sure curwin isn't invalid. It can cause severe trouble when
2671 // printing an error message. For win_equal() curbuf needs to be valid 2682 // printing an error message. For win_equal() curbuf needs to be valid
2672 // too. 2683 // too.
2673 if (win == curwin) 2684 if (win == curwin)
2674 { 2685 {
6859 vim_free(fr); 6870 vim_free(fr);
6860 } 6871 }
6861 } 6872 }
6862 6873
6863 /* 6874 /*
6875 * Traverse a snapshot to find the previous curwin.
6876 */
6877 static win_T *
6878 get_snapshot_curwin_rec(frame_T *ft)
6879 {
6880 win_T *wp;
6881
6882 if (ft->fr_next != NULL)
6883 {
6884 if ((wp = get_snapshot_curwin_rec(ft->fr_next)) != NULL)
6885 return wp;
6886 }
6887 if (ft->fr_child != NULL)
6888 {
6889 if ((wp = get_snapshot_curwin_rec(ft->fr_child)) != NULL)
6890 return wp;
6891 }
6892
6893 return ft->fr_win;
6894 }
6895
6896 /*
6897 * Return the current window stored in the snapshot or NULL.
6898 */
6899 static win_T *
6900 get_snapshot_curwin(int idx)
6901 {
6902 if (curtab->tp_snapshot[idx] == NULL)
6903 return NULL;
6904
6905 return get_snapshot_curwin_rec(curtab->tp_snapshot[idx]);
6906 }
6907
6908 /*
6864 * Restore a previously created snapshot, if there is any. 6909 * Restore a previously created snapshot, if there is any.
6865 * This is only done if the screen size didn't change and the window layout is 6910 * This is only done if the screen size didn't change and the window layout is
6866 * still the same. 6911 * still the same.
6867 */ 6912 */
6868 void 6913 void