Skip to content

Commit a82cb06

Browse files
EpocSquadronpostsolar
authored andcommitted
Add textobject for entries/elements of list-like things (helix-editor#8150)
1 parent 547bb65 commit a82cb06

File tree

17 files changed

+145
-3
lines changed

17 files changed

+145
-3
lines changed

book/src/generated/lang-support.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
| gomod || | | `gopls` |
7070
| gotmpl || | | `gopls` |
7171
| gowork || | | `gopls` |
72-
| graphql || | | `graphql-lsp` |
72+
| graphql || | | `graphql-lsp` |
7373
| groovy || | | |
7474
| hare || | | |
7575
| haskell ||| | `haskell-language-server-wrapper` |
@@ -91,7 +91,7 @@
9191
| javascript |||| `typescript-language-server` |
9292
| jinja || | | |
9393
| jsdoc || | | |
94-
| json || || `vscode-json-language-server` |
94+
| json || || `vscode-json-language-server` |
9595
| json5 || | | |
9696
| jsonc || || `vscode-json-language-server` |
9797
| jsonnet || | | `jsonnet-language-server` |
@@ -188,7 +188,7 @@
188188
| templ || | | `templ` |
189189
| tfvars || || `terraform-ls` |
190190
| todotxt || | | |
191-
| toml || | | `taplo` |
191+
| toml || | | `taplo` |
192192
| tsq || | | |
193193
| tsx |||| `typescript-language-server` |
194194
| twig || | | |

book/src/guides/textobject.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ The following [captures][tree-sitter-captures] are recognized:
2525
| `parameter.inside` |
2626
| `comment.inside` |
2727
| `comment.around` |
28+
| `entry.inside` |
29+
| `entry.around` |
2830

2931
[Example query files][textobject-examples] can be found in the helix GitHub repository.
3032

helix-term/src/commands.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,8 @@ impl MappableCommand {
475475
goto_prev_comment, "Goto previous comment",
476476
goto_next_test, "Goto next test",
477477
goto_prev_test, "Goto previous test",
478+
goto_next_entry, "Goto next pairing",
479+
goto_prev_entry, "Goto previous pairing",
478480
goto_next_paragraph, "Goto next paragraph",
479481
goto_prev_paragraph, "Goto previous paragraph",
480482
dap_launch, "Launch debug target",
@@ -5167,6 +5169,14 @@ fn goto_prev_test(cx: &mut Context) {
51675169
goto_ts_object_impl(cx, "test", Direction::Backward)
51685170
}
51695171

5172+
fn goto_next_entry(cx: &mut Context) {
5173+
goto_ts_object_impl(cx, "entry", Direction::Forward)
5174+
}
5175+
5176+
fn goto_prev_entry(cx: &mut Context) {
5177+
goto_ts_object_impl(cx, "entry", Direction::Backward)
5178+
}
5179+
51705180
fn select_textobject_around(cx: &mut Context) {
51715181
select_textobject(cx, textobject::TextObject::Around);
51725182
}
@@ -5231,6 +5241,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
52315241
'a' => textobject_treesitter("parameter", range),
52325242
'c' => textobject_treesitter("comment", range),
52335243
'T' => textobject_treesitter("test", range),
5244+
'e' => textobject_treesitter("entry", range),
52345245
'p' => textobject::textobject_paragraph(text, range, objtype, count),
52355246
'm' => textobject::textobject_pair_surround_closest(
52365247
text, range, objtype, count,
@@ -5263,6 +5274,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
52635274
("a", "Argument/parameter (tree-sitter)"),
52645275
("c", "Comment (tree-sitter)"),
52655276
("T", "Test (tree-sitter)"),
5277+
("e", "Data structure entry (tree-sitter)"),
52665278
("m", "Closest surrounding pair"),
52675279
(" ", "... or any character acting as a pair"),
52685280
];

helix-term/src/keymap/default.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
114114
"t" => goto_prev_class,
115115
"a" => goto_prev_parameter,
116116
"c" => goto_prev_comment,
117+
"e" => goto_prev_entry,
117118
"T" => goto_prev_test,
118119
"p" => goto_prev_paragraph,
119120
"space" => add_newline_above,
@@ -127,6 +128,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
127128
"t" => goto_next_class,
128129
"a" => goto_next_parameter,
129130
"c" => goto_next_comment,
131+
"e" => goto_next_entry,
130132
"T" => goto_next_test,
131133
"p" => goto_next_paragraph,
132134
"space" => add_newline_below,

runtime/queries/_typescript/textobjects.scm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
(type_alias_declaration
55
value: (_) @class.inside)
66
] @class.around
7+
8+
(enum_body
9+
(_) @entry.around)
10+
11+
(enum_assignment (_) @entry.inside)
12+

runtime/queries/bash/textobjects.scm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
(comment) @comment.inside
88

99
(comment)+ @comment.around
10+
11+
(array
12+
(_) @entry.around)

runtime/queries/c/textobjects.scm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@
1919
(comment) @comment.inside
2020

2121
(comment)+ @comment.around
22+
23+
(enumerator
24+
(_) @entry.inside) @entry.around
25+
26+
(initializer_list
27+
(_) @entry.around)

runtime/queries/ecma/textobjects.scm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,12 @@
3434
(comment) @comment.inside
3535

3636
(comment)+ @comment.around
37+
38+
(array
39+
(_) @entry.around)
40+
41+
(pair
42+
(_) @entry.inside) @entry.around
43+
44+
(pair_pattern
45+
(_) @entry.inside) @entry.around
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(type_definition) @class.around
2+
3+
(executable_definition) @function.around
4+
5+
(arguments_definition
6+
(input_value_definition) @parameter.inside @parameter.movement)
7+
8+
(arguments
9+
(argument) @parameter.inside @parameter.movement)
10+
11+
(selection
12+
[(field) (fragment_spread)] @entry.around)
13+
14+
(selection
15+
(field (selection_set) @entry.inside))
16+
17+
(field_definition
18+
(_) @entry.inside) @entry.around
19+
20+
(input_fields_definition
21+
(input_value_definition ) @entry.around)
22+
23+
(enum_value) @entry.around

runtime/queries/java/textobjects.scm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@
3636
(line_comment)+ @comment.around
3737

3838
(block_comment) @comment.around
39+
40+
(array_initializer
41+
(_) @entry.around)
42+
43+
(enum_body
44+
(enum_constant) @entry.around)

0 commit comments

Comments
 (0)