1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 13:21:38 +03:00

add pane:activate() and tab:activate()

refs: #3217
This commit is contained in:
Wez Furlong 2023-03-27 21:12:10 -07:00
parent 46fc05a746
commit dd16e586c3
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
5 changed files with 62 additions and 1 deletions

View File

@ -22,7 +22,7 @@ usually the best available version.
As features stabilize some brief notes about them will accumulate here.
#### New
* Not yet
* [pane:activate()](config/lua/pane/activate.md) and [tab:activate()](config/lua/MuxTab/activate.md). #3217
### 20230326-111934-3666303c

View File

@ -0,0 +1,6 @@
# `tab:activate()`
{{since('nightly')}}
Activates (focuses) the tab.

View File

@ -0,0 +1,5 @@
# `pane:activate()`
{{since('nightly')}}
Activates (focuses) the pane and its containing tab.

View File

@ -379,6 +379,30 @@ impl UserData for MuxPane {
Ok((MuxTab(tab.tab_id()), MuxWindow(window)))
},
);
methods.add_method("activate", move |_lua, this, ()| {
let mux = Mux::get();
let pane = this.resolve(&mux)?;
let (_domain_id, window_id, tab_id) = mux
.resolve_pane_id(this.0)
.ok_or_else(|| mlua::Error::external(format!("pane {} not found", this.0)))?;
{
let mut window = mux.get_window_mut(window_id).ok_or_else(|| {
mlua::Error::external(format!("window {window_id} not found"))
})?;
let tab_idx = window.idx_by_id(tab_id).ok_or_else(|| {
mlua::Error::external(format!(
"tab {tab_id} isn't really in window {window_id}!?"
))
})?;
window.save_and_then_set_active(tab_idx);
}
let tab = mux
.get_tab(tab_id)
.ok_or_else(|| mlua::Error::external(format!("tab {tab_id} not found")))?;
tab.set_active_pane(&pane);
Ok(())
});
}
}

View File

@ -124,5 +124,31 @@ impl UserData for MuxTab {
let tab = this.resolve(&mux)?;
to_lua(lua, tab.get_size())
});
methods.add_method("activate", move |_lua, this, ()| {
let mux = Mux::get();
let tab = this.resolve(&mux)?;
let pane = tab.get_active_pane().ok_or_else(|| {
mlua::Error::external(format!("tab {} has no active pane!?", this.0))
})?;
let (_domain_id, window_id, tab_id) =
mux.resolve_pane_id(pane.pane_id()).ok_or_else(|| {
mlua::Error::external(format!("pane {} not found", pane.pane_id()))
})?;
{
let mut window = mux.get_window_mut(window_id).ok_or_else(|| {
mlua::Error::external(format!("window {window_id} not found"))
})?;
let tab_idx = window.idx_by_id(tab_id).ok_or_else(|| {
mlua::Error::external(format!(
"tab {tab_id} isn't really in window {window_id}!?"
))
})?;
window.save_and_then_set_active(tab_idx);
}
Ok(())
});
}
}