diff options
author | Skyler Hawthorne | 2022-08-17 01:28:41 +0000 |
---|---|---|
committer | Michael Davis | 2023-08-01 14:41:42 +0000 |
commit | 93acb538121cab36712f40f26fa287df93817de5 (patch) | |
tree | b0ad0a3037d62750b4da6498a96b82758c25a18c /helix-term/src | |
parent | 1d702ea191e9bf84566ea0008755d1ab53d19265 (diff) |
add node boundary movement
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/commands.rs | 44 | ||||
-rw-r--r-- | helix-term/src/keymap/default.rs | 5 |
2 files changed, 49 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index bf60ad71..fc01eec7 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -247,6 +247,8 @@ impl MappableCommand { move_prev_long_word_start, "Move to start of previous long word", move_next_long_word_end, "Move to end of next long word", move_prev_long_word_end, "Move to end of previous long word", + move_parent_node_end, "Move to end of the parent node", + move_parent_node_start, "Move to beginning of the parent node", extend_next_word_start, "Extend to start of next word", extend_prev_word_start, "Extend to start of previous word", extend_next_word_end, "Extend to end of next word", @@ -255,6 +257,8 @@ impl MappableCommand { extend_prev_long_word_start, "Extend to start of previous long word", extend_next_long_word_end, "Extend to end of next long word", extend_prev_long_word_end, "Extend to end of prev long word", + extend_parent_node_end, "Extend to end of the parent node", + extend_parent_node_start, "Extend to beginning of the parent node", find_till_char, "Move till next occurrence of char", find_next_char, "Move to next occurrence of char", extend_till_char, "Extend till next occurrence of char", @@ -4605,6 +4609,46 @@ fn select_prev_sibling(cx: &mut Context) { select_sibling_impl(cx, &|node| Node::prev_sibling(&node)) } +fn move_node_bound_impl(cx: &mut Context, dir: Direction, movement: Movement) { + let motion = move |editor: &mut Editor| { + let (view, doc) = current!(editor); + + if let Some(syntax) = doc.syntax() { + let text = doc.text().slice(..); + let current_selection = doc.selection(view.id); + + let selection = movement::move_parent_node_end( + syntax, + text, + current_selection.clone(), + dir, + movement, + ); + + doc.set_selection(view.id, selection); + } + }; + + motion(cx.editor); + cx.editor.last_motion = Some(Motion(Box::new(motion))); +} + +pub fn move_parent_node_end(cx: &mut Context) { + move_node_bound_impl(cx, Direction::Forward, Movement::Move) +} + +pub fn move_parent_node_start(cx: &mut Context) { + move_node_bound_impl(cx, Direction::Backward, Movement::Move) +} + +pub fn extend_parent_node_end(cx: &mut Context) { + move_node_bound_impl(cx, Direction::Forward, Movement::Extend) +} + +pub fn extend_parent_node_start(cx: &mut Context) { + move_node_bound_impl(cx, Direction::Backward, Movement::Extend) +} + fn match_brackets(cx: &mut Context) { let (view, doc) = current!(cx.editor); let is_select = cx.editor.mode == Mode::Select; diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index 37983352..419e376f 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -88,6 +88,8 @@ pub fn default() -> HashMap<Mode, KeyTrie> { "A-i" | "A-down" => shrink_selection, "A-p" | "A-left" => select_prev_sibling, "A-n" | "A-right" => select_next_sibling, + "A-e" => move_parent_node_end, + "A-b" => move_parent_node_start, "%" => select_all, "x" => extend_line_below, @@ -336,6 +338,9 @@ pub fn default() -> HashMap<Mode, KeyTrie> { "B" => extend_prev_long_word_start, "E" => extend_next_long_word_end, + "A-e" => extend_parent_node_end, + "A-b" => extend_parent_node_start, + "n" => extend_search_next, "N" => extend_search_prev, |