Skip to content

Commit

Permalink
tweak ActivateLastTab and add a changelog entry for it
Browse files Browse the repository at this point in the history
refs: #610
  • Loading branch information
wez committed Apr 2, 2021
1 parent ee4b4b5 commit 4a3e061
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ brief notes about them may accumulate here.
* Fixed: Windows: we now compile libssh2 against openssl on all platforms to improve overall key and crypto algorithm support
* Fixed: spawning a new tab via the launcher menu failed because it used the pretty printed multiplexer domain label rather than the multiplexer domain name.
* Fixed: macOS: middle mouse button wasn't recognized. Thanks to [@guswynn](https://github.com/guswynn)! [#599](https://github.com/wez/wezterm/pull/599)
* New: added [ActivateLastTab](config/lua/keyassignment/ActivateLastTab.md) key assignment for jumping back to a previously active tab. Thanks to [@alexgartrell](https://github.com/alexgartrell) [#610](https://github.com/wez/wezterm/pull/610)

### 20210314-114017-04b7cedd

Expand Down
5 changes: 4 additions & 1 deletion docs/config/lua/keyassignment/ActivateLastTab.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# ActivateLastTab

Activate the last active tab. If there is none, it will do nothing.
*Since: nightly builds only*

Activate the last active tab. If there is none, it will do nothing.

```lua
return {
leader = { key="a", mods="CTRL" },
keys = {
-- CTRL-a, followed by CTRL-o will switch back to the last active tab
{key="o", mods="LEADER|CTRL", action="ActivateLastTab"},
}
}
Expand Down
17 changes: 15 additions & 2 deletions mux/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Window {
self.tabs.remove(idx);
let len = self.tabs.len();
if len > 0 && self.active == idx && idx >= len {
self.set_active(len - 1);
self.set_active_without_saving(len - 1);
}
true
} else {
Expand Down Expand Up @@ -139,7 +139,20 @@ impl Window {
}
}

pub fn set_active(&mut self, idx: usize) {
/// 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() {
return;
}
self.save_last_active();
self.set_active_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) {
assert!(idx < self.tabs.len());
self.invalidated = true;
self.active = idx;
Expand Down
2 changes: 1 addition & 1 deletion wezterm-gui/src/overlay/tabnavigator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn tab_navigator(
.get_window_mut(mux_window_id)
.ok_or_else(|| anyhow!("no such window"))?;

window.set_active(idx);
window.save_and_then_set_active(idx);
anyhow::Result::<()>::Ok(())
})
.detach();
Expand Down
7 changes: 2 additions & 5 deletions wezterm-gui/src/termwindow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,10 +1098,7 @@ impl TermWindow {
};

if tab_idx < max {
if tab_idx != window.get_active_idx() {
window.save_last_active();
}
window.set_active(tab_idx);
window.save_and_then_set_active(tab_idx);

drop(window);

Expand Down Expand Up @@ -1160,7 +1157,7 @@ impl TermWindow {

let tab_inst = window.remove_by_idx(active);
window.insert(tab_idx, &tab_inst);
window.set_active(tab_idx);
window.set_active_without_saving(tab_idx);

drop(window);
self.update_title();
Expand Down
3 changes: 1 addition & 2 deletions wezterm-gui/src/termwindow/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,8 @@ impl super::TermWindow {
let mut window = mux
.get_window_mut(target_window_id)
.ok_or_else(|| anyhow!("no such window!?"))?;
window.save_last_active();
if let Some(idx) = window.idx_by_id(tab_id) {
window.set_active(idx);
window.save_and_then_set_active(idx);
}
}
}
Expand Down

0 comments on commit 4a3e061

Please sign in to comment.