1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-11 22:37:11 +03:00

Implement o & O to move cursor to other end of selection in copy mode

This commit is contained in:
Benoit de Chezelles 2022-06-21 01:32:51 +02:00 committed by Wez Furlong
parent 55e63d867b
commit 097abc4fe8
3 changed files with 54 additions and 0 deletions

View File

@ -440,6 +440,8 @@ pub enum CopyModeAssignment {
MoveToEndOfLineContent,
MoveToStartOfLine,
MoveToStartOfNextLine,
MoveToSelectionOtherEnd,
MoveToSelectionOtherEndHoriz,
MoveBackwardWord,
MoveForwardWord,
MoveRight,

View File

@ -64,6 +64,8 @@ reassignable.
| | `CTRL-b` |
| Move down one screen | `PageDown` |
| | `CTRL-f` |
| Move to other end of the selection| `o` |
| Move to other end of the selection horizontaly| `O` (only in Rectangular mode) |
### Configurable Key Assignments
@ -131,6 +133,10 @@ return {
{key="L", mods="NONE", action=wezterm.action{CopyMode="MoveToViewportBottom"}},
{key="L", mods="SHIFT", action=wezterm.action{CopyMode="MoveToViewportBottom"}},
{key="o", mods="NONE", action=wezterm.action{CopyMode="MoveToSelectionOtherEnd"}},
{key="O", mods="NONE", action=wezterm.action{CopyMode="MoveToSelectionOtherEndHoriz"}},
{key="O", mods="SHIFT", action=wezterm.action{CopyMode="MoveToSelectionOtherEndHoriz"}},
{key="PageUp", mods="NONE", action=wezterm.action{CopyMode="PageUp"}},
{key="PageDown", mods="NONE", action=wezterm.action{CopyMode="PageDown"}},

View File

@ -591,6 +591,35 @@ impl CopyRenderable {
self.select_to_cursor_pos();
}
fn move_to_selection_other_end(&mut self) {
if let Some(old_start) = self.start {
// Swap cursor & start of selection
self.start.replace(SelectionCoordinate {
x: self.cursor.x,
y: self.cursor.y,
});
self.cursor.x = old_start.x;
self.cursor.y = old_start.y;
self.select_to_cursor_pos();
}
}
fn move_to_selection_other_end_horiz(&mut self) {
if self.selection_mode != SelectionMode::Block {
// This action makes sense ONLY in block mode
return;
}
if let Some(old_start) = self.start {
// Swap X coordinate of cursor & start of selection
self.start.replace(SelectionCoordinate {
x: self.cursor.x,
y: old_start.y,
});
self.cursor.x = old_start.x;
self.select_to_cursor_pos();
}
}
fn move_backward_one_word(&mut self) {
let y = if self.cursor.x == 0 && self.cursor.y > 0 {
self.cursor.x = usize::max_value();
@ -787,6 +816,8 @@ impl Pane for CopyOverlay {
MoveToEndOfLineContent => render.move_to_end_of_line_content(),
MoveToStartOfLine => render.move_to_start_of_line(),
MoveToStartOfNextLine => render.move_to_start_of_next_line(),
MoveToSelectionOtherEnd => render.move_to_selection_other_end(),
MoveToSelectionOtherEndHoriz => render.move_to_selection_other_end_horiz(),
MoveBackwardWord => render.move_backward_one_word(),
MoveForwardWord => render.move_forward_one_word(),
MoveRight => render.move_right_single_cell(),
@ -1239,6 +1270,21 @@ pub fn copy_key_table() -> KeyTable {
Modifiers::CTRL,
KeyAssignment::CopyMode(CopyModeAssignment::PageDown),
),
(
WKeyCode::Char('o'),
Modifiers::NONE,
KeyAssignment::CopyMode(CopyModeAssignment::MoveToSelectionOtherEnd),
),
(
WKeyCode::Char('O'),
Modifiers::NONE,
KeyAssignment::CopyMode(CopyModeAssignment::MoveToSelectionOtherEndHoriz),
),
(
WKeyCode::Char('O'),
Modifiers::SHIFT,
KeyAssignment::CopyMode(CopyModeAssignment::MoveToSelectionOtherEndHoriz),
),
] {
table.insert((key, mods), KeyTableEntry { action });
}