on master help sign in
Incorporate long word commands into keymap
commitde8745aea772fb03ffc36fd3f959d8aa7ca1fd57 authorPabloMansanet <pablomansanet@gmail.com> dateTue 29 Jun 2021, 14:54 (5 years ago) parent73572b7
3 files changed+48−3
helix-core/src/movement.rs+5−3 helix-term/src/commands.rs+39 helix-term/src/keymap.rs+4
helix-core/src/movement.rs+5−3
@@ -194,7 +194,9 @@ impl CharHelpers for Chars<'_> {
194194
195195 // Index advancement also depends on the direction.
196196 let advance: &dyn Fn(&mut usize) = match target {
197− WordMotionTarget::PrevWordStart | WordMotionTarget::PrevLongWordStart => &|u| *u = u.saturating_sub(1),
197+ WordMotionTarget::PrevWordStart | WordMotionTarget::PrevLongWordStart => {
198+ &|u| *u = u.saturating_sub(1)
199+ }
198200 _ => &|u| *u += 1,
199201 };
200202
@@ -254,9 +256,9 @@ fn is_word_boundary(a: char, b: char) -> bool {
254256fn is_long_word_boundary(a: char, b: char) -> bool {
255257 match (categorize_char(a), categorize_char(b)) {
256258 (CharCategory::Word, CharCategory::Punctuation)
257− | (CharCategory::Punctuation, CharCategory::Word) => false,
259+ | (CharCategory::Punctuation, CharCategory::Word) => false,
258260 (a, b) if a != b => true,
259− _ => false
261+ _ => false,
260262 }
261263}
262264
helix-term/src/commands.rs+39
@@ -158,6 +158,9 @@ impl Command {
158158 move_next_word_start,
159159 move_prev_word_start,
160160 move_next_word_end,
161+ move_next_long_word_start,
162+ move_prev_long_word_start,
163+ move_next_long_word_end,
161164 move_file_start,
162165 move_file_end,
163166 extend_next_word_start,
@@ -434,6 +437,42 @@ fn move_next_word_end(cx: &mut Context) {
434437 doc.set_selection(view.id, selection);
435438}
436439
440+fn move_next_long_word_start(cx: &mut Context) {
441+ let count = cx.count();
442+ let (view, doc) = current!(cx.editor);
443+ let text = doc.text().slice(..);
444+
445+ let selection = doc
446+ .selection(view.id)
447+ .transform(|range| movement::move_next_long_word_start(text, range, count));
448+
449+ doc.set_selection(view.id, selection);
450+}
451+
452+fn move_prev_long_word_start(cx: &mut Context) {
453+ let count = cx.count();
454+ let (view, doc) = current!(cx.editor);
455+ let text = doc.text().slice(..);
456+
457+ let selection = doc
458+ .selection(view.id)
459+ .transform(|range| movement::move_prev_long_word_start(text, range, count));
460+
461+ doc.set_selection(view.id, selection);
462+}
463+
464+fn move_next_long_word_end(cx: &mut Context) {
465+ let count = cx.count();
466+ let (view, doc) = current!(cx.editor);
467+ let text = doc.text().slice(..);
468+
469+ let selection = doc
470+ .selection(view.id)
471+ .transform(|range| movement::move_next_long_word_end(text, range, count));
472+
473+ doc.set_selection(view.id, selection);
474+}
475+
437476fn move_file_start(cx: &mut Context) {
438477 push_jump(cx.editor);
439478 let (view, doc) = current!(cx.editor);
helix-term/src/keymap.rs+4
@@ -186,6 +186,10 @@ impl Default for Keymaps {
186186 key!('b') => Command::move_prev_word_start,
187187 key!('e') => Command::move_next_word_end,
188188
189+ key!('W') => Command::move_next_long_word_start,
190+ key!('B') => Command::move_prev_long_word_start,
191+ key!('E') => Command::move_next_long_word_end,
192+
189193 key!('v') => Command::select_mode,
190194 key!('g') => Command::goto_mode,
191195 key!(':') => Command::command_mode,