diff --git a/docs/changelog.markdown b/docs/changelog.markdown index 060bfd996..c4252fbf3 100644 --- a/docs/changelog.markdown +++ b/docs/changelog.markdown @@ -41,6 +41,9 @@ brief notes about them may accumulate here. to a similar degree as iTerm2 * Fixed an issue where unmodified F5+ would use the CSI-u encoded-modifiers format, and confused eg: `htop`. +* `ActivateTab` now accepts negative numbers as a way to reference the last + tab in the Window. The default assignment for `CTRL+SHIFT+9` and `CMD+9` + is now `ActivateTab=-1`, which selects the last tab. ### 20200607-144723-74889cd4 diff --git a/docs/config/keys.markdown b/docs/config/keys.markdown index 4ec6f04a7..3d3acd501 100644 --- a/docs/config/keys.markdown +++ b/docs/config/keys.markdown @@ -40,7 +40,7 @@ The default key bindings are: | `SUPER` | `6` | `ActivateTab=5` | | `SUPER` | `7` | `ActivateTab=6` | | `SUPER` | `8` | `ActivateTab=7` | -| `SUPER` | `9` | `ActivateTab=8` | +| `SUPER` | `9` | `ActivateTab=-1` | | `CTRL+SHIFT` | `w` | `CloseCurrentTab` | | `CTRL+SHIFT` | `1` | `ActivateTab=0` | | `CTRL+SHIFT` | `2` | `ActivateTab=1` | @@ -50,7 +50,7 @@ The default key bindings are: | `CTRL+SHIFT` | `6` | `ActivateTab=5` | | `CTRL+SHIFT` | `7` | `ActivateTab=6` | | `CTRL+SHIFT` | `8` | `ActivateTab=7` | -| `CTRL+SHIFT` | `9` | `ActivateTab=8` | +| `CTRL+SHIFT` | `9` | `ActivateTab=-1` | | `SUPER+SHIFT` | `[` | `ActivateTabRelative=-1` | | `SUPER+SHIFT` | `]` | `ActivateTabRelative=1` | | `CTRL+SHIFT` | `PAGEUP` | `MoveTabRelative=-1` | @@ -340,6 +340,13 @@ return { Activate the tab specified by the argument value. eg: `0` activates the leftmost tab, while `1` activates the second tab from the left, and so on. +*since: nightly* + +`ActivateTab` now accepts negative numbers; these wrap around from the start +of the tabs to the end, so `-1` references the right-most tab, `-2` the tab +to its left and so on. + + ```lua local wezterm = require 'wezterm'; diff --git a/src/frontend/gui/termwindow.rs b/src/frontend/gui/termwindow.rs index 7564dd732..56634ff4f 100644 --- a/src/frontend/gui/termwindow.rs +++ b/src/frontend/gui/termwindow.rs @@ -1202,13 +1202,20 @@ impl TermWindow { } } - fn activate_tab(&mut self, tab_idx: usize) -> anyhow::Result<()> { + fn activate_tab(&mut self, tab_idx: isize) -> anyhow::Result<()> { let mux = Mux::get().unwrap(); let mut window = mux .get_window_mut(self.mux_window_id) .ok_or_else(|| anyhow!("no such window"))?; let max = window.len(); + + let tab_idx = if tab_idx < 0 { + max.saturating_sub(tab_idx.abs() as usize) + } else { + tab_idx as usize + }; + if tab_idx < max { window.set_active(tab_idx); @@ -1232,7 +1239,7 @@ impl TermWindow { let tab = active + delta; let tab = if tab < 0 { max as isize + tab } else { tab }; drop(window); - self.activate_tab(tab as usize % max) + self.activate_tab((tab as usize % max) as isize) } fn move_tab(&mut self, tab_idx: usize) -> anyhow::Result<()> { @@ -2950,7 +2957,7 @@ impl TermWindow { match event.kind { WMEK::Press(MousePress::Left) => match self.tab_bar.hit_test(x) { TabBarItem::Tab(tab_idx) => { - self.activate_tab(tab_idx).ok(); + self.activate_tab(tab_idx as isize).ok(); } TabBarItem::NewTabButton => { self.spawn_tab(&SpawnTabDomain::CurrentTabDomain); diff --git a/src/keyassignment.rs b/src/keyassignment.rs index abbe4c78d..3f0dc7945 100644 --- a/src/keyassignment.rs +++ b/src/keyassignment.rs @@ -82,7 +82,7 @@ pub enum KeyAssignment { IncreaseFontSize, DecreaseFontSize, ResetFontSize, - ActivateTab(usize), + ActivateTab(isize), SendString(String), Nop, DisableDefaultAssignment, @@ -207,7 +207,7 @@ impl InputMap { [KeyModifiers::SUPER, KeyCode::Char('6'), ActivateTab(5)], [KeyModifiers::SUPER, KeyCode::Char('7'), ActivateTab(6)], [KeyModifiers::SUPER, KeyCode::Char('8'), ActivateTab(7)], - [KeyModifiers::SUPER, KeyCode::Char('9'), ActivateTab(8)], + [KeyModifiers::SUPER, KeyCode::Char('9'), ActivateTab(-1)], [KeyModifiers::SUPER, KeyCode::Char('w'), CloseCurrentTab], [ctrl_shift, KeyCode::Char('1'), ActivateTab(0)], [ctrl_shift, KeyCode::Char('2'), ActivateTab(1)], @@ -217,7 +217,7 @@ impl InputMap { [ctrl_shift, KeyCode::Char('6'), ActivateTab(5)], [ctrl_shift, KeyCode::Char('7'), ActivateTab(6)], [ctrl_shift, KeyCode::Char('8'), ActivateTab(7)], - [ctrl_shift, KeyCode::Char('9'), ActivateTab(8)], + [ctrl_shift, KeyCode::Char('9'), ActivateTab(-1)], [ctrl_shift, KeyCode::Char('W'), CloseCurrentTab], [ KeyModifiers::SUPER | KeyModifiers::SHIFT,