Skip to content

Commit

Permalink
Add a CloseWithoutClear copy mode key assignment (#4924)
Browse files Browse the repository at this point in the history
* Add a CloseWithoutClear copy mode key assignment

Closing the copy overlay currently unconditionally clears the viewport,
in particular resetting scroll. For the search overlay, we don't
necessarily want to scroll back to the prompt after finding a match --
indeed, the old search overlay (which didn't use copy mode) had this
behaviour.

Add a CloseWithoutClear key assignment which has this desired behaviour,
and make it the default for ESC in search mode.

* Change CloseWithoutClear into normal Close, and add ResetViewport

* Remove ResetViewport, add helper for keys
  • Loading branch information
LeszekSwirski authored Jul 22, 2024
1 parent 574e022 commit fef52df
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
21 changes: 17 additions & 4 deletions docs/examples/default-copy-mode-key-table.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ return {
mods = 'NONE',
action = act.CopyMode 'MoveToStartOfNextLine',
},
{ key = 'Escape', mods = 'NONE', action = act.CopyMode 'Close' },
{ key = 'Escape', mods = 'NONE', action = act.Multiple {
{ CopyMode = 'ScrollToBottom' },
{ CopyMode = 'Close' },
} },
{
key = 'Space',
mods = 'NONE',
Expand Down Expand Up @@ -124,7 +127,10 @@ return {
{ key = 'b', mods = 'NONE', action = act.CopyMode 'MoveBackwardWord' },
{ key = 'b', mods = 'ALT', action = act.CopyMode 'MoveBackwardWord' },
{ key = 'b', mods = 'CTRL', action = act.CopyMode 'PageUp' },
{ key = 'c', mods = 'CTRL', action = act.CopyMode 'Close' },
{ key = 'c', mods = 'CTRL', action = act.Multiple {
{ CopyMode = 'ScrollToBottom' },
{ CopyMode = 'Close' },
} },
{
key = 'd',
mods = 'CTRL',
Expand All @@ -147,7 +153,10 @@ return {
mods = 'NONE',
action = act.CopyMode 'MoveToScrollbackTop',
},
{ key = 'g', mods = 'CTRL', action = act.CopyMode 'Close' },
{ key = 'g', mods = 'CTRL', action = act.Multiple {
{ CopyMode = 'ScrollToBottom' },
{ CopyMode = 'Close' },
} },
{ key = 'h', mods = 'NONE', action = act.CopyMode 'MoveLeft' },
{ key = 'j', mods = 'NONE', action = act.CopyMode 'MoveDown' },
{ key = 'k', mods = 'NONE', action = act.CopyMode 'MoveUp' },
Expand All @@ -162,7 +171,10 @@ return {
mods = 'NONE',
action = act.CopyMode 'MoveToSelectionOtherEnd',
},
{ key = 'q', mods = 'NONE', action = act.CopyMode 'Close' },
{ key = 'q', mods = 'NONE', action = act.Multiple {
{ CopyMode = 'ScrollToBottom' },
{ CopyMode = 'Close' },
} },
{
key = 't',
mods = 'NONE',
Expand All @@ -189,6 +201,7 @@ return {
mods = 'NONE',
action = act.Multiple {
{ CopyTo = 'ClipboardAndPrimarySelection' },
{ CopyMode = 'ScrollToBottom' },
{ CopyMode = 'Close' },
},
},
Expand Down
18 changes: 12 additions & 6 deletions wezterm-gui/src/overlay/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ impl CopyRenderable {
}

fn close(&self) {
self.set_viewport(None);
TermWindow::schedule_cancel_overlay_for_pane(self.window.clone(), self.delegate.pane_id());
}

Expand Down Expand Up @@ -1684,28 +1683,35 @@ pub fn search_key_table() -> KeyTable {
table
}

fn scroll_to_bottom_and_close() -> KeyAssignment {
KeyAssignment::Multiple(vec![
KeyAssignment::ScrollToBottom,
KeyAssignment::CopyMode(CopyModeAssignment::Close),
])
}

pub fn copy_key_table() -> KeyTable {
let mut table = KeyTable::default();
for (key, mods, action) in [
(
WKeyCode::Char('c'),
Modifiers::CTRL,
KeyAssignment::CopyMode(CopyModeAssignment::Close),
scroll_to_bottom_and_close(),
),
(
WKeyCode::Char('g'),
Modifiers::CTRL,
KeyAssignment::CopyMode(CopyModeAssignment::Close),
scroll_to_bottom_and_close(),
),
(
WKeyCode::Char('q'),
Modifiers::NONE,
KeyAssignment::CopyMode(CopyModeAssignment::Close),
scroll_to_bottom_and_close(),
),
(
WKeyCode::Char('\x1b'),
Modifiers::NONE,
KeyAssignment::CopyMode(CopyModeAssignment::Close),
scroll_to_bottom_and_close(),
),
(
WKeyCode::Char('h'),
Expand Down Expand Up @@ -1957,7 +1963,7 @@ pub fn copy_key_table() -> KeyTable {
Modifiers::NONE,
KeyAssignment::Multiple(vec![
KeyAssignment::CopyTo(ClipboardCopyDestination::ClipboardAndPrimarySelection),
KeyAssignment::CopyMode(CopyModeAssignment::Close),
scroll_to_bottom_and_close(),
]),
),
(
Expand Down

0 comments on commit fef52df

Please sign in to comment.