From 192711cc6cd2b531f0c88d544768e7248ef717e9 Mon Sep 17 00:00:00 2001 From: nhurlock Date: Sat, 16 Nov 2024 22:12:20 -0500 Subject: [PATCH] QuickSelectArgs: optionally bypass performing action on paste --- config/src/keyassignment.rs | 5 ++++- docs/config/lua/keyassignment/QuickSelectArgs.md | 2 ++ docs/quickselect.md | 2 +- wezterm-gui/src/overlay/quickselect.rs | 5 ++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/config/src/keyassignment.rs b/config/src/keyassignment.rs index c273182caa4..405e7afc63a 100644 --- a/config/src/keyassignment.rs +++ b/config/src/keyassignment.rs @@ -446,10 +446,13 @@ pub struct QuickSelectArguments { pub patterns: Vec, #[dynamic(default)] pub action: Option>, + /// Call `action` after paste is performed (capital selection) + #[dynamic(default = "default_true")] + pub paste_performs_action: bool, /// Label to use in place of "copy" when `action` is set #[dynamic(default)] pub label: String, - /// How man lines before and how many lines after the viewport to + /// How many lines before and how many lines after the viewport to /// search to produce the quickselect results pub scope_lines: Option, } diff --git a/docs/config/lua/keyassignment/QuickSelectArgs.md b/docs/config/lua/keyassignment/QuickSelectArgs.md index ac87f4f117d..ccfdfcce90d 100644 --- a/docs/config/lua/keyassignment/QuickSelectArgs.md +++ b/docs/config/lua/keyassignment/QuickSelectArgs.md @@ -31,6 +31,7 @@ The `QuickSelectArgs` struct allows for the following fields: * `patterns` - if present, completely overrides the normal set of patterns and uses only the patterns specified * `alphabet` - if present, this alphabet is used instead of [quick_select_alphabet](../config/quick_select_alphabet.md) * `action` - if present, this key assignment action is performed as if by [window:perform_action](../window/perform_action.md) when an item is selected. The normal clipboard action is NOT performed in this case. +* `paste_performs_action` - overrides whether `action` is performed after an item is selected using a capital value (when paste occurs). * `label` - if present, replaces the string `"copy"` that is shown at the bottom of the overlay; you can use this to indicate which action will happen if you are using `action`. * `scope_lines` - Specify the number of lines to search above and below the current viewport. The default is 1000 lines. The scope will be increased to the current viewport height if it is smaller than the viewport. {{since('20220807-113146-c2fee766', inline=True)}}. In earlier releases, the entire scrollback was always searched). @@ -50,6 +51,7 @@ config.keys = { patterns = { 'https?://\\S+', }, + paste_performs_action = false, action = wezterm.action_callback(function(window, pane) local url = window:get_selection_text_for_pane(pane) wezterm.log_info('opening: ' .. url) diff --git a/docs/quickselect.md b/docs/quickselect.md index c5241b8d3de..ee76b8739a8 100644 --- a/docs/quickselect.md +++ b/docs/quickselect.md @@ -23,7 +23,7 @@ do next; typing in a highlighted prefix will cause that text to be selected and copied to the clipboard, and quick select mode will be cancelled. Typing in the uppercase form of the prefix will copy AND paste the highlighted -text, and cancel quick select mod. +text, and cancel quick select mode. Pressing `ESCAPE` will cancel quick select mode. diff --git a/wezterm-gui/src/overlay/quickselect.rs b/wezterm-gui/src/overlay/quickselect.rs index db631fbe897..eb3329ec212 100644 --- a/wezterm-gui/src/overlay/quickselect.rs +++ b/wezterm-gui/src/overlay/quickselect.rs @@ -914,6 +914,7 @@ impl QuickSelectRenderable { let pane_id = self.delegate.pane_id(); let action = self.args.action.clone(); + let paste_performs_action = self.args.paste_performs_action; self.window .notify(TermWindowNotif::Apply(Box::new(move |term_window| { let mux = mux::Mux::get(); @@ -942,7 +943,9 @@ impl QuickSelectRenderable { let _ = pane.send_paste(&text); } if let Some(action) = action { - let _ = term_window.perform_key_assignment(&pane, &action); + if !paste || paste_performs_action { + let _ = term_window.perform_key_assignment(&pane, &action); + } } else { term_window.copy_to_clipboard( ClipboardCopyDestination::ClipboardAndPrimarySelection,