Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QuickSelectArgs: optionally bypass custom action on paste #6405

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion config/src/keyassignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,13 @@ pub struct QuickSelectArguments {
pub patterns: Vec<String>,
#[dynamic(default)]
pub action: Option<Box<KeyAssignment>>,
/// 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<usize>,
}
Expand Down
2 changes: 2 additions & 0 deletions docs/config/lua/keyassignment/QuickSelectArgs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/quickselect.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
5 changes: 4 additions & 1 deletion wezterm-gui/src/overlay/quickselect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down