aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/tabpage.c
diff options
context:
space:
mode:
authorWill Hopkins <willothyh@gmail.com>2024-01-28 23:18:33 -0800
committerGitHub <noreply@github.com>2024-01-29 15:18:33 +0800
commitca9f6f56949d66f0f6467fa64b215f861fe0a3bf (patch)
treec65f6084044279f65617c6e7345304edc015b767 /src/nvim/api/tabpage.c
parent5e5b004da44c7075ed1e20ae9d05ab09c6f2ac58 (diff)
downloadrneovim-ca9f6f56949d66f0f6467fa64b215f861fe0a3bf.tar.gz
rneovim-ca9f6f56949d66f0f6467fa64b215f861fe0a3bf.tar.bz2
rneovim-ca9f6f56949d66f0f6467fa64b215f861fe0a3bf.zip
feat(api): add nvim_tabpage_set_win (#27222)
Allows setting the current window of a non-current tabpage without switching tabpages.
Diffstat (limited to 'src/nvim/api/tabpage.c')
-rw-r--r--src/nvim/api/tabpage.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/nvim/api/tabpage.c b/src/nvim/api/tabpage.c
index 303f2ca817..fadc03b3e5 100644
--- a/src/nvim/api/tabpage.c
+++ b/src/nvim/api/tabpage.c
@@ -122,6 +122,37 @@ Window nvim_tabpage_get_win(Tabpage tabpage, Error *err)
abort();
}
+/// Sets the current window in a tabpage
+///
+/// @param tabpage Tabpage handle, or 0 for current tabpage
+/// @param win Window handle, must already belong to {tabpage}
+/// @param[out] err Error details, if any
+void nvim_tabpage_set_win(Tabpage tabpage, Window win, Error *err)
+ FUNC_API_SINCE(12)
+{
+ tabpage_T *tp = find_tab_by_handle(tabpage, err);
+ if (!tp) {
+ return;
+ }
+
+ win_T *wp = find_window_by_handle(win, err);
+ if (!wp) {
+ return;
+ }
+
+ if (!tabpage_win_valid(tp, wp)) {
+ api_set_error(err, kErrorTypeException, "Window does not belong to tabpage %d", tp->handle);
+ return;
+ }
+
+ if (tp == curtab) {
+ win_enter(wp, true);
+ } else if (tp->tp_curwin != wp) {
+ tp->tp_prevwin = tp->tp_curwin;
+ tp->tp_curwin = wp;
+ }
+}
+
/// Gets the tabpage number
///
/// @param tabpage Tabpage handle, or 0 for current tabpage