on master help sign in
Incorporate long word commands into keymap
de8745aPabloMansanet
helix-core/src/movement.rs+5−3
@@ -194,7 +194,9 @@ impl CharHelpers for Chars<'_> {
194
194
195 // Index advancement also depends on the direction.
195 // Index advancement also depends on the direction.
196 let advance: &dyn Fn(&mut usize) = match target {
196 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+ }
198 _ => &|u| *u += 1,
200 _ => &|u| *u += 1,
199 };
201 };
200
202
@@ -254,9 +256,9 @@ fn is_word_boundary(a: char, b: char) -> bool {
254fn is_long_word_boundary(a: char, b: char) -> bool {
256fn is_long_word_boundary(a: char, b: char) -> bool {
255 match (categorize_char(a), categorize_char(b)) {
257 match (categorize_char(a), categorize_char(b)) {
256 (CharCategory::Word, CharCategory::Punctuation)
258 (CharCategory::Word, CharCategory::Punctuation)
257− | (CharCategory::Punctuation, CharCategory::Word) => false,
259+ | (CharCategory::Punctuation, CharCategory::Word) => false,
258 (a, b) if a != b => true,
260 (a, b) if a != b => true,
259− _ => false
261+ _ => false,
260 }
262 }
261}
263}
262
264
helix-term/src/commands.rs+39
@@ -158,6 +158,9 @@ impl Command {
158 move_next_word_start,
158 move_next_word_start,
159 move_prev_word_start,
159 move_prev_word_start,
160 move_next_word_end,
160 move_next_word_end,
161+ move_next_long_word_start,
162+ move_prev_long_word_start,
163+ move_next_long_word_end,
161 move_file_start,
164 move_file_start,
162 move_file_end,
165 move_file_end,
163 extend_next_word_start,
166 extend_next_word_start,
@@ -434,6 +437,42 @@ fn move_next_word_end(cx: &mut Context) {
434 doc.set_selection(view.id, selection);
437 doc.set_selection(view.id, selection);
435}
438}
436
439
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+
437fn move_file_start(cx: &mut Context) {
476fn move_file_start(cx: &mut Context) {
438 push_jump(cx.editor);
477 push_jump(cx.editor);
439 let (view, doc) = current!(cx.editor);
478 let (view, doc) = current!(cx.editor);
helix-term/src/keymap.rs+4
@@ -186,6 +186,10 @@ impl Default for Keymaps {
186 key!('b') => Command::move_prev_word_start,
186 key!('b') => Command::move_prev_word_start,
187 key!('e') => Command::move_next_word_end,
187 key!('e') => Command::move_next_word_end,
188
188
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+
189 key!('v') => Command::select_mode,
193 key!('v') => Command::select_mode,
190 key!('g') => Command::goto_mode,
194 key!('g') => Command::goto_mode,
191 key!(':') => Command::command_mode,
195 key!(':') => Command::command_mode,