diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-12-02 10:30:50 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-12-02 10:51:50 +0800 |
commit | 982c0053f4059fb4558ce83a0b8d250be1058980 (patch) | |
tree | 6971f5ce71a9255b1ba23b5889e8788b700b7125 /src | |
parent | 61e99217e68498e757b9f8b0c70978a9635ccbfa (diff) | |
download | rneovim-982c0053f4059fb4558ce83a0b8d250be1058980.tar.gz rneovim-982c0053f4059fb4558ce83a0b8d250be1058980.tar.bz2 rneovim-982c0053f4059fb4558ce83a0b8d250be1058980.zip |
fix(float): make closing float in another tab return to correct window
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/window.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c index e761f7e40b..80c51516b1 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -1644,11 +1644,20 @@ 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; |