mirror of
https://github.com/wez/wezterm.git
synced 2024-11-27 12:23:46 +03:00
wezterm: add CloseActivePane key assignment
This removes the active pane from the current tab, causing the tab to close if it was the last remaining pane in the tab. ```lua {key="W", mods="CTRL", action="CloseActivePane"}, ``` refs: https://github.com/wez/wezterm/issues/157
This commit is contained in:
parent
81ba73d5b8
commit
5031a53ff9
@ -1855,6 +1855,7 @@ impl TermWindow {
|
||||
}
|
||||
}
|
||||
CloseCurrentTab => self.close_current_tab(),
|
||||
CloseActivePane => self.close_active_pane(),
|
||||
Nop | DisableDefaultAssignment => {}
|
||||
ReloadConfiguration => crate::config::reload(),
|
||||
MoveTab(n) => self.move_tab(*n)?,
|
||||
@ -2125,6 +2126,15 @@ impl TermWindow {
|
||||
self.scaling_changed(self.dimensions, 1.);
|
||||
}
|
||||
|
||||
fn close_active_pane(&mut self) {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = match mux.get_active_tab_for_window(self.mux_window_id) {
|
||||
Some(tab) => tab,
|
||||
None => return,
|
||||
};
|
||||
tab.kill_active_pane();
|
||||
}
|
||||
|
||||
fn close_current_tab(&mut self) {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = match mux.get_active_tab_for_window(self.mux_window_id) {
|
||||
|
@ -123,6 +123,7 @@ pub enum KeyAssignment {
|
||||
AdjustPaneSize(PaneDirection, usize),
|
||||
ActivatePaneDirection(PaneDirection),
|
||||
TogglePaneZoomState,
|
||||
CloseActivePane,
|
||||
}
|
||||
impl_lua_conversion!(KeyAssignment);
|
||||
|
||||
|
@ -711,6 +711,18 @@ impl Tab {
|
||||
}
|
||||
|
||||
pub fn prune_dead_panes(&self) -> bool {
|
||||
self.remove_pane_if(|_, pane| pane.is_dead())
|
||||
}
|
||||
|
||||
pub fn kill_active_pane(&self) -> bool {
|
||||
let active_idx = *self.active.borrow();
|
||||
self.remove_pane_if(|idx, _| idx == active_idx)
|
||||
}
|
||||
|
||||
fn remove_pane_if<F>(&self, f: F) -> bool
|
||||
where
|
||||
F: Fn(usize, &Rc<dyn Pane>) -> bool,
|
||||
{
|
||||
let mut dead_panes = vec![];
|
||||
|
||||
{
|
||||
@ -723,7 +735,7 @@ impl Tab {
|
||||
|
||||
loop {
|
||||
// Figure out the available size by looking at our immediate parent node.
|
||||
// If we are the root, look at the provided new size
|
||||
// If we are the root, look at the tab size
|
||||
let pane_size = if let Some((branch, Some(parent))) = cursor.path_to_root().next() {
|
||||
if branch == PathBranch::IsRight {
|
||||
parent.second
|
||||
@ -736,7 +748,7 @@ impl Tab {
|
||||
|
||||
if cursor.is_leaf() {
|
||||
let pane = Rc::clone(cursor.leaf_mut().unwrap());
|
||||
if pane.is_dead() {
|
||||
if f(pane_index, &pane) {
|
||||
if pane_index == active_idx {
|
||||
active_idx = pane_index.saturating_sub(1);
|
||||
}
|
||||
@ -749,7 +761,11 @@ impl Tab {
|
||||
}
|
||||
Err(c) => {
|
||||
// We might be the root, for example
|
||||
root.replace(c.tree());
|
||||
if c.is_top() && c.is_leaf() {
|
||||
root.replace(Tree::Empty);
|
||||
} else {
|
||||
root.replace(c.tree());
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user