Skip to content

Commit

Permalink
key
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Nov 20, 2023
1 parent ed999b9 commit bc1a01f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 49 deletions.
9 changes: 0 additions & 9 deletions packages/cursorless-engine/src/languages/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ const nodeMatchers: Partial<
Record<SimpleScopeTypeType, NodeMatcherAlternative>
> = {
collectionItem: "jsx_attribute",
collectionKey: trailingMatcher(
[
"pair[key]",
"jsx_attribute.property_identifier!",
"object_type.property_signature[name]!",
"shorthand_property_identifier",
],
[":"],
),
statement: cascadingMatcher(
matcher(
patternFinder(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
languageId: typescript
command:
version: 1
spokenForm: take every key
action: setSelection
spokenForm: change every key
action: clearAndSetSelection
targets:
- type: primitive
modifier: {type: containingScope, scopeType: collectionKey, includeSiblings: true}
Expand All @@ -19,11 +19,11 @@ initialState:
finalState:
documentContents: |-
const value = {
key1: "hello",
key2: "there",
: "hello",
: "there",
};
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 8}
active: {line: 1, character: 4}
- anchor: {line: 2, character: 4}
active: {line: 2, character: 8}
active: {line: 2, character: 4}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
languageId: typescript
command:
version: 1
spokenForm: take every key
action: setSelection
spokenForm: change every key
action: clearAndSetSelection
targets:
- type: primitive
modifier: {type: containingScope, scopeType: collectionKey, includeSiblings: true}
Expand All @@ -19,11 +19,11 @@ initialState:
finalState:
documentContents: |-
{
foo: "hello",
bar,
: "hello",
,
}
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 7}
active: {line: 1, character: 4}
- anchor: {line: 2, character: 4}
active: {line: 2, character: 7}
active: {line: 2, character: 4}
20 changes: 8 additions & 12 deletions queries/javascript.core.scm
Original file line number Diff line number Diff line change
Expand Up @@ -352,20 +352,9 @@
(#not-parent-type? @_.domain expression_statement)
)

;; Match nodes at field `value` of their parent node, setting leading delimiter
;; to be the range until the previous named node
(
(_
(_)? @value.leading.start.endOf
.
value: (_) @value @value.leading.end.startOf
) @_.domain
(#not-type? @_.domain variable_declarator)
)

;;!! const aaa = {bbb};
;;! ^^^
(shorthand_property_identifier) @value
(shorthand_property_identifier) @collectionKey @value

;;!! return 0;
;;! ^
Expand Down Expand Up @@ -567,3 +556,10 @@
)

(try_statement) @branch.iteration

(pair
key: (_) @collectionKey @collectionKey.removal.start @value.removal.start.endOf
value: (_) @value @collectionKey.removal.end.startOf @value.removal.end
) @_.domain

(object) @collectionKey.iteration
25 changes: 9 additions & 16 deletions queries/javascript.jsx.scm
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,15 @@
(_) @value @value.leading.end.startOf
) @_.domain

(jsx_self_closing_element
"<" @value.iteration.start.endOf
"/" @value.iteration.end.startOf
)

(jsx_opening_element
"<" @value.iteration.start.endOf
">" @value.iteration.end.startOf
)
(jsx_attribute
(property_identifier) @collectionKey
) @_.domain

(jsx_text) @textFragment
(jsx_attribute) @attribute

(jsx_opening_element
(jsx_attribute) @attribute
) @_.iteration
[
(jsx_opening_element)
(jsx_self_closing_element)
] @attribute.iteration @collectionKey.iteration @value.iteration

(jsx_self_closing_element
(jsx_attribute) @attribute
) @_.iteration
(jsx_text) @textFragment
10 changes: 10 additions & 0 deletions queries/typescript.core.scm
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,13 @@
(abstract_class_declaration
name: (_) @name
) @_.domain

(object_type
(property_signature
name: (_) @collectionKey @_.removal.start
type: (_
":"
(_) @_.removal.end.startOf
)
) @_.domain
) @_.iteration

0 comments on commit bc1a01f

Please sign in to comment.