1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-27 15:37:29 +03:00

new ActivateTabRelativeNoWrap key assignment

refs: #1414
This commit is contained in:
Wez Furlong 2021-12-23 09:32:49 -07:00
parent 3856a61527
commit 6a265d9f72
5 changed files with 49 additions and 7 deletions

View File

@ -160,6 +160,7 @@ pub enum KeyAssignment {
PastePrimarySelection,
PasteFrom(ClipboardPasteSource),
ActivateTabRelative(isize),
ActivateTabRelativeNoWrap(isize),
IncreaseFontSize,
DecreaseFontSize,
ResetFontSize,

View File

@ -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

View File

@ -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)

View File

@ -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}},
}
}
```

View File

@ -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<PaneState> {