Add a CloseWithoutClear copy mode key assignment (#4924)

* 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
This commit is contained in:
Leszek Swirski authored and GitHub committed 2024-07-22 08:06:54 -07:00
1 parent 574e0221fa
commit fef52df952
2 files changed
+29 -10

No files matched your search

@@ -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',
@@ -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',
@@ -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' },
@@ -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',
@@ -189,6 +201,7 @@ return {
mods = 'NONE',
action = act.Multiple {
{ CopyTo = 'ClipboardAndPrimarySelection' },
{ CopyMode = 'ScrollToBottom' },
{ CopyMode = 'Close' },
},
},
+12 -6
View File
@@ -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());
}
@@ -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'),
@@ -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(),
]),
),
(