Skip to content

Commit

Permalink
Incorporate long word commands into keymap
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloMansanet committed Jun 29, 2021
1 parent fcca647 commit 937347c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
8 changes: 5 additions & 3 deletions helix-core/src/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ impl CharHelpers for Chars<'_> {

// Index advancement also depends on the direction.
let advance: &dyn Fn(&mut usize) = match target {
WordMotionTarget::PrevWordStart | WordMotionTarget::PrevLongWordStart => &|u| *u = u.saturating_sub(1),
WordMotionTarget::PrevWordStart | WordMotionTarget::PrevLongWordStart => {
&|u| *u = u.saturating_sub(1)
}
_ => &|u| *u += 1,
};

Expand Down Expand Up @@ -254,9 +256,9 @@ fn is_word_boundary(a: char, b: char) -> bool {
fn is_long_word_boundary(a: char, b: char) -> bool {
match (categorize_char(a), categorize_char(b)) {
(CharCategory::Word, CharCategory::Punctuation)
| (CharCategory::Punctuation, CharCategory::Word) => false,
| (CharCategory::Punctuation, CharCategory::Word) => false,
(a, b) if a != b => true,
_ => false
_ => false,
}
}

Expand Down
39 changes: 39 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ impl Command {
move_next_word_start,
move_prev_word_start,
move_next_word_end,
move_next_long_word_start,
move_prev_long_word_start,
move_next_long_word_end,
move_file_start,
move_file_end,
extend_next_word_start,
Expand Down Expand Up @@ -434,6 +437,42 @@ fn move_next_word_end(cx: &mut Context) {
doc.set_selection(view.id, selection);
}

fn move_next_long_word_start(cx: &mut Context) {
let count = cx.count();
let (view, doc) = current!(cx.editor);
let text = doc.text().slice(..);

let selection = doc
.selection(view.id)
.transform(|range| movement::move_next_long_word_start(text, range, count));

doc.set_selection(view.id, selection);
}

fn move_prev_long_word_start(cx: &mut Context) {
let count = cx.count();
let (view, doc) = current!(cx.editor);
let text = doc.text().slice(..);

let selection = doc
.selection(view.id)
.transform(|range| movement::move_prev_long_word_start(text, range, count));

doc.set_selection(view.id, selection);
}

fn move_next_long_word_end(cx: &mut Context) {
let count = cx.count();
let (view, doc) = current!(cx.editor);
let text = doc.text().slice(..);

let selection = doc
.selection(view.id)
.transform(|range| movement::move_next_long_word_end(text, range, count));

doc.set_selection(view.id, selection);
}

fn move_file_start(cx: &mut Context) {
push_jump(cx.editor);
let (view, doc) = current!(cx.editor);
Expand Down
4 changes: 4 additions & 0 deletions helix-term/src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ impl Default for Keymaps {
key!('b') => Command::move_prev_word_start,
key!('e') => Command::move_next_word_end,

key!('W') => Command::move_next_long_word_start,
key!('B') => Command::move_prev_long_word_start,
key!('E') => Command::move_next_long_word_end,

key!('v') => Command::select_mode,
key!('g') => Command::goto_mode,
key!(':') => Command::command_mode,
Expand Down

0 comments on commit 937347c

Please sign in to comment.