aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/winfloat.c
diff options
context:
space:
mode:
authorSean Dewar <6256228+seandewar@users.noreply.github.com>2024-03-09 16:56:32 +0000
committerSean Dewar <6256228+seandewar@users.noreply.github.com>2024-03-09 18:00:30 +0000
commitb52d15853e89149472c1ecd9cce3a84e4af0785a (patch)
treedd13e54f31d20bff698a209af0af2424b75e4617 /src/nvim/winfloat.c
parent33dfb5a383d7afacda35b8fd392ad18d57db2870 (diff)
downloadrneovim-b52d15853e89149472c1ecd9cce3a84e4af0785a.tar.gz
rneovim-b52d15853e89149472c1ecd9cce3a84e4af0785a.tar.bz2
rneovim-b52d15853e89149472c1ecd9cce3a84e4af0785a.zip
fix(api): win_set_config set tp_curwin of win moved from other tabpage
Problem: nvim_win_set_config does not update the tp_curwin of win's original tabpage when moving it to another. Solution: update it if win was the tp_curwin. Add a test.
Diffstat (limited to 'src/nvim/winfloat.c')
-rw-r--r--src/nvim/winfloat.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/nvim/winfloat.c b/src/nvim/winfloat.c
index 3ddff8aa5a..65d2c1306b 100644
--- a/src/nvim/winfloat.c
+++ b/src/nvim/winfloat.c
@@ -319,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;
+}