From 10121790df10fbc40896f567046b6fcd54c42bfb Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 29 Jul 2022 05:00:35 -0700 Subject: [PATCH] copy mode: pressing v while in v mode toggles off v mode. Add yank. refs: https://github.com/wez/wezterm/discussions/2246 refs: https://github.com/wez/wezterm/issues/993#issuecomment-1118512595 --- docs/changelog.md | 2 ++ wezterm-gui/src/overlay/copy.rs | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 96b7b5d0b..3dfa8ba6a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -48,6 +48,8 @@ As features stabilize some brief notes about them will accumulate here. * Improved search performance * Quickselect: now defaults to searching 1000 lines above and below the current viewport, making it faster and the labels shorter for users with a larger scrollback. A new `scope_lines` parameter to [QuickSelectArgs](config/lua/keyassignment/QuickSelectArgs.md) allows controlling the search region explicitly. Thanks to [@yyogo](https://github.com/yyogo) for the initial PR! [#1317](https://github.com/wez/wezterm/pull/1317) * OSC 10, 11 and 12 (Set Default Text Background, Default Text Foreground Color, and Text Cursor Color) now support setting the alpha component [#2313](https://github.com/wez/wezterm/issues/2313) +* Copy Mode: setting the same selection mode a second time will now toggle off that mode and clear the selection, preserving the current position [#2246](https://github.com/wez/wezterm/discussions/2246) +* Copy Mode: new default vim-style `y` "yank" key assignment will copy the selection and close copy mode #### Fixed * [ActivateKeyTable](config/lua/keyassignment/ActivateKeyTable.md)'s `replace_current` field was not actually optional. Made it optional. [#2179](https://github.com/wez/wezterm/issues/2179) diff --git a/wezterm-gui/src/overlay/copy.rs b/wezterm-gui/src/overlay/copy.rs index 1c1fc4ba0..9f9ae5e87 100644 --- a/wezterm-gui/src/overlay/copy.rs +++ b/wezterm-gui/src/overlay/copy.rs @@ -1,7 +1,8 @@ use crate::selection::{SelectionCoordinate, SelectionRange, SelectionX}; use crate::termwindow::{TermWindow, TermWindowNotif}; use config::keyassignment::{ - CopyModeAssignment, KeyAssignment, KeyTable, KeyTableEntry, ScrollbackEraseMode, SelectionMode, + ClipboardCopyDestination, CopyModeAssignment, KeyAssignment, KeyTable, KeyTableEntry, + ScrollbackEraseMode, SelectionMode, }; use mux::domain::DomainId; use mux::pane::{Pane, PaneId, Pattern, SearchResult}; @@ -767,11 +768,18 @@ impl CopyRenderable { match mode { None => { self.start.take(); + self.clear_selection(); } Some(mode) => { if self.start.is_none() { let coord = SelectionCoordinate::x_y(self.cursor.x, self.cursor.y); self.start.replace(coord); + } else if self.selection_mode == *mode { + // We have a selection and we're trying to set the same mode + // again; consider this to be a toggle that clears the selection + self.start.take(); + self.clear_selection(); + return; } self.selection_mode = *mode; self.select_to_cursor_pos(); @@ -1356,6 +1364,14 @@ pub fn copy_key_table() -> KeyTable { Modifiers::SHIFT, KeyAssignment::CopyMode(CopyModeAssignment::MoveToSelectionOtherEndHoriz), ), + ( + WKeyCode::Char('y'), + Modifiers::NONE, + KeyAssignment::Multiple(vec![ + KeyAssignment::CopyTo(ClipboardCopyDestination::ClipboardAndPrimarySelection), + KeyAssignment::CopyMode(CopyModeAssignment::Close), + ]), + ), ] { table.insert((key, mods), KeyTableEntry { action }); }