diff --git a/config/src/keyassignment.rs b/config/src/keyassignment.rs index ff7fca0e7..31eb8cff7 100644 --- a/config/src/keyassignment.rs +++ b/config/src/keyassignment.rs @@ -160,6 +160,7 @@ pub enum KeyAssignment { PastePrimarySelection, PasteFrom(ClipboardPasteSource), ActivateTabRelative(isize), + ActivateTabRelativeNoWrap(isize), IncreaseFontSize, DecreaseFontSize, ResetFontSize, diff --git a/docs/changelog.md b/docs/changelog.md index c07e30fab..7e64d2fd8 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -19,6 +19,7 @@ As features stabilize some brief notes about them will accumulate here. * [default_gui_startup_args](config/lua/config/default_gui_startup_args.md) allows defaulting to starting the ssh client (for example). [#1030](https://github.com/wez/wezterm/issues/1030) * [mux-is-process-stateful](config/lua/mux-events/mux-is-process-stateful.md) event for finer control over prompting when closing panes. [#1412](https://github.com/wez/wezterm/issues/1412) * [harfbuzz_features](config/font-shaping.md), [freetype_load_target](config/lua/config/freetype_load_target.md), [freetype_render_target](config/lua/config/freetype_render_target.md) and [freetype_load_flags](config/lua/config/freetype_load_flags.md) can now be overridden on a per-font basis as described in [wezterm.font](config/lua/wezterm/font.md) and [wezterm.font_with_fallback](config/lua/wezterm/font_with_fallback.md). +* [ActivateTabRelativeNoWrap](config/lua/keyassignment/ActivateTabRelativeNoWrap.md) key assignment [#1414](https://github.com/wez/wezterm/issues/1414) #### Changed diff --git a/docs/config/lua/keyassignment/ActivateTabRelative.md b/docs/config/lua/keyassignment/ActivateTabRelative.md index 6f600bc45..455cccff3 100644 --- a/docs/config/lua/keyassignment/ActivateTabRelative.md +++ b/docs/config/lua/keyassignment/ActivateTabRelative.md @@ -8,10 +8,12 @@ activates the tab to the right. local wezterm = require 'wezterm'; return { keys = { - {key="{", mods="SHIFT|ALT", action=wezterm.action{ActivateTabRelative=-1}}, - {key="}", mods="SHIFT|ALT", action=wezterm.action{ActivateTabRelative=1}}, + {key="{", mods="ALT", action=wezterm.action{ActivateTabRelative=-1}}, + {key="}", mods="ALT", action=wezterm.action{ActivateTabRelative=1}}, } } ``` +See also [ActivateTabRelativeNoWrap](ActivateTabRelativeNoWrap.md) + diff --git a/docs/config/lua/keyassignment/ActivateTabRelativeNoWrap.md b/docs/config/lua/keyassignment/ActivateTabRelativeNoWrap.md new file mode 100644 index 000000000..8ca82fc41 --- /dev/null +++ b/docs/config/lua/keyassignment/ActivateTabRelativeNoWrap.md @@ -0,0 +1,24 @@ +# ActivateTabRelativeNoWrap + +*Since: nightly builds only* + +Activate a tab relative to the current tab. The argument value specifies an +offset. eg: `-1` activates the tab to the left of the current tab, while `1` +activates the tab to the right. + +This is almost identical to [ActivateTabRelative](ActivateTabRelative.md) +but this one will not wrap around; for example, if the first tab is active +`ActivateTabRelativeNoWrap=-1` will not move to the last tab and vice versa. + + +```lua +local wezterm = require 'wezterm'; +return { + keys = { + {key="{", mods="ALT", action=wezterm.action{ActivateTabRelativeNoWrap=-1}}, + {key="}", mods="ALT", action=wezterm.action{ActivateTabRelativeNoWrap=1}}, + } +} +``` + + diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index a51331a70..ff58aaa9d 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -1502,7 +1502,7 @@ impl TermWindow { Ok(()) } - fn activate_tab_relative(&mut self, delta: isize) -> anyhow::Result<()> { + fn activate_tab_relative(&mut self, delta: isize, wrap: bool) -> anyhow::Result<()> { let mux = Mux::get().unwrap(); let window = mux .get_window(self.mux_window_id) @@ -1513,9 +1513,20 @@ impl TermWindow { let active = window.get_active_idx() as isize; let tab = active + delta; - let tab = if tab < 0 { max as isize + tab } else { tab }; + let tab = if wrap { + let tab = if tab < 0 { max as isize + tab } else { tab }; + (tab as usize % max) as isize + } else { + if tab < 0 { + 0 + } else if tab >= max as isize { + max as isize - 1 + } else { + tab + } + }; drop(window); - self.activate_tab((tab as usize % max) as isize) + self.activate_tab(tab) } fn activate_last_tab(&mut self) -> anyhow::Result<()> { @@ -1833,7 +1844,10 @@ impl TermWindow { self.paste_from_clipboard(pane, *source); } ActivateTabRelative(n) => { - self.activate_tab_relative(*n)?; + self.activate_tab_relative(*n, true)?; + } + ActivateTabRelativeNoWrap(n) => { + self.activate_tab_relative(*n, false)?; } ActivateLastTab => self.activate_last_tab()?, DecreaseFontSize => { @@ -2108,7 +2122,7 @@ impl TermWindow { drop(win); mux.remove_tab(tab.tab_id()); } - self.activate_tab_relative(0) + self.activate_tab_relative(0, true) } pub fn pane_state(&self, pane_id: PaneId) -> RefMut {