Skip to content

Commit 8926787

Browse files
committed
Add SelectMoveWord<Left/Right> command on Shift + Ctrl + Arrow
1 parent 5e1cabd commit 8926787

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/core_editor/editor.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ impl Editor {
102102
EditCommand::SelectAll => self.select_all(),
103103
EditCommand::CutSelection => self.cut_selection(),
104104
EditCommand::CopySelection => self.copy_selection(),
105+
EditCommand::SelectMoveWordLeft => self.select_move_word_left(),
106+
EditCommand::SelectMoveWordRight => self.select_move_word_right(),
105107
}
106108

107109
let new_undo_behavior = match (command, command.edit_type()) {
@@ -120,7 +122,11 @@ impl Editor {
120122
};
121123
if !matches!(
122124
command,
123-
EditCommand::SelectMoveLeft | EditCommand::SelectMoveRight | EditCommand::SelectAll
125+
EditCommand::SelectMoveLeft
126+
| EditCommand::SelectMoveRight
127+
| EditCommand::SelectMoveWordLeft
128+
| EditCommand::SelectMoveWordRight
129+
| EditCommand::SelectAll
124130
) {
125131
self.reset_selection();
126132
}
@@ -545,6 +551,20 @@ impl Editor {
545551
}
546552
})
547553
}
554+
555+
fn select_move_word_left(&mut self) {
556+
if self.selection_anchor.is_none() {
557+
self.selection_anchor = Some(self.insertion_point());
558+
}
559+
self.line_buffer.move_word_left();
560+
}
561+
562+
fn select_move_word_right(&mut self) {
563+
if self.selection_anchor.is_none() {
564+
self.selection_anchor = Some(self.insertion_point());
565+
}
566+
self.line_buffer.move_word_right();
567+
}
548568
}
549569

550570
#[cfg(test)]

src/edit_mode/keybindings.rs

+10
Original file line numberDiff line numberDiff line change
@@ -210,5 +210,15 @@ pub fn add_common_selection_bindings(kb: &mut Keybindings) {
210210

211211
kb.add_binding(KM::SHIFT, KC::Left, edit_bind(EC::SelectMoveLeft));
212212
kb.add_binding(KM::SHIFT, KC::Right, edit_bind(EC::SelectMoveRight));
213+
kb.add_binding(
214+
KM::SHIFT | KM::CONTROL,
215+
KC::Left,
216+
edit_bind(EC::SelectMoveWordLeft),
217+
);
218+
kb.add_binding(
219+
KM::SHIFT | KM::CONTROL,
220+
KC::Right,
221+
edit_bind(EC::SelectMoveWordRight),
222+
);
213223
kb.add_binding(KM::CONTROL, KC::Char('a'), edit_bind(EC::SelectAll));
214224
}

src/enums.rs

+10
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ pub enum EditCommand {
196196
/// Select and move right
197197
SelectMoveRight,
198198

199+
/// Select and move whole word left
200+
SelectMoveWordLeft,
201+
202+
/// Select and move whole word right
203+
SelectMoveWordRight,
204+
199205
/// Select whole input buffer
200206
SelectAll,
201207

@@ -270,6 +276,8 @@ impl Display for EditCommand {
270276
EditCommand::SelectAll => write!(f, "SelectAll"),
271277
EditCommand::CutSelection => write!(f, "CutSelection"),
272278
EditCommand::CopySelection => write!(f, "CopySelection"),
279+
EditCommand::SelectMoveWordLeft => write!(f, "SelectMoveWordLeft"),
280+
EditCommand::SelectMoveWordRight => write!(f, "SelectMoveWordRight"),
273281
}
274282
}
275283
}
@@ -300,6 +308,8 @@ impl EditCommand {
300308
| EditCommand::MoveLeftBefore(_)
301309
| EditCommand::SelectMoveLeft
302310
| EditCommand::SelectMoveRight
311+
| EditCommand::SelectMoveWordLeft
312+
| EditCommand::SelectMoveWordRight
303313
| EditCommand::SelectAll => EditType::MoveCursor,
304314

305315
// Text edits

0 commit comments

Comments
 (0)