Skip to content

Commit

Permalink
Implement ReedlineEvent::ResetSelection
Browse files Browse the repository at this point in the history
  • Loading branch information
who committed Jan 1, 2025
1 parent 5abfa17 commit f033574
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/core_editor/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,10 @@ impl Editor {
self.delete_selection();
insert_clipboard_content_before(&mut self.line_buffer, self.cut_buffer.deref_mut());
}

pub(crate) fn reset_selection(&mut self) {
self.selection_anchor = None;
}
}

fn insert_clipboard_content_before(line_buffer: &mut LineBuffer, clipboard: &mut dyn Clipboard) {
Expand Down
12 changes: 2 additions & 10 deletions src/edit_mode/vi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,7 @@ impl EditMode for Vi {
self.cache.clear();
self.mode = ViMode::Normal;
ReedlineEvent::Multiple(vec![
// Move left then right to clear the selection.
// Order matters here: this makes sure cursor does not move at end of line
ReedlineEvent::Edit(vec![
EditCommand::MoveLeft { select: false },
EditCommand::MoveRight { select: false },
]),
ReedlineEvent::ResetSelection,
ReedlineEvent::Esc,
ReedlineEvent::Repaint,
])
Expand Down Expand Up @@ -201,10 +196,7 @@ mod test {
assert_eq!(
result,
ReedlineEvent::Multiple(vec![
ReedlineEvent::Edit(vec![
EditCommand::MoveLeft { select: false },
EditCommand::MoveRight { select: false }
]),
ReedlineEvent::ResetSelection,
ReedlineEvent::Esc,
ReedlineEvent::Repaint
])
Expand Down
8 changes: 8 additions & 0 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,10 @@ impl Reedline {
self.input_mode = InputMode::Regular;
Ok(EventStatus::Handled)
}
ReedlineEvent::ResetSelection => {
self.editor.reset_selection();
Ok(EventStatus::Handled)
}
// TODO: Check if events should be handled
ReedlineEvent::Right
| ReedlineEvent::Left
Expand Down Expand Up @@ -1197,6 +1201,10 @@ impl Reedline {
Ok(EventStatus::Handled)
}
ReedlineEvent::OpenEditor => self.open_editor().map(|_| EventStatus::Handled),
ReedlineEvent::ResetSelection => {
self.editor.reset_selection();
Ok(EventStatus::Handled)
}
ReedlineEvent::Resize(width, height) => {
self.painter.handle_resize(width, height);
Ok(EventStatus::Handled)
Expand Down
4 changes: 4 additions & 0 deletions src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,9 @@ pub enum ReedlineEvent {

/// Open text editor
OpenEditor,

/// Reset the current text selection
ResetSelection,
}

impl Display for ReedlineEvent {
Expand Down Expand Up @@ -687,6 +690,7 @@ impl Display for ReedlineEvent {
ReedlineEvent::MenuPagePrevious => write!(f, "MenuPagePrevious"),
ReedlineEvent::ExecuteHostCommand(_) => write!(f, "ExecuteHostCommand"),
ReedlineEvent::OpenEditor => write!(f, "OpenEditor"),
ReedlineEvent::ResetSelection => write!(f, "ResetSelection"),
}
}
}
Expand Down

0 comments on commit f033574

Please sign in to comment.