From fcc2b1ab7de853208693601bae6b879db3c4ec6f Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 22 Jun 2019 07:46:49 -0700 Subject: [PATCH] rejigger tab spawning hotkeys cmd-t now spawns in the same domain as the active tab, cmd-shift-t spawns in the default domain. It is possible to define bindings to spawn in an arbitrary domain. --- README.md | 15 +++++++++++++-- src/config.rs | 14 ++++++++++++-- src/frontend/guicommon/host.rs | 24 ++++++++++++++---------- src/frontend/guicommon/window.rs | 1 - 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 6d9b24f21..394c2a493 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,8 @@ The default key bindings are: | `CTRL` | `=` | `IncreaseFontSize` | | `SUPER` | `0` | `ResetFontSize` | | `CTRL` | `0` | `ResetFontSize` | -| `SUPER` | `t` | `SpawnTab` | +| `SUPER` | `t` | `SpawnTabInCurrentTabDomain` | +| `SUPER|SHIFT` | `T` | `SpawnTab` | | `SUPER` | `w` | `CloseCurrentTab` | | `SUPER` | `1` | `ActivateTab(0)` | | `SUPER` | `2` | `ActivateTab(1)` | @@ -205,7 +206,9 @@ specified via the `arg` key; see examples below. | Name | Effect | | ------------------ | ------------------ | -| `SpawnTab` | Create a new tab in the current window | +| `SpawnTab` | Create a new local tab in the current window | +| `SpawnTabInCurrentTabDomain` | Create a new tab in the current window. The tab will be spawned in the same domain as the currently active tab | +| `SpawnTabInDomain` | Create a new tab in the current window. The tab will be spawned in the domain specified by the `arg` value | | `SpawnWindow` | Create a new window | | `ToggleFullScreen` | Toggles full screen mode for current window | | `Paste` | Paste the clipboard to the current tab | @@ -244,6 +247,14 @@ mods = "CTRL|ALT" action = "ActivateTab" # the tab number arg = "0" + +# CMD+y spawns a new tab in Domain 1 +[[keys]] +key = "y" +mods = "CMD" +action = "SpawnTabInDomain" +# the domain ID +arg = "1" ``` ### Colors diff --git a/src/config.rs b/src/config.rs index 9ae3da1c0..04df9af16 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,6 +2,7 @@ use crate::font::FontSystemSelection; use crate::frontend::guicommon::host::KeyAssignment; +use crate::frontend::guicommon::window::SpawnTabDomain; use crate::frontend::FrontEndSelection; use crate::get_shell; use failure::{bail, err_msg, format_err, Error, Fallible}; @@ -174,8 +175,16 @@ impl std::convert::TryInto for &Key { type Error = Error; fn try_into(self) -> Result { Ok(match self.action { - KeyAction::SpawnTab => KeyAssignment::SpawnTab, - KeyAction::SpawnTabInCurrentTabDomain => KeyAssignment::SpawnTabInCurrentTabDomain, + KeyAction::SpawnTab => KeyAssignment::SpawnTab(SpawnTabDomain::DefaultDomain), + KeyAction::SpawnTabInCurrentTabDomain => { + KeyAssignment::SpawnTab(SpawnTabDomain::CurrentTabDomain) + } + KeyAction::SpawnTabInDomain => KeyAssignment::SpawnTab(SpawnTabDomain::Domain( + self.arg + .as_ref() + .ok_or_else(|| format_err!("missing arg for {:?}", self))? + .parse()?, + )), KeyAction::SpawnWindow => KeyAssignment::SpawnWindow, KeyAction::ToggleFullScreen => KeyAssignment::ToggleFullScreen, KeyAction::Copy => KeyAssignment::Copy, @@ -213,6 +222,7 @@ impl std::convert::TryInto for &Key { pub enum KeyAction { SpawnTab, SpawnTabInCurrentTabDomain, + SpawnTabInDomain, SpawnWindow, ToggleFullScreen, Copy, diff --git a/src/frontend/guicommon/host.rs b/src/frontend/guicommon/host.rs index 427558e78..9f3aa775d 100644 --- a/src/frontend/guicommon/host.rs +++ b/src/frontend/guicommon/host.rs @@ -20,10 +20,7 @@ use termwiz::hyperlink::Hyperlink; #[derive(Debug, Clone)] pub enum KeyAssignment { - /// Spawn a tab in the default domain - SpawnTab, - /// Spawn a tab in whichever domain the current tab belongs - SpawnTabInCurrentTabDomain, + SpawnTab(SpawnTabDomain), SpawnWindow, ToggleFullScreen, Copy, @@ -133,7 +130,16 @@ fn key_bindings() -> KeyMap { [KeyModifiers::SUPER, KeyCode::Char('0'), ResetFontSize], [KeyModifiers::CTRL, KeyCode::Char('0'), ResetFontSize], // Tab navigation and management - [KeyModifiers::SUPER, KeyCode::Char('t'), SpawnTab], + [ + KeyModifiers::SUPER, + KeyCode::Char('t'), + SpawnTab(SpawnTabDomain::DefaultDomain) + ], + [ + KeyModifiers::SUPER | KeyModifiers::SHIFT, + KeyCode::Char('T'), + SpawnTab(SpawnTabDomain::CurrentTabDomain) + ], [KeyModifiers::SUPER, KeyCode::Char('w'), CloseCurrentTab], [KeyModifiers::SUPER, KeyCode::Char('1'), ActivateTab(0)], [KeyModifiers::SUPER, KeyCode::Char('2'), ActivateTab(1)], @@ -206,11 +212,9 @@ impl HostImpl { ) -> Fallible<()> { use KeyAssignment::*; match assignment { - SpawnTab => { - self.with_window(|win| win.spawn_tab(SpawnTabDomain::DefaultDomain).map(|_| ())) - } - SpawnTabInCurrentTabDomain => { - self.with_window(|win| win.spawn_tab(SpawnTabDomain::CurrentTabDomain).map(|_| ())) + SpawnTab(spawn_where) => { + let spawn_where = *spawn_where; + self.with_window(move |win| win.spawn_tab(spawn_where).map(|_| ())) } SpawnWindow => self.spawn_new_window(), ToggleFullScreen => self.toggle_full_screen(), diff --git a/src/frontend/guicommon/window.rs b/src/frontend/guicommon/window.rs index fdee5ba36..b5bfa4a68 100644 --- a/src/frontend/guicommon/window.rs +++ b/src/frontend/guicommon/window.rs @@ -22,7 +22,6 @@ pub enum SpawnTabDomain { /// Use the domain from the current tab in the associated window CurrentTabDomain, /// Use a specific domain - #[allow(dead_code)] Domain(DomainId), }