From bdfea2a8919963dfe24052635883f0213cff83e8 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Wed, 3 Jan 2024 19:09:43 +0100 Subject: vim-patch:9.1.0001: when closing window, wincmd p may fail Avoid `prevwin == curwin` when closing `curwin` Problem: When closing the current window (or when moving it to a tabpage), the previous window may refer to the new current window (`winnr() == winnr('#')`) if that window is selected as the new current window. Solution: Set `prevwin = NULL` when switching away from an invalid `curwin` and the target window was the `prevwin`. (Sean Dewar) related: vim/vim#4537 closes: vim/vim#13762 https://github.com/vim/vim/commit/bf44b69d1f91d9778ae1887128c63d35d9a3d19b Co-authored-by: Sean Dewar --- src/nvim/window.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/nvim/window.c b/src/nvim/window.c index bb630f6217..c123de0f77 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -4738,10 +4738,14 @@ static void win_enter_ext(win_T *const wp, const int flags) if (wp->w_buffer != curbuf) { buf_copy_options(wp->w_buffer, BCO_ENTER | BCO_NOHELP); } + if (!curwin_invalid) { prevwin = curwin; // remember for CTRL-W p curwin->w_redr_status = true; + } else if (wp == prevwin) { + prevwin = NULL; // don't want it to be the new curwin } + curwin = wp; curbuf = wp->w_buffer; -- cgit