mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
fix(float): make closing float in another tab return to correct window
This commit is contained in:
@@ -1643,12 +1643,21 @@ bool win_valid_floating(const win_T *win)
|
||||
///
|
||||
/// @param win window to check
|
||||
bool win_valid(const win_T *win) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
||||
{
|
||||
return tabpage_win_valid(curtab, win);
|
||||
}
|
||||
|
||||
/// Check if "win" is a pointer to an existing window in tabpage "tp".
|
||||
///
|
||||
/// @param win window to check
|
||||
static bool tabpage_win_valid(const tabpage_T *tp, const win_T *win)
|
||||
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
||||
{
|
||||
if (win == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
|
||||
FOR_ALL_WINDOWS_IN_TAB(wp, tp) {
|
||||
if (wp == win) {
|
||||
return true;
|
||||
}
|
||||
@@ -3057,10 +3066,18 @@ static win_T *win_free_mem(win_T *win, int *dirp, tabpage_T *tp)
|
||||
xfree(frp);
|
||||
} else {
|
||||
*dirp = 'h'; // Dummy value.
|
||||
if (win_valid(prevwin) && prevwin != win) {
|
||||
wp = prevwin;
|
||||
if (tp == NULL) {
|
||||
if (win_valid(prevwin) && prevwin != win) {
|
||||
wp = prevwin;
|
||||
} else {
|
||||
wp = firstwin;
|
||||
}
|
||||
} else {
|
||||
wp = firstwin;
|
||||
if (tabpage_win_valid(tp, tp->tp_prevwin) && tp->tp_prevwin != win) {
|
||||
wp = tp->tp_prevwin;
|
||||
} else {
|
||||
wp = tp->tp_firstwin;
|
||||
}
|
||||
}
|
||||
}
|
||||
win_free(win, tp);
|
||||
@@ -3068,11 +3085,7 @@ static win_T *win_free_mem(win_T *win, int *dirp, tabpage_T *tp)
|
||||
// When deleting the current window of another tab page select a new
|
||||
// current window.
|
||||
if (tp != NULL && win == tp->tp_curwin) {
|
||||
if (win_valid(tp->tp_prevwin) && tp->tp_prevwin != win) {
|
||||
tp->tp_curwin = tp->tp_prevwin;
|
||||
} else {
|
||||
tp->tp_curwin = tp->tp_firstwin;
|
||||
}
|
||||
tp->tp_curwin = wp;
|
||||
}
|
||||
|
||||
return wp;
|
||||
|
@@ -490,6 +490,8 @@ describe('API/win', function()
|
||||
|
||||
it('closing current (float) window of another tabpage #15313', function()
|
||||
command('tabedit')
|
||||
command('botright split')
|
||||
local prevwin = curwin().id
|
||||
eq(2, eval('tabpagenr()'))
|
||||
local win = meths.open_win(0, true, {
|
||||
relative='editor', row=10, col=10, width=50, height=10
|
||||
@@ -499,7 +501,7 @@ describe('API/win', function()
|
||||
eq(1, eval('tabpagenr()'))
|
||||
meths.win_close(win, false)
|
||||
|
||||
eq(1001, meths.tabpage_get_win(tab).id)
|
||||
eq(prevwin, meths.tabpage_get_win(tab).id)
|
||||
assert_alive()
|
||||
end)
|
||||
end)
|
||||
|
Reference in New Issue
Block a user