1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-27 12:23:46 +03:00

Add SwitchWorkspaceRelative key assignment

This commit is contained in:
Wez Furlong 2022-01-17 09:54:11 -07:00
parent 8d3d3e02a7
commit db8f588c5e
4 changed files with 49 additions and 1 deletions

View File

@ -346,6 +346,7 @@ pub enum KeyAssignment {
name: Option<String>,
spawn: Option<SpawnCommand>,
},
SwitchWorkspaceRelative(isize),
}
impl_lua_conversion!(KeyAssignment);

View File

@ -22,7 +22,7 @@ As features stabilize some brief notes about them will accumulate here.
* `Symbols Nerd Font Mono` is now bundled with WezTerm and is included as a default fallback font. This means that you may use any of the glyphs available in the [Nerd Fonts](https://github.com/ryanoasis/nerd-fonts) collection with any font without patching fonts and without explicitly adding that font to your fallback list. Pomicons have an unclear license for distribution and are excluded from this bundled font, however, you may manually install the font with those icons from the Nerd Font site itself and it will take precedence over the bundled font. This font replaces the older `PowerlineExtraSymbols` font. [#1521](https://github.com/wez/wezterm/issues/1521).
* [wezterm.nerdfonts](config/lua/wezterm/nerdfonts.md) as a convenient way to resolve Nerd Fonts glyphs by name in your config file
* [ShowLauncherArgs](config/lua/keyassignment/ShowLauncherArgs.md) key assignment to show the launcher scoped to certain items, or to launch it directly in fuzzy matching mode
* Workspaces. Follow work in progress on [#1531](https://github.com/wez/wezterm/issues/1531) and [#1322](https://github.com/wez/wezterm/discussions/1322)! [window:active_workspace()](config/lua/window/active_workspace.md) [default_workspace](config/lua/config/default_workspace.md)
* Workspaces. Follow work in progress on [#1531](https://github.com/wez/wezterm/issues/1531) and [#1322](https://github.com/wez/wezterm/discussions/1322)! [window:active_workspace()](config/lua/window/active_workspace.md) [default_workspace](config/lua/config/default_workspace.md) [SwitchWorkspaceRelative](config/lua/keyassignment/SwitchWorkspaceRelative.md)
#### Changed

View File

@ -0,0 +1,31 @@
# SwitchWorkspaceRelative
*Since: nightly builds only*
Switch to the workspace relative to the current workspace. Workspaces are ordered
lexicographically based on their names.
The argument value specifies an offset. eg: `-1` switches to the workspace
immediately prior to the current workspace, while `1` switches to the workspace
immediately following the current workspace.
This example binds CTRL-N and CTRL-P to move forwards, backwards through workspaces.
It shows the active workspace in the title bar. The launcher menu can be used
to create workspaces.
```lua
local wezterm = require 'wezterm'
wezterm.on("update-right-status", function(window, pane)
window:set_right_status(window:active_workspace())
end)
return {
keys = {
{key="9", mods="ALT", action=wezterm.action{ShowLauncherArgs={flags="FUZZY|WORKSPACES"}}},
{key="n", mods="CTRL", action=wezterm.action{SwitchWorkspaceRelative=1}},
{key="p", mods="CTRL", action=wezterm.action{SwitchWorkspaceRelative=-1}},
},
}
```

View File

@ -2100,6 +2100,22 @@ impl TermWindow {
};
tab.toggle_zoom();
}
SwitchWorkspaceRelative(delta) => {
let mux = Mux::get().unwrap();
let workspace = mux.active_workspace();
let workspaces = mux.iter_workspaces();
let idx = workspaces.iter().position(|w| *w == workspace).unwrap_or(0);
let new_idx = idx as isize + delta;
let new_idx = if new_idx < 0 {
workspaces.len() as isize + new_idx
} else {
new_idx
};
let new_idx = new_idx as usize % workspaces.len();
if let Some(w) = workspaces.get(new_idx) {
front_end().switch_workspace(w);
}
}
SwitchToWorkspace { name, spawn } => {
let activity = crate::Activity::new();
let mux = Mux::get().unwrap();