aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/winfloat.c
diff options
context:
space:
mode:
authorSean Dewar <6256228+seandewar@users.noreply.github.com>2024-03-09 22:32:20 +0000
committerGitHub <noreply@github.com>2024-03-09 22:32:20 +0000
commitb596732831b5e947ce83c1153f0df10a0553c88d (patch)
tree0a6e874de0ba7fb9eb3ef71d89516281731401e7 /src/nvim/winfloat.c
parentade1b12f49c3b3914c74847d791eb90ea90b56b7 (diff)
parentc3d22d32ee4b4c1911ec15f2a77683d09b09f845 (diff)
downloadrneovim-b596732831b5e947ce83c1153f0df10a0553c88d.tar.gz
rneovim-b596732831b5e947ce83c1153f0df10a0553c88d.tar.bz2
rneovim-b596732831b5e947ce83c1153f0df10a0553c88d.zip
Merge pull request #27330 from seandewar/win_set_config-fixes
fix(api): various window-related function fixes This is a big one!
Diffstat (limited to 'src/nvim/winfloat.c')
-rw-r--r--src/nvim/winfloat.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/nvim/winfloat.c b/src/nvim/winfloat.c
index 8fe0315230..65d2c1306b 100644
--- a/src/nvim/winfloat.c
+++ b/src/nvim/winfloat.c
@@ -55,13 +55,26 @@ win_T *win_new_float(win_T *wp, bool last, WinConfig fconfig, Error *err)
api_set_error(err, kErrorTypeException,
"Cannot change window from different tabpage into float");
return NULL;
+ } else if (cmdwin_win != NULL && !cmdwin_win->w_floating) {
+ // cmdwin can't become the only non-float. Check for others.
+ bool other_nonfloat = false;
+ for (win_T *wp2 = firstwin; wp2 != NULL && !wp2->w_floating; wp2 = wp2->w_next) {
+ if (wp2 != wp && wp2 != cmdwin_win) {
+ other_nonfloat = true;
+ break;
+ }
+ }
+ if (!other_nonfloat) {
+ api_set_error(err, kErrorTypeException, "%s", e_cmdwin);
+ return NULL;
+ }
}
int dir;
- winframe_remove(wp, &dir, NULL);
+ winframe_remove(wp, &dir, NULL, NULL);
XFREE_CLEAR(wp->w_frame);
win_comp_pos(); // recompute window positions
win_remove(wp, NULL);
- win_append(lastwin_nofloating(), wp);
+ win_append(lastwin_nofloating(), wp, NULL);
}
wp->w_floating = true;
wp->w_status_height = 0;
@@ -306,3 +319,21 @@ win_T *win_float_find_preview(void)
}
return NULL;
}
+
+/// Select an alternative window to `win` (assumed floating) in tabpage `tp`.
+///
+/// Useful for finding a window to switch to if `win` is the current window, but is then closed or
+/// moved to a different tabpage.
+///
+/// @param tp `win`'s original tabpage, or NULL for current.
+win_T *win_float_find_altwin(const win_T *win, const tabpage_T *tp)
+ FUNC_ATTR_NONNULL_ARG(1)
+{
+ if (tp == NULL) {
+ return (win_valid(prevwin) && prevwin != win) ? prevwin : firstwin;
+ }
+
+ assert(tp != curtab);
+ return (tabpage_win_valid(tp, tp->tp_prevwin) && tp->tp_prevwin != win) ? tp->tp_prevwin
+ : tp->tp_firstwin;
+}