mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 01:16:18 +04:00
Add comment textobject for surround selection and navigation (#1605)
This commit is contained in:
parent
7633c5acd3
commit
9bfb0caf1b
@ -21,6 +21,8 @@ # Adding Textobject Queries
|
||||
| `class.inside` |
|
||||
| `class.around` |
|
||||
| `parameter.inside` |
|
||||
| `comment.inside` |
|
||||
| `comment.around` |
|
||||
|
||||
[Example query files][textobject-examples] can be found in the helix GitHub repository.
|
||||
|
||||
|
@ -270,6 +270,8 @@ #### Unimpaired
|
||||
| `[c` | Go to previous class (**TS**) | `goto_prev_class` |
|
||||
| `]p` | Go to next parameter (**TS**) | `goto_next_parameter` |
|
||||
| `[p` | Go to previous parameter (**TS**) | `goto_prev_parameter` |
|
||||
| `]o` | Go to next comment (**TS**) | `goto_next_comment` |
|
||||
| `[o` | Go to previous comment (**TS**) | `goto_prev_comment` |
|
||||
| `[space` | Add newline above | `add_newline_above` |
|
||||
| `]space` | Add newline below | `add_newline_below` |
|
||||
|
||||
|
@ -69,6 +69,7 @@ ## Textobjects
|
||||
| `f` | Function |
|
||||
| `c` | Class |
|
||||
| `p` | Parameter |
|
||||
| `o` | Comment |
|
||||
|
||||
> NOTE: `f`, `c`, etc need a tree-sitter grammar active for the current
|
||||
document and a special tree-sitter query file to work properly. [Only
|
||||
|
@ -401,6 +401,8 @@ pub fn doc(&self) -> &str {
|
||||
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"),
|
||||
];
|
||||
|
@ -608,6 +608,7 @@ fn default() -> Self {
|
||||
"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 @@ fn default() -> Self {
|
||||
"f" => goto_next_function,
|
||||
"c" => goto_next_class,
|
||||
"p" => goto_next_parameter,
|
||||
"o" => goto_next_comment,
|
||||
"space" => add_newline_below,
|
||||
},
|
||||
|
||||
|
@ -11,3 +11,7 @@
|
||||
body: (_) @class.inside) @class.around
|
||||
|
||||
(parameter_declaration) @parameter.inside
|
||||
|
||||
(comment) @comment.inside
|
||||
|
||||
(comment)+ @comment.around
|
||||
|
@ -1,3 +1,12 @@
|
||||
(macro_def) @function.around
|
||||
|
||||
(argument) @parameter.inside
|
||||
|
||||
[
|
||||
(bracket_comment)
|
||||
(line_comment)
|
||||
] @comment.inside
|
||||
|
||||
(line_comment)+ @comment.around
|
||||
|
||||
(bracket_comment) @comment.around
|
@ -1 +1,5 @@
|
||||
(function_definition) @function.around
|
||||
|
||||
(comment) @comment.inside
|
||||
|
||||
(comment)+ @comment.around
|
||||
|
@ -19,3 +19,7 @@
|
||||
|
||||
(argument_list
|
||||
(_) @parameter.inside)
|
||||
|
||||
(comment) @comment.inside
|
||||
|
||||
(comment)+ @comment.around
|
||||
|
@ -1,3 +1,12 @@
|
||||
(basic_block) @function.around
|
||||
|
||||
(argument) @parameter.inside
|
||||
|
||||
[
|
||||
(comment)
|
||||
(multiline_comment)
|
||||
] @comment.inside
|
||||
|
||||
(comment)+ @comment.around
|
||||
|
||||
(multiline_comment) @comment.around
|
||||
|
@ -14,3 +14,7 @@
|
||||
(array_vector_body) @class.inside) @class.around
|
||||
|
||||
(argument) @parameter.inside
|
||||
|
||||
(comment) @comment.inside
|
||||
|
||||
(comment)+ @comment.around
|
||||
|
@ -6,3 +6,12 @@
|
||||
|
||||
(argument
|
||||
(_) @parameter.inside)
|
||||
|
||||
[
|
||||
(comments)
|
||||
(pod_statement)
|
||||
] @comment.inside
|
||||
|
||||
(comments)+ @comment.around
|
||||
|
||||
(pod_statement) @comment.around
|
||||
|
@ -28,3 +28,7 @@
|
||||
(variadic_parameter)
|
||||
(property_promotion_parameter)
|
||||
] @parameter.inside)
|
||||
|
||||
(comment) @comment.inside
|
||||
|
||||
(comment)+ @comment.around
|
||||
|
@ -12,3 +12,7 @@
|
||||
|
||||
(argument_list
|
||||
(_) @parameter.inside)
|
||||
|
||||
(comment) @comment.inside
|
||||
|
||||
(comment)+ @comment.around
|
||||
|
@ -7,3 +7,10 @@
|
||||
;----------
|
||||
|
||||
(function body: (_) @function.inside) @function.around
|
||||
|
||||
; Comments
|
||||
;---------
|
||||
|
||||
(comment) @comment.inside
|
||||
|
||||
(comment)+ @comment.around
|
||||
|
@ -24,3 +24,12 @@
|
||||
|
||||
(arguments
|
||||
(_) @parameter.inside)
|
||||
|
||||
[
|
||||
(line_comment)
|
||||
(block_comment)
|
||||
] @comment.inside
|
||||
|
||||
(line_comment)+ @comment.around
|
||||
|
||||
(block_comment) @comment.around
|
||||
|
@ -5,3 +5,12 @@
|
||||
body: (_) @class.inside) @class.around
|
||||
|
||||
(_ argument: _ @parameter.inside)
|
||||
|
||||
[
|
||||
(comment)
|
||||
(multiline_comment)
|
||||
] @comment.inside
|
||||
|
||||
(comment)+ @comment.around
|
||||
|
||||
(multiline_comment) @comment.around
|
||||
|
Loading…
Reference in New Issue
Block a user