mirror of
https://github.com/wezterm/wezterm.git
synced 2026-11-08 01:21:45 +08:00
mux: Rename+doc Window functions for better readability
This commit is contained in:
parent
08e50ca2cd
commit
17d9fe1f1e
@ -282,12 +282,12 @@ impl SpawnTab {
|
||||
{
|
||||
let window = window.resolve(&mux)?;
|
||||
size = window
|
||||
.get_by_idx(0)
|
||||
.get_tab_at_idx(0)
|
||||
.map(|tab| tab.get_size())
|
||||
.unwrap_or_else(|| config::configuration().initial_size(0, None));
|
||||
|
||||
pane = window
|
||||
.get_active()
|
||||
.get_active_tab()
|
||||
.and_then(|tab| tab.get_active_pane().map(|pane| pane.pane_id()));
|
||||
};
|
||||
|
||||
|
||||
@ -414,12 +414,12 @@ impl UserData for MuxPane {
|
||||
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(|| {
|
||||
let tab_idx = window.get_tab_idx_for_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);
|
||||
window.remember_and_set_active_tab_idx(tab_idx);
|
||||
}
|
||||
let tab = mux
|
||||
.get_tab(tab_id)
|
||||
|
||||
@ -27,7 +27,7 @@ impl UserData for MuxTab {
|
||||
let mux = get_mux()?;
|
||||
for window_id in mux.iter_windows() {
|
||||
if let Some(window) = mux.get_window(window_id) {
|
||||
for tab in window.iter() {
|
||||
for tab in window.iter_tabs() {
|
||||
if tab.tab_id() == this.0 {
|
||||
return Ok(Some(MuxWindow(window_id)));
|
||||
}
|
||||
@ -146,12 +146,12 @@ impl UserData for MuxTab {
|
||||
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(|| {
|
||||
let tab_idx = window.get_tab_idx_for_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);
|
||||
window.remember_and_set_active_tab_idx(tab_idx);
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
|
||||
@ -68,7 +68,7 @@ impl UserData for MuxWindow {
|
||||
let mux = get_mux()?;
|
||||
let window = this.resolve(&mux)?;
|
||||
Ok(window
|
||||
.iter()
|
||||
.iter_tabs()
|
||||
.map(|tab| MuxTab(tab.tab_id()))
|
||||
.collect::<Vec<MuxTab>>())
|
||||
});
|
||||
@ -76,11 +76,11 @@ impl UserData for MuxWindow {
|
||||
let mux = get_mux()?;
|
||||
let window = this.resolve(&mux)?;
|
||||
let result = lua.create_table()?;
|
||||
let active_idx = window.get_active_idx();
|
||||
for (index, tab) in window.iter().enumerate() {
|
||||
let active_tab_idx = window.get_active_tab_idx();
|
||||
for (index, tab) in window.iter_tabs().enumerate() {
|
||||
let info = MuxTabInfo {
|
||||
index,
|
||||
is_active: index == active_idx,
|
||||
is_active: index == active_tab_idx,
|
||||
};
|
||||
let info = luahelper::dynamic_to_lua_value(lua, info.to_dynamic())?;
|
||||
match &info {
|
||||
@ -96,13 +96,13 @@ impl UserData for MuxWindow {
|
||||
methods.add_method("active_tab", |_, this, _: ()| {
|
||||
let mux = get_mux()?;
|
||||
let window = this.resolve(&mux)?;
|
||||
Ok(window.get_active().map(|tab| MuxTab(tab.tab_id())))
|
||||
Ok(window.get_active_tab().map(|tab| MuxTab(tab.tab_id())))
|
||||
});
|
||||
methods.add_method("active_pane", |_, this, _: ()| {
|
||||
let mux = get_mux()?;
|
||||
let window = this.resolve(&mux)?;
|
||||
Ok(window
|
||||
.get_active()
|
||||
.get_active_tab()
|
||||
.and_then(|tab| tab.get_active_pane().map(|pane| MuxPane(pane.pane_id()))))
|
||||
});
|
||||
}
|
||||
|
||||
@ -476,7 +476,7 @@ impl Mux {
|
||||
let mut count = HashMap::new();
|
||||
for window in self.windows.read().values() {
|
||||
let workspace = window.get_workspace();
|
||||
for tab in window.iter() {
|
||||
for tab in window.iter_tabs() {
|
||||
*count.entry(workspace.to_string()).or_insert(0) += match tab.count_panes() {
|
||||
Some(n) => n,
|
||||
None => {
|
||||
@ -557,9 +557,9 @@ impl Mux {
|
||||
.get_window_mut(window_id)
|
||||
.ok_or_else(|| anyhow::anyhow!("window_id {window_id} not found"))?;
|
||||
let tab_idx = win
|
||||
.idx_by_id(tab_id)
|
||||
.get_tab_idx_for_id(tab_id)
|
||||
.ok_or_else(|| anyhow::anyhow!("tab {tab_id} not in {window_id}"))?;
|
||||
win.save_and_then_set_active(tab_idx);
|
||||
win.remember_and_set_active_tab_idx(tab_idx);
|
||||
}
|
||||
|
||||
// Focus/activate the pane locally
|
||||
@ -839,7 +839,7 @@ impl Mux {
|
||||
|
||||
if let Some(mut windows) = self.windows.try_write() {
|
||||
for w in windows.values_mut() {
|
||||
w.remove_by_id(tab_id);
|
||||
w.remove_tab_id(tab_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -863,7 +863,7 @@ impl Mux {
|
||||
if let Some(window) = window {
|
||||
// Gather all the domains referenced by this window
|
||||
let mut domains_of_window = HashSet::new();
|
||||
for tab in window.iter() {
|
||||
for tab in window.iter_tabs() {
|
||||
for pane in tab.iter_panes_ignoring_zoom() {
|
||||
domains_of_window.insert(pane.pane.domain_id());
|
||||
}
|
||||
@ -883,7 +883,7 @@ impl Mux {
|
||||
}
|
||||
}
|
||||
|
||||
for tab in window.iter() {
|
||||
for tab in window.iter_tabs() {
|
||||
self.remove_tab_internal(tab.tab_id());
|
||||
}
|
||||
self.notify(MuxNotification::WindowRemoved(window_id));
|
||||
@ -982,7 +982,7 @@ impl Mux {
|
||||
|
||||
pub fn get_active_tab_for_window(&self, window_id: WindowId) -> Option<Arc<Tab>> {
|
||||
let window = self.get_window(window_id)?;
|
||||
window.get_active().map(Arc::clone)
|
||||
window.get_active_tab().map(Arc::clone)
|
||||
}
|
||||
|
||||
pub fn new_empty_window(
|
||||
@ -1006,7 +1006,7 @@ impl Mux {
|
||||
let mut window = self
|
||||
.get_window_mut(window_id)
|
||||
.ok_or_else(|| anyhow!("add_tab_to_window: no such window_id {}", window_id))?;
|
||||
window.push(tab);
|
||||
window.push_tab(tab);
|
||||
}
|
||||
self.recompute_pane_count();
|
||||
self.notify(MuxNotification::TabAddedToWindow { tab_id, window_id });
|
||||
@ -1016,7 +1016,7 @@ impl Mux {
|
||||
/// Returns the ID of the window containing the given tab ID, if any.
|
||||
pub fn window_containing_tab(&self, tab_id: TabId) -> Option<WindowId> {
|
||||
for w in self.windows.read().values() {
|
||||
for t in w.iter() {
|
||||
for t in w.iter_tabs() {
|
||||
if t.tab_id() == tab_id {
|
||||
return Some(w.window_id());
|
||||
}
|
||||
@ -1103,7 +1103,7 @@ impl Mux {
|
||||
{
|
||||
let mut windows = self.windows.write();
|
||||
for (_, win) in windows.iter_mut() {
|
||||
for tab in win.iter() {
|
||||
for tab in win.iter_tabs() {
|
||||
tab.kill_panes_in_domain(domain);
|
||||
}
|
||||
}
|
||||
@ -1286,7 +1286,7 @@ impl Mux {
|
||||
.get_window_mut(window_id)
|
||||
.ok_or_else(|| anyhow!("window_id {} not found on this server", window_id))?;
|
||||
let tab = window
|
||||
.get_active()
|
||||
.get_active_tab()
|
||||
.ok_or_else(|| anyhow!("window {} has no tabs", window_id))?;
|
||||
let size = tab.get_size();
|
||||
|
||||
@ -1336,7 +1336,7 @@ impl Mux {
|
||||
.get_window_mut(window_id)
|
||||
.ok_or_else(|| anyhow!("window_id {} not found on this server", window_id))?;
|
||||
let tab = window
|
||||
.get_active()
|
||||
.get_active_tab()
|
||||
.ok_or_else(|| anyhow!("window {} has no tabs", window_id))?;
|
||||
let pane = tab
|
||||
.get_active_pane()
|
||||
@ -1400,8 +1400,8 @@ impl Mux {
|
||||
let mut window = self
|
||||
.get_window_mut(window_id)
|
||||
.ok_or_else(|| anyhow!("no such window!?"))?;
|
||||
if let Some(idx) = window.idx_by_id(tab.tab_id()) {
|
||||
window.save_and_then_set_active(idx);
|
||||
if let Some(idx) = window.get_tab_idx_for_id(tab.tab_id()) {
|
||||
window.remember_and_set_active_tab_idx(idx);
|
||||
}
|
||||
|
||||
Ok((tab, pane, window_id))
|
||||
|
||||
@ -558,8 +558,8 @@ pub async fn run<
|
||||
let mut window = mux
|
||||
.get_window_mut(window_id)
|
||||
.ok_or_else(|| anyhow::anyhow!("invalid window id {}", window_id))?;
|
||||
let tab_idx = window.len().saturating_sub(1);
|
||||
window.save_and_then_set_active(tab_idx);
|
||||
let tab_idx = window.count_tabs().saturating_sub(1);
|
||||
window.remember_and_set_active_tab_idx(tab_idx);
|
||||
|
||||
Ok((pane.pane_id(), window_id))
|
||||
}
|
||||
|
||||
@ -590,7 +590,7 @@ impl TmuxDomainState {
|
||||
}
|
||||
MuxNotification::WindowInvalidated(window_id) => {
|
||||
if let Some(window) = mux.get_window(window_id) {
|
||||
let Some(tab) = window.get_active() else {
|
||||
let Some(tab) = window.get_active_tab() else {
|
||||
return;
|
||||
};
|
||||
let tmux_window_id = match tmux_domain
|
||||
|
||||
@ -9,34 +9,38 @@ pub type WindowId = usize;
|
||||
pub struct Window {
|
||||
id: WindowId,
|
||||
tabs: Vec<Arc<Tab>>,
|
||||
active: usize,
|
||||
last_active: Option<TabId>,
|
||||
active_tab_idx: usize,
|
||||
last_active_tab_id: Option<TabId>,
|
||||
workspace: String,
|
||||
title: String,
|
||||
initial_position: Option<GuiPosition>,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
/// Create a new Window.
|
||||
pub fn new(workspace: Option<String>, initial_position: Option<GuiPosition>) -> Self {
|
||||
Self {
|
||||
id: WIN_ID.fetch_add(1, ::std::sync::atomic::Ordering::Relaxed),
|
||||
tabs: vec![],
|
||||
active: 0,
|
||||
last_active: None,
|
||||
active_tab_idx: 0,
|
||||
last_active_tab_id: None,
|
||||
title: String::new(),
|
||||
workspace: workspace.unwrap_or_else(|| Mux::get().active_workspace()),
|
||||
initial_position,
|
||||
}
|
||||
}
|
||||
|
||||
/// Return initial position of the window.
|
||||
pub fn get_initial_position(&self) -> &Option<GuiPosition> {
|
||||
&self.initial_position
|
||||
}
|
||||
|
||||
/// Return current workspace.
|
||||
pub fn get_workspace(&self) -> &str {
|
||||
&self.workspace
|
||||
}
|
||||
|
||||
/// Set window title, notifying listeners if it changed.
|
||||
pub fn set_title(&mut self, title: &str) {
|
||||
if self.title != title {
|
||||
self.title = title.to_string();
|
||||
@ -49,10 +53,12 @@ impl Window {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return current title.
|
||||
pub fn get_title(&self) -> &str {
|
||||
&self.title
|
||||
}
|
||||
|
||||
/// Set window workspace, notifying listeners if it changed.
|
||||
pub fn set_workspace(&mut self, workspace: &str) {
|
||||
if workspace == self.workspace {
|
||||
return;
|
||||
@ -65,41 +71,50 @@ impl Window {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn check_that_tab_isnt_already_in_window(&self, tab: &Arc<Tab>) {
|
||||
/// Panic if given tab is already present in this window.
|
||||
fn assert_tab_isnt_already_in_window(&self, tab: &Arc<Tab>) {
|
||||
for t in &self.tabs {
|
||||
assert_ne!(t.tab_id(), tab.tab_id(), "tab already added to this window");
|
||||
}
|
||||
}
|
||||
|
||||
/// Notify that this window's tab layout has changed (add/remove/reorder),
|
||||
/// so listeners can refresh any cached view of it.
|
||||
fn invalidate(&self) {
|
||||
let mux = Mux::get();
|
||||
mux.notify(MuxNotification::WindowInvalidated(self.id));
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, index: usize, tab: &Arc<Tab>) {
|
||||
self.check_that_tab_isnt_already_in_window(tab);
|
||||
/// Insert `tab` in window, at given index.
|
||||
pub fn insert_tab_at_idx(&mut self, index: usize, tab: &Arc<Tab>) {
|
||||
self.assert_tab_isnt_already_in_window(tab);
|
||||
self.tabs.insert(index, Arc::clone(tab));
|
||||
self.invalidate();
|
||||
}
|
||||
|
||||
pub fn push(&mut self, tab: &Arc<Tab>) {
|
||||
self.check_that_tab_isnt_already_in_window(tab);
|
||||
/// Insert `tab` in window, after other tabs.
|
||||
pub fn push_tab(&mut self, tab: &Arc<Tab>) {
|
||||
self.assert_tab_isnt_already_in_window(tab);
|
||||
self.tabs.push(Arc::clone(tab));
|
||||
self.invalidate();
|
||||
}
|
||||
|
||||
/// Return true if this window contains no tabs.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.tabs.is_empty()
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
/// Return number of tabs in this window.
|
||||
pub fn count_tabs(&self) -> usize {
|
||||
self.tabs.len()
|
||||
}
|
||||
|
||||
pub fn get_by_idx(&self, idx: usize) -> Option<&Arc<Tab>> {
|
||||
/// Return tab at given index, if any.
|
||||
pub fn get_tab_at_idx(&self, idx: usize) -> Option<&Arc<Tab>> {
|
||||
self.tabs.get(idx)
|
||||
}
|
||||
|
||||
/// Return true if every tab can be closed without prompting the user.
|
||||
pub fn can_close_without_prompting(&self) -> bool {
|
||||
for tab in &self.tabs {
|
||||
if !tab.can_close_without_prompting(CloseReason::Window) {
|
||||
@ -109,7 +124,8 @@ impl Window {
|
||||
true
|
||||
}
|
||||
|
||||
pub fn idx_by_id(&self, id: TabId) -> Option<usize> {
|
||||
/// Return index of tab with given id, if it is found in this window.
|
||||
pub fn get_tab_idx_for_id(&self, id: TabId) -> Option<usize> {
|
||||
for (idx, t) in self.tabs.iter().enumerate() {
|
||||
if t.tab_id() == id {
|
||||
return Some(idx);
|
||||
@ -118,46 +134,49 @@ impl Window {
|
||||
None
|
||||
}
|
||||
|
||||
/// Re-establish a valid active tab after a tab removal.
|
||||
fn fixup_active_tab_after_removal(&mut self, active: Option<Arc<Tab>>) {
|
||||
let len = self.tabs.len();
|
||||
if let Some(active) = active {
|
||||
for (idx, tab) in self.tabs.iter().enumerate() {
|
||||
if tab.tab_id() == active.tab_id() {
|
||||
self.set_active_without_saving(idx);
|
||||
self.set_active_tab_idx_without_saving(idx);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len > 0 && self.active >= len {
|
||||
self.set_active_without_saving(len - 1);
|
||||
if len > 0 && self.active_tab_idx >= len {
|
||||
self.set_active_tab_idx_without_saving(len - 1);
|
||||
} else {
|
||||
self.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove_by_idx(&mut self, idx: usize) -> Arc<Tab> {
|
||||
/// Remove tab at given index and return it.
|
||||
pub fn remove_tab_idx(&mut self, idx: usize) -> Arc<Tab> {
|
||||
self.invalidate();
|
||||
let active = self.get_active().map(Arc::clone);
|
||||
self.do_remove_idx(idx, active)
|
||||
let active = self.get_active_tab().map(Arc::clone);
|
||||
self.do_remove_tab_idx(idx, active)
|
||||
}
|
||||
|
||||
pub fn remove_by_id(&mut self, id: TabId) {
|
||||
let active = self.get_active().map(Arc::clone);
|
||||
if let Some(idx) = self.idx_by_id(id) {
|
||||
self.do_remove_idx(idx, active);
|
||||
/// Remove tab with given id, if present.
|
||||
pub fn remove_tab_id(&mut self, id: TabId) {
|
||||
let active = self.get_active_tab().map(Arc::clone);
|
||||
if let Some(idx) = self.get_tab_idx_for_id(id) {
|
||||
self.do_remove_tab_idx(idx, active);
|
||||
}
|
||||
}
|
||||
|
||||
fn do_remove_idx(&mut self, idx: usize, active: Option<Arc<Tab>>) -> Arc<Tab> {
|
||||
/// Remove tab at given index, switching to previous active tab if needed.
|
||||
fn do_remove_tab_idx(&mut self, idx: usize, active: Option<Arc<Tab>>) -> Arc<Tab> {
|
||||
if let (Some(active), Some(removing)) = (&active, self.tabs.get(idx)) {
|
||||
if active.tab_id() == removing.tab_id()
|
||||
&& config::configuration().switch_to_last_active_tab_when_closing_tab
|
||||
{
|
||||
// If we are removing the active tab, switch back to
|
||||
// the previously active tab
|
||||
if let Some(last_active) = self.get_last_active_idx() {
|
||||
self.set_active_without_saving(last_active);
|
||||
// If we are removing active tab, switch back to previously active tab
|
||||
if let Some(last_active) = self.get_last_active_tab_idx() {
|
||||
self.set_active_tab_idx_without_saving(last_active);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -166,58 +185,66 @@ impl Window {
|
||||
tab
|
||||
}
|
||||
|
||||
pub fn get_active(&self) -> Option<&Arc<Tab>> {
|
||||
self.get_by_idx(self.active)
|
||||
/// Return currently active tab.
|
||||
pub fn get_active_tab(&self) -> Option<&Arc<Tab>> {
|
||||
// FIXME: `self.active_tab_idx` is supposed to be always valid, so this should really always
|
||||
// return the Tab.. and warn/panic(?) if active tab index isn't valid somehow (logic error!)
|
||||
self.get_tab_at_idx(self.active_tab_idx)
|
||||
}
|
||||
|
||||
/// Return index of currently active tab.
|
||||
#[inline]
|
||||
pub fn get_active_idx(&self) -> usize {
|
||||
self.active
|
||||
pub fn get_active_tab_idx(&self) -> usize {
|
||||
self.active_tab_idx
|
||||
}
|
||||
|
||||
pub fn save_last_active(&mut self) {
|
||||
self.last_active = self.get_by_idx(self.active).map(|tab| tab.tab_id());
|
||||
/// Remember current tab as the "last active" tab.
|
||||
pub fn remember_current_as_last_active_tab(&mut self) {
|
||||
self.last_active_tab_id = self
|
||||
.get_tab_at_idx(self.active_tab_idx)
|
||||
.map(|tab| tab.tab_id());
|
||||
}
|
||||
|
||||
/// Return index of previously active tab, if any.
|
||||
#[inline]
|
||||
pub fn get_last_active_idx(&self) -> Option<usize> {
|
||||
if let Some(tab_id) = self.last_active {
|
||||
self.idx_by_id(tab_id)
|
||||
pub fn get_last_active_tab_idx(&self) -> Option<usize> {
|
||||
if let Some(tab_id) = self.last_active_tab_id {
|
||||
self.get_tab_idx_for_id(tab_id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// If `idx` is different from the current active tab,
|
||||
/// save the current tabid and then make `idx` the active
|
||||
/// tab position.
|
||||
pub fn save_and_then_set_active(&mut self, idx: usize) {
|
||||
if idx == self.get_active_idx() {
|
||||
/// Remember current tab as the "last active" tab, then make tab at given index active.
|
||||
/// No-op when given index is already the active tab.
|
||||
pub fn remember_and_set_active_tab_idx(&mut self, idx: usize) {
|
||||
if idx == self.get_active_tab_idx() {
|
||||
return;
|
||||
}
|
||||
self.save_last_active();
|
||||
self.set_active_without_saving(idx);
|
||||
self.remember_current_as_last_active_tab();
|
||||
self.set_active_tab_idx_without_saving(idx);
|
||||
}
|
||||
|
||||
/// Make `idx` the active tab position.
|
||||
/// The saved tab id is not changed.
|
||||
pub fn set_active_without_saving(&mut self, idx: usize) {
|
||||
/// Make given index the active tab without remembering current tab as the "last active" tab.
|
||||
pub fn set_active_tab_idx_without_saving(&mut self, idx: usize) {
|
||||
assert!(idx < self.tabs.len());
|
||||
if self.active != idx {
|
||||
if let Some(tab) = self.tabs.get(self.active) {
|
||||
if self.active_tab_idx != idx {
|
||||
if let Some(tab) = self.tabs.get(self.active_tab_idx) {
|
||||
if let Some(pane) = tab.get_active_pane() {
|
||||
pane.focus_changed(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.active = idx;
|
||||
self.active_tab_idx = idx;
|
||||
self.invalidate();
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = &Arc<Tab>> {
|
||||
/// Iterate over tabs in this window.
|
||||
pub fn iter_tabs(&self) -> impl Iterator<Item = &Arc<Tab>> {
|
||||
self.tabs.iter()
|
||||
}
|
||||
|
||||
/// Remove dead tabs, and any tabs not present in given `live_tab_ids`.
|
||||
pub fn prune_dead_tabs(&mut self, live_tab_ids: &[TabId]) {
|
||||
let mut invalidated = false;
|
||||
let dead: Vec<TabId> = self
|
||||
@ -237,7 +264,7 @@ impl Window {
|
||||
|
||||
for tab_id in dead {
|
||||
log::trace!("Window::prune_dead_tabs: tab_id {} is dead", tab_id);
|
||||
self.remove_by_id(tab_id);
|
||||
self.remove_tab_id(tab_id);
|
||||
invalidated = true;
|
||||
}
|
||||
|
||||
@ -258,7 +285,7 @@ impl Window {
|
||||
.collect();
|
||||
for tab_id in dead {
|
||||
log::trace!("Window::prune_dead_tabs: (live) tab_id {} is dead", tab_id);
|
||||
self.remove_by_id(tab_id);
|
||||
self.remove_tab_id(tab_id);
|
||||
}
|
||||
|
||||
if invalidated {
|
||||
|
||||
@ -71,7 +71,7 @@ impl ClientInner {
|
||||
.retain(
|
||||
|_remote_window_id, local_window_id| match mux.get_window(*local_window_id) {
|
||||
Some(w) => {
|
||||
for tab in w.iter() {
|
||||
for tab in w.iter_tabs() {
|
||||
for pos in tab.iter_panes_ignoring_zoom() {
|
||||
if pos.pane.domain_id() == self.local_domain_id {
|
||||
return true;
|
||||
@ -627,8 +627,8 @@ impl ClientDomain {
|
||||
inner.local_domain_id,
|
||||
local_window_id
|
||||
);
|
||||
if window.idx_by_id(tab.tab_id()).is_none() {
|
||||
window.push(&tab);
|
||||
if window.get_tab_idx_for_id(tab.tab_id()).is_none() {
|
||||
window.push_tab(&tab);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -266,7 +266,7 @@ fn have_panes_in_domain_and_ws(domain: &Arc<dyn Domain>, workspace: &Option<Stri
|
||||
if let Some(ws) = &workspace {
|
||||
for window_id in mux.iter_windows_in_workspace(ws) {
|
||||
if let Some(win) = mux.get_window(window_id) {
|
||||
for t in win.iter() {
|
||||
for t in win.iter_tabs() {
|
||||
for p in t.iter_panes_ignoring_zoom() {
|
||||
if p.pane.domain_id() == domain.domain_id() {
|
||||
return true;
|
||||
@ -483,8 +483,8 @@ async fn async_run_terminal_gui(
|
||||
let mut window = mux
|
||||
.get_window_mut(window_id)
|
||||
.ok_or_else(|| anyhow!("failed to get mux window id {window_id}"))?;
|
||||
if let Some(tab_idx) = window.idx_by_id(tab.tab_id()) {
|
||||
window.set_active_without_saving(tab_idx);
|
||||
if let Some(tab_idx) = window.get_tab_idx_for_id(tab.tab_id()) {
|
||||
window.set_active_tab_idx_without_saving(tab_idx);
|
||||
}
|
||||
trigger_and_log_gui_attached(MuxDomain(domain.domain_id())).await;
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ impl LauncherArgs {
|
||||
.get_window(mux_window_id)
|
||||
.expect("to resolve my own window_id");
|
||||
window
|
||||
.iter()
|
||||
.iter_tabs()
|
||||
.enumerate()
|
||||
.map(|(tab_idx, tab)| {
|
||||
let tab_title = tab.get_title();
|
||||
|
||||
@ -50,7 +50,9 @@ impl UserData for GuiWin {
|
||||
let window = mux.get_window(this.mux_window_id).ok_or_else(|| {
|
||||
mlua::Error::external(format!("invalid window {}", this.mux_window_id))
|
||||
})?;
|
||||
Ok(window.get_active().map(|tab| mux_lua::MuxTab(tab.tab_id())))
|
||||
Ok(window
|
||||
.get_active_tab()
|
||||
.map(|tab| mux_lua::MuxTab(tab.tab_id())))
|
||||
});
|
||||
|
||||
methods.add_method(
|
||||
|
||||
@ -632,7 +632,7 @@ impl TermWindow {
|
||||
terminal_size,
|
||||
);
|
||||
if let Some(window) = mux.get_window(mux_window_id) {
|
||||
for tab in window.iter() {
|
||||
for tab in window.iter_tabs() {
|
||||
tab.resize(terminal_size);
|
||||
}
|
||||
};
|
||||
@ -1347,7 +1347,7 @@ impl TermWindow {
|
||||
|
||||
let mux = Mux::get();
|
||||
if let Some(window) = mux.get_window(self.mux_window_id) {
|
||||
for tab in window.iter() {
|
||||
for tab in window.iter_tabs() {
|
||||
tab.resize(self.terminal_size);
|
||||
}
|
||||
};
|
||||
@ -1749,7 +1749,7 @@ impl TermWindow {
|
||||
Some(window) => window,
|
||||
_ => return,
|
||||
};
|
||||
if window.len() == 1 {
|
||||
if window.count_tabs() == 1 {
|
||||
self.show_tab_bar = config.enable_tab_bar && !config.hide_tab_bar_if_only_one_tab;
|
||||
} else {
|
||||
self.show_tab_bar = config.enable_tab_bar;
|
||||
@ -1803,7 +1803,7 @@ impl TermWindow {
|
||||
if let Some(window) = mux.get_window(self.mux_window_id) {
|
||||
let term_config: Arc<dyn TerminalConfiguration> =
|
||||
Arc::new(TermConfig::with_config(config.clone()));
|
||||
for tab in window.iter() {
|
||||
for tab in window.iter_tabs() {
|
||||
for pane in tab.iter_panes_ignoring_zoom() {
|
||||
pane.pane.set_config(Arc::clone(&term_config));
|
||||
}
|
||||
@ -2011,8 +2011,8 @@ impl TermWindow {
|
||||
}
|
||||
}
|
||||
|
||||
let num_tabs = window.len();
|
||||
if num_tabs == 0 {
|
||||
let tabs_count = window.count_tabs();
|
||||
if tabs_count == 0 {
|
||||
return;
|
||||
}
|
||||
drop(window);
|
||||
@ -2054,14 +2054,14 @@ impl TermWindow {
|
||||
Some(title) => title,
|
||||
None => {
|
||||
if let (Some(pos), Some(tab)) = (active_pane, active_tab) {
|
||||
if num_tabs == 1 {
|
||||
if tabs_count == 1 {
|
||||
format!("{}{}", if pos.is_zoomed { "[Z] " } else { "" }, pos.title)
|
||||
} else {
|
||||
format!(
|
||||
"{}[{}/{}] {}",
|
||||
if pos.is_zoomed { "[Z] " } else { "" },
|
||||
tab.tab_index + 1,
|
||||
num_tabs,
|
||||
tabs_count,
|
||||
pos.title
|
||||
)
|
||||
}
|
||||
@ -2074,7 +2074,7 @@ impl TermWindow {
|
||||
if let Some(window) = self.window.as_ref() {
|
||||
window.set_title(&title);
|
||||
|
||||
let show_tab_bar = if num_tabs == 1 {
|
||||
let show_tab_bar = if tabs_count == 1 {
|
||||
self.config.enable_tab_bar && !self.config.hide_tab_bar_if_only_one_tab
|
||||
} else {
|
||||
self.config.enable_tab_bar
|
||||
@ -2184,7 +2184,7 @@ impl TermWindow {
|
||||
|
||||
// This logic is coupled with the CliSubCommand::ActivateTab
|
||||
// logic in wezterm/src/main.rs. If you update this, update that!
|
||||
let max = window.len();
|
||||
let max = window.count_tabs();
|
||||
|
||||
let tab_idx = if tab_idx < 0 {
|
||||
max.saturating_sub(tab_idx.abs() as usize)
|
||||
@ -2193,7 +2193,7 @@ impl TermWindow {
|
||||
};
|
||||
|
||||
if tab_idx < max {
|
||||
window.save_and_then_set_active(tab_idx);
|
||||
window.remember_and_set_active_tab_idx(tab_idx);
|
||||
|
||||
drop(window);
|
||||
|
||||
@ -2213,12 +2213,12 @@ impl TermWindow {
|
||||
.get_window(self.mux_window_id)
|
||||
.ok_or_else(|| anyhow!("no such window"))?;
|
||||
|
||||
let max = window.len();
|
||||
let max = window.count_tabs();
|
||||
ensure!(max > 0, "no more tabs");
|
||||
|
||||
// This logic is coupled with the CliSubCommand::ActivateTab
|
||||
// logic in wezterm/src/main.rs. If you update this, update that!
|
||||
let active = window.get_active_idx() as isize;
|
||||
let active = window.get_active_tab_idx() as isize;
|
||||
let tab = active + delta;
|
||||
let tab = if wrap {
|
||||
let tab = if tab < 0 { max as isize + tab } else { tab };
|
||||
@ -2242,7 +2242,7 @@ impl TermWindow {
|
||||
.get_window(self.mux_window_id)
|
||||
.ok_or_else(|| anyhow!("no such window"))?;
|
||||
|
||||
let last_idx = window.get_last_active_idx();
|
||||
let last_idx = window.get_last_active_tab_idx();
|
||||
drop(window);
|
||||
match last_idx {
|
||||
Some(idx) => self.activate_tab(idx as isize),
|
||||
@ -2256,16 +2256,16 @@ impl TermWindow {
|
||||
.get_window_mut(self.mux_window_id)
|
||||
.ok_or_else(|| anyhow!("no such window"))?;
|
||||
|
||||
let max = window.len();
|
||||
let max = window.count_tabs();
|
||||
ensure!(max > 0, "no more tabs");
|
||||
|
||||
let active = window.get_active_idx();
|
||||
let active_tab_idx = window.get_active_tab_idx();
|
||||
|
||||
ensure!(tab_idx < max, "cannot move a tab out of range");
|
||||
|
||||
let tab_inst = window.remove_by_idx(active);
|
||||
window.insert(tab_idx, &tab_inst);
|
||||
window.set_active_without_saving(tab_idx);
|
||||
let tab = window.remove_tab_idx(active_tab_idx);
|
||||
window.insert_tab_at_idx(tab_idx, &tab);
|
||||
window.set_active_tab_idx_without_saving(tab_idx);
|
||||
|
||||
drop(window);
|
||||
self.update_title();
|
||||
@ -2370,7 +2370,7 @@ impl TermWindow {
|
||||
fn show_tab_navigator(&mut self) {
|
||||
let mux = Mux::get();
|
||||
let active_tab_idx = match mux.get_window(self.mux_window_id) {
|
||||
Some(mux_window) => mux_window.get_active_idx(),
|
||||
Some(mux_window) => mux_window.get_active_tab_idx(),
|
||||
None => return,
|
||||
};
|
||||
let title = "Tab Navigator".to_string();
|
||||
@ -2563,10 +2563,10 @@ impl TermWindow {
|
||||
.get_window(self.mux_window_id)
|
||||
.ok_or_else(|| anyhow!("no such window"))?;
|
||||
|
||||
let max = window.len();
|
||||
let max = window.count_tabs();
|
||||
ensure!(max > 0, "no more tabs");
|
||||
|
||||
let active = window.get_active_idx();
|
||||
let active = window.get_active_tab_idx();
|
||||
let tab = active as isize + delta;
|
||||
let tab = if tab < 0 {
|
||||
0usize
|
||||
@ -3242,7 +3242,7 @@ impl TermWindow {
|
||||
None => return,
|
||||
};
|
||||
|
||||
let tab = match mux_window.get_by_idx(tab_idx) {
|
||||
let tab = match mux_window.get_tab_at_idx(tab_idx) {
|
||||
Some(tab) => Arc::clone(tab),
|
||||
None => return,
|
||||
};
|
||||
@ -3460,10 +3460,10 @@ impl TermWindow {
|
||||
Some(window) => window,
|
||||
_ => return vec![],
|
||||
};
|
||||
let tab_index = window.get_active_idx();
|
||||
let tab_index = window.get_active_tab_idx();
|
||||
|
||||
window
|
||||
.iter()
|
||||
.iter_tabs()
|
||||
.enumerate()
|
||||
.map(|(idx, tab)| {
|
||||
let panes = self.get_pos_panes_for_tab(tab);
|
||||
@ -3473,7 +3473,7 @@ impl TermWindow {
|
||||
tab_id: tab.tab_id(),
|
||||
is_active: tab_index == idx,
|
||||
is_last_active: window
|
||||
.get_last_active_idx()
|
||||
.get_last_active_tab_idx()
|
||||
.map(|last_active| last_active == idx)
|
||||
.unwrap_or(false),
|
||||
window_id: self.mux_window_id,
|
||||
|
||||
@ -294,7 +294,7 @@ impl super::TermWindow {
|
||||
|
||||
let mux = Mux::get();
|
||||
if let Some(window) = mux.get_window(self.mux_window_id) {
|
||||
for tab in window.iter() {
|
||||
for tab in window.iter_tabs() {
|
||||
tab.resize(size);
|
||||
}
|
||||
};
|
||||
|
||||
@ -348,12 +348,13 @@ impl SessionHandler {
|
||||
mux.get_window_mut(window_id).ok_or_else(|| {
|
||||
anyhow::anyhow!("window {window_id} not found")
|
||||
})?;
|
||||
let tab_idx = window.idx_by_id(tab_id).ok_or_else(|| {
|
||||
anyhow::anyhow!(
|
||||
"tab {tab_id} isn't really in window {window_id}!?"
|
||||
)
|
||||
})?;
|
||||
window.save_and_then_set_active(tab_idx);
|
||||
let tab_idx =
|
||||
window.get_tab_idx_for_id(tab_id).ok_or_else(|| {
|
||||
anyhow::anyhow!(
|
||||
"tab {tab_id} isn't really in window {window_id}!?"
|
||||
)
|
||||
})?;
|
||||
window.remember_and_set_active_tab_idx(tab_idx);
|
||||
}
|
||||
let tab = mux
|
||||
.get_tab(tab_id)
|
||||
@ -396,7 +397,7 @@ impl SessionHandler {
|
||||
for window_id in mux.iter_windows().into_iter() {
|
||||
let window = mux.get_window(window_id).unwrap();
|
||||
window_titles.insert(window_id, window.get_title().to_string());
|
||||
for tab in window.iter() {
|
||||
for tab in window.iter_tabs() {
|
||||
tabs.push(tab.codec_pane_tree());
|
||||
tab_titles.push(tab.get_title());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user