diff --git a/config/src/keyassignment.rs b/config/src/keyassignment.rs index 7208319be..ee2872ed9 100644 --- a/config/src/keyassignment.rs +++ b/config/src/keyassignment.rs @@ -440,6 +440,8 @@ pub enum CopyModeAssignment { MoveToEndOfLineContent, MoveToStartOfLine, MoveToStartOfNextLine, + MoveToSelectionOtherEnd, + MoveToSelectionOtherEndHoriz, MoveBackwardWord, MoveForwardWord, MoveRight, diff --git a/docs/copymode.md b/docs/copymode.md index ff669189b..bfcfaadf5 100644 --- a/docs/copymode.md +++ b/docs/copymode.md @@ -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"}}, diff --git a/wezterm-gui/src/overlay/copy.rs b/wezterm-gui/src/overlay/copy.rs index 364e6186a..f60ddca32 100644 --- a/wezterm-gui/src/overlay/copy.rs +++ b/wezterm-gui/src/overlay/copy.rs @@ -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 }); }