Skip to content

Commit

Permalink
Add SelectMoveWord<Left/Right> command on Shift + Ctrl + Arrow
Browse files Browse the repository at this point in the history
  • Loading branch information
Tastaturtaste committed Dec 28, 2023
1 parent 5e1cabd commit 8926787
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/core_editor/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ impl Editor {
EditCommand::SelectAll => self.select_all(),
EditCommand::CutSelection => self.cut_selection(),
EditCommand::CopySelection => self.copy_selection(),
EditCommand::SelectMoveWordLeft => self.select_move_word_left(),
EditCommand::SelectMoveWordRight => self.select_move_word_right(),

Check warning on line 106 in src/core_editor/editor.rs

View check run for this annotation

Codecov / codecov/patch

src/core_editor/editor.rs#L100-L106

Added lines #L100 - L106 were not covered by tests
}

let new_undo_behavior = match (command, command.edit_type()) {
Expand All @@ -120,7 +122,11 @@ impl Editor {
};
if !matches!(
command,
EditCommand::SelectMoveLeft | EditCommand::SelectMoveRight | EditCommand::SelectAll
EditCommand::SelectMoveLeft
| EditCommand::SelectMoveRight
| EditCommand::SelectMoveWordLeft
| EditCommand::SelectMoveWordRight
| EditCommand::SelectAll
) {
self.reset_selection();
}
Expand Down Expand Up @@ -545,6 +551,20 @@ impl Editor {
}
})
}

Check warning on line 553 in src/core_editor/editor.rs

View check run for this annotation

Codecov / codecov/patch

src/core_editor/editor.rs#L552-L553

Added lines #L552 - L553 were not covered by tests

fn select_move_word_left(&mut self) {
if self.selection_anchor.is_none() {
self.selection_anchor = Some(self.insertion_point());
}
self.line_buffer.move_word_left();
}

Check warning on line 560 in src/core_editor/editor.rs

View check run for this annotation

Codecov / codecov/patch

src/core_editor/editor.rs#L555-L560

Added lines #L555 - L560 were not covered by tests

fn select_move_word_right(&mut self) {
if self.selection_anchor.is_none() {
self.selection_anchor = Some(self.insertion_point());
}
self.line_buffer.move_word_right();
}

Check warning on line 567 in src/core_editor/editor.rs

View check run for this annotation

Codecov / codecov/patch

src/core_editor/editor.rs#L562-L567

Added lines #L562 - L567 were not covered by tests
}

#[cfg(test)]
Expand Down
10 changes: 10 additions & 0 deletions src/edit_mode/keybindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,15 @@ pub fn add_common_selection_bindings(kb: &mut Keybindings) {

kb.add_binding(KM::SHIFT, KC::Left, edit_bind(EC::SelectMoveLeft));
kb.add_binding(KM::SHIFT, KC::Right, edit_bind(EC::SelectMoveRight));
kb.add_binding(
KM::SHIFT | KM::CONTROL,
KC::Left,
edit_bind(EC::SelectMoveWordLeft),
);
kb.add_binding(
KM::SHIFT | KM::CONTROL,
KC::Right,
edit_bind(EC::SelectMoveWordRight),
);
kb.add_binding(KM::CONTROL, KC::Char('a'), edit_bind(EC::SelectAll));
}
10 changes: 10 additions & 0 deletions src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ pub enum EditCommand {
/// Select and move right
SelectMoveRight,

/// Select and move whole word left
SelectMoveWordLeft,

/// Select and move whole word right
SelectMoveWordRight,

/// Select whole input buffer
SelectAll,

Expand Down Expand Up @@ -270,6 +276,8 @@ impl Display for EditCommand {
EditCommand::SelectAll => write!(f, "SelectAll"),
EditCommand::CutSelection => write!(f, "CutSelection"),
EditCommand::CopySelection => write!(f, "CopySelection"),
EditCommand::SelectMoveWordLeft => write!(f, "SelectMoveWordLeft"),
EditCommand::SelectMoveWordRight => write!(f, "SelectMoveWordRight"),

Check warning on line 280 in src/enums.rs

View check run for this annotation

Codecov / codecov/patch

src/enums.rs#L274-L280

Added lines #L274 - L280 were not covered by tests
}
}
}
Expand Down Expand Up @@ -300,6 +308,8 @@ impl EditCommand {
| EditCommand::MoveLeftBefore(_)
| EditCommand::SelectMoveLeft
| EditCommand::SelectMoveRight
| EditCommand::SelectMoveWordLeft
| EditCommand::SelectMoveWordRight
| EditCommand::SelectAll => EditType::MoveCursor,

Check warning on line 313 in src/enums.rs

View check run for this annotation

Codecov / codecov/patch

src/enums.rs#L313

Added line #L313 was not covered by tests

// Text edits
Expand Down

0 comments on commit 8926787

Please sign in to comment.