mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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
bf44b69d1f
Co-authored-by: Sean Dewar <seandewar@users.noreply.github.com>
This commit is contained in:
parent
5dbf6ab9b1
commit
bdfea2a891
@ -4738,10 +4738,14 @@ static void win_enter_ext(win_T *const wp, const int flags)
|
|||||||
if (wp->w_buffer != curbuf) {
|
if (wp->w_buffer != curbuf) {
|
||||||
buf_copy_options(wp->w_buffer, BCO_ENTER | BCO_NOHELP);
|
buf_copy_options(wp->w_buffer, BCO_ENTER | BCO_NOHELP);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!curwin_invalid) {
|
if (!curwin_invalid) {
|
||||||
prevwin = curwin; // remember for CTRL-W p
|
prevwin = curwin; // remember for CTRL-W p
|
||||||
curwin->w_redr_status = true;
|
curwin->w_redr_status = true;
|
||||||
|
} else if (wp == prevwin) {
|
||||||
|
prevwin = NULL; // don't want it to be the new curwin
|
||||||
}
|
}
|
||||||
|
|
||||||
curwin = wp;
|
curwin = wp;
|
||||||
curbuf = wp->w_buffer;
|
curbuf = wp->w_buffer;
|
||||||
|
|
||||||
|
@ -113,6 +113,64 @@ func Test_window_quit()
|
|||||||
bw Xa Xb
|
bw Xa Xb
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_window_curwin_not_prevwin()
|
||||||
|
botright split
|
||||||
|
call assert_equal(2, winnr())
|
||||||
|
call assert_equal(1, winnr('#'))
|
||||||
|
quit
|
||||||
|
call assert_equal(1, winnr())
|
||||||
|
call assert_equal(0, winnr('#'))
|
||||||
|
|
||||||
|
botright split
|
||||||
|
botright split
|
||||||
|
call assert_equal(3, winnr())
|
||||||
|
call assert_equal(2, winnr('#'))
|
||||||
|
1quit
|
||||||
|
call assert_equal(2, winnr())
|
||||||
|
call assert_equal(1, winnr('#'))
|
||||||
|
|
||||||
|
botright split
|
||||||
|
call assert_equal(1, tabpagenr())
|
||||||
|
call assert_equal(3, winnr())
|
||||||
|
call assert_equal(2, winnr('#'))
|
||||||
|
wincmd T
|
||||||
|
call assert_equal(2, tabpagenr())
|
||||||
|
call assert_equal(1, winnr())
|
||||||
|
call assert_equal(0, winnr('#'))
|
||||||
|
tabfirst
|
||||||
|
call assert_equal(1, tabpagenr())
|
||||||
|
call assert_equal(2, winnr())
|
||||||
|
call assert_equal(0, winnr('#'))
|
||||||
|
|
||||||
|
tabonly
|
||||||
|
botright split
|
||||||
|
wincmd t
|
||||||
|
wincmd p
|
||||||
|
call assert_equal(3, winnr())
|
||||||
|
call assert_equal(1, winnr('#'))
|
||||||
|
quit
|
||||||
|
call assert_equal(2, winnr())
|
||||||
|
call assert_equal(1, winnr('#'))
|
||||||
|
|
||||||
|
botright split
|
||||||
|
wincmd t
|
||||||
|
wincmd p
|
||||||
|
call assert_equal(1, tabpagenr())
|
||||||
|
call assert_equal(3, winnr())
|
||||||
|
call assert_equal(1, winnr('#'))
|
||||||
|
wincmd T
|
||||||
|
call assert_equal(2, tabpagenr())
|
||||||
|
call assert_equal(1, winnr())
|
||||||
|
call assert_equal(0, winnr('#'))
|
||||||
|
tabfirst
|
||||||
|
call assert_equal(1, tabpagenr())
|
||||||
|
call assert_equal(2, winnr())
|
||||||
|
call assert_equal(1, winnr('#'))
|
||||||
|
|
||||||
|
tabonly
|
||||||
|
only
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_window_horizontal_split()
|
func Test_window_horizontal_split()
|
||||||
call assert_equal(1, winnr('$'))
|
call assert_equal(1, winnr('$'))
|
||||||
3wincmd s
|
3wincmd s
|
||||||
|
Loading…
Reference in New Issue
Block a user