From 9bfb0caf1b4bafdac8eb964f38f7820740056fff Mon Sep 17 00:00:00 2001 From: Daniel S Poulin Date: Sun, 6 Mar 2022 00:24:24 -0500 Subject: Add comment textobject for surround selection and navigation (#1605) --- helix-term/src/commands.rs | 12 ++++++++++++ helix-term/src/keymap.rs | 2 ++ 2 files changed, 14 insertions(+) (limited to 'helix-term') diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 8ee05ece..2a8f462d 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -401,6 +401,8 @@ impl MappableCommand { goto_prev_class, "Goto previous class", goto_next_parameter, "Goto next parameter", goto_prev_parameter, "Goto previous parameter", + goto_next_comment, "Goto next comment", + goto_prev_comment, "Goto previous comment", dap_launch, "Launch debug target", dap_toggle_breakpoint, "Toggle breakpoint", dap_continue, "Continue program execution", @@ -5381,6 +5383,14 @@ fn goto_prev_parameter(cx: &mut Context) { goto_ts_object_impl(cx, "parameter", Direction::Backward) } +fn goto_next_comment(cx: &mut Context) { + goto_ts_object_impl(cx, "comment", Direction::Forward) +} + +fn goto_prev_comment(cx: &mut Context) { + goto_ts_object_impl(cx, "comment", Direction::Backward) +} + fn select_textobject_around(cx: &mut Context) { select_textobject(cx, textobject::TextObject::Around); } @@ -5423,6 +5433,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) { 'c' => textobject_treesitter("class", range), 'f' => textobject_treesitter("function", range), 'p' => textobject_treesitter("parameter", range), + 'o' => textobject_treesitter("comment", range), 'm' => { let ch = text.char(range.cursor(text)); if !ch.is_ascii_alphanumeric() { @@ -5456,6 +5467,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) { ("c", "Class (tree-sitter)"), ("f", "Function (tree-sitter)"), ("p", "Parameter (tree-sitter)"), + ("o", "Comment (tree-sitter)"), ("m", "Matching delimiter under cursor"), (" ", "... or any character acting as a pair"), ]; diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index 0147f58e..a5a615f3 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -608,6 +608,7 @@ impl Default for Keymaps { "f" => goto_prev_function, "c" => goto_prev_class, "p" => goto_prev_parameter, + "o" => goto_prev_comment, "space" => add_newline_above, }, "]" => { "Right bracket" @@ -616,6 +617,7 @@ impl Default for Keymaps { "f" => goto_next_function, "c" => goto_next_class, "p" => goto_next_parameter, + "o" => goto_next_comment, "space" => add_newline_below, }, -- cgit v1.2.3-70-g09d2