From d361b8a7c51a45f8fa29731a0bfce3a6833ff758 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 30 May 2020 06:54:34 -0700 Subject: [PATCH] wezterm: add DisableDefaultAssignment action Similar to Nop but allows the key press to pass through to the underlying tab. Expand docs to clarify how these two actions work. --- docs/config/keys.markdown | 26 +++++++++++++++++++++----- src/frontend/gui/termwindow.rs | 2 +- src/keyassignment.rs | 10 +++++++--- src/mux/tab.rs | 2 +- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/docs/config/keys.markdown b/docs/config/keys.markdown index 5cb874274..a238ca1ed 100644 --- a/docs/config/keys.markdown +++ b/docs/config/keys.markdown @@ -415,16 +415,32 @@ return { } ``` -## Nop +## DisableDefaultAssignment -Does nothing. This is useful to disable a default key assignment. +Has no special meaning of its own; this action will undo the registration +of a default assignment if that key/mouse/modifier combination is one of the +default assignments and cause the key press to be propagated through +to the tab for processing. ```lua -local wezterm = require 'wezterm'; - return { keys = { - -- Turn off the default CMD-m Hide action + -- Turn off the default CMD-m Hide action, allowing CMD-m to + -- be potentially recognized and handled by the tab + {key="m", mods="CMD", action="DisableDefaultAssignment"}, + } +} +``` + +## Nop + +Causes the key press to have no effect; it behaves as though those +keys were not pressed. + +```lua +return { + keys = { + -- Turn off any side effects from pressing CMD-m {key="m", mods="CMD", action="Nop"}, } } diff --git a/src/frontend/gui/termwindow.rs b/src/frontend/gui/termwindow.rs index accc62c3e..f0d951401 100644 --- a/src/frontend/gui/termwindow.rs +++ b/src/frontend/gui/termwindow.rs @@ -1444,7 +1444,7 @@ impl TermWindow { } } CloseCurrentTab => self.close_current_tab(), - Nop => {} + Nop | DisableDefaultAssignment => {} ReloadConfiguration => crate::config::reload(), MoveTab(n) => self.move_tab(*n)?, MoveTabRelative(n) => self.move_tab_relative(*n)?, diff --git a/src/keyassignment.rs b/src/keyassignment.rs index 6c33fc77d..f7c7a3892 100644 --- a/src/keyassignment.rs +++ b/src/keyassignment.rs @@ -24,7 +24,7 @@ pub enum MouseEventTrigger { /// When spawning a tab, specify which domain should be used to /// host/spawn that tab. -#[derive(Debug, Clone, Deserialize, Serialize)] +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] pub enum SpawnTabDomain { /// Use the default domain DefaultDomain, @@ -42,7 +42,7 @@ impl Default for SpawnTabDomain { } } -#[derive(Default, Debug, Clone, Deserialize, Serialize)] +#[derive(Default, Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] pub struct SpawnCommand { /// Optional descriptive label pub label: Option, @@ -70,7 +70,7 @@ pub struct SpawnCommand { pub domain: SpawnTabDomain, } -#[derive(Debug, Clone, Deserialize, Serialize)] +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] pub enum KeyAssignment { SpawnTab(SpawnTabDomain), SpawnWindow, @@ -85,6 +85,7 @@ pub enum KeyAssignment { ActivateTab(usize), SendString(String), Nop, + DisableDefaultAssignment, Hide, Show, CloseCurrentTab, @@ -343,6 +344,9 @@ impl InputMap { ); } + keys.retain(|_, v| *v != KeyAssignment::DisableDefaultAssignment); + mouse.retain(|_, v| *v != KeyAssignment::DisableDefaultAssignment); + Self { keys, mouse } } diff --git a/src/mux/tab.rs b/src/mux/tab.rs index 986dbeb91..11ba8c785 100644 --- a/src/mux/tab.rs +++ b/src/mux/tab.rs @@ -45,7 +45,7 @@ fn schedule_next_paste(paste: &Arc>) { }); } -#[derive(Debug, Clone, Deserialize, Serialize)] +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] pub enum Pattern { CaseSensitiveString(String), CaseInSensitiveString(String),