Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/core_editor/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ impl Editor {
self.move_left_until_char(*c, true, true, *select)
}
EditCommand::SelectAll => self.select_all(),
EditCommand::SelectChar => self.select_char(),
EditCommand::CutSelection => self.cut_selection_to_cut_buffer(),
EditCommand::CopySelection => self.copy_selection_to_cut_buffer(),
EditCommand::Paste => self.paste_cut_buffer(),
Expand Down Expand Up @@ -642,6 +643,10 @@ impl Editor {
self.line_buffer.move_to_end();
}

fn select_char(&mut self) {
self.update_selection_anchor(true);
}

#[cfg(feature = "system_clipboard")]
fn cut_selection_to_system(&mut self) {
if let Some((start, end)) = self.get_selection() {
Expand Down
9 changes: 9 additions & 0 deletions src/edit_mode/vi/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ where
let _ = input.next();
Some(Command::EnterViAppend)
}
Some('v') => {
let _ = input.next();
match mode {
ViMode::Normal => Some(Command::EnterViVisual),
_ => None,
}
}
Some('u') => {
let _ = input.next();
Some(Command::Undo)
Expand Down Expand Up @@ -185,6 +192,7 @@ pub enum Command {
PasteBefore,
EnterViAppend,
EnterViInsert,
EnterViVisual,
Undo,
ChangeToLineEnd,
DeleteToEnd,
Expand Down Expand Up @@ -228,6 +236,7 @@ impl Command {
Self::EnterViAppend => vec![ReedlineOption::Edit(EditCommand::MoveRight {
select: false,
})],
Self::EnterViVisual => vec![ReedlineOption::Edit(EditCommand::SelectChar)],
Self::NewlineAbove => vec![ReedlineOption::Edit(EditCommand::InsertNewlineAbove)],
Self::NewlineBelow => vec![ReedlineOption::Edit(EditCommand::InsertNewlineBelow)],
Self::PasteAfter => vec![ReedlineOption::Edit(EditCommand::PasteCutBufferAfter)],
Expand Down
5 changes: 0 additions & 5 deletions src/edit_mode/vi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ impl EditMode for Vi {
Event::Key(KeyEvent {
code, modifiers, ..
}) => match (self.mode, modifiers, code) {
(ViMode::Normal, KeyModifiers::NONE, KeyCode::Char('v')) => {
self.cache.clear();
self.mode = ViMode::Visual;
ReedlineEvent::Multiple(vec![ReedlineEvent::Esc, ReedlineEvent::Repaint])
}
(ViMode::Normal | ViMode::Visual, modifier, KeyCode::Char(c)) => {
let c = c.to_ascii_lowercase();

Expand Down
3 changes: 3 additions & 0 deletions src/edit_mode/vi/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ impl ParsedViSequence {
(Some(Command::Delete), ParseResult::Incomplete) if mode == ViMode::Visual => {
Some(ViMode::Normal)
}
(Some(Command::EnterViVisual), ParseResult::Incomplete) if mode == ViMode::Normal => {
Some(ViMode::Visual)
}
(Some(Command::ChangeInsidePair { .. }), _) => Some(ViMode::Insert),
(Some(Command::ChangeTextObject { .. }), _) => Some(ViMode::Insert),
(Some(Command::Delete), ParseResult::Incomplete)
Expand Down
10 changes: 7 additions & 3 deletions src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ pub enum EditCommand {
/// Select whole input buffer
SelectAll,

/// Select grapheme under cursor,
SelectChar,

/// Cut selection to local buffer
CutSelection,

Expand Down Expand Up @@ -536,9 +539,10 @@ impl EditCommand {
| EditCommand::MoveLeftBefore { select, .. } => {
EditType::MoveCursor { select: *select }
}
EditCommand::SwapCursorAndAnchor => EditType::MoveCursor { select: true },

EditCommand::SelectAll => EditType::MoveCursor { select: true },
// Selection
EditCommand::SwapCursorAndAnchor | EditCommand::SelectAll | EditCommand::SelectChar => {
EditType::MoveCursor { select: true }
}
// Text edits
EditCommand::InsertChar(_)
| EditCommand::Backspace
Expand Down
Loading