Skip to content

Commit 3dd52d9

Browse files
pokeyfidgetingbits
authored and
fidgetingbits
committed
Fix value scope nesting in Typescript (cursorless-dev#1929)
We only want nested value scopes if there is more than one declarator in a statement. Before: <img width="186" alt="image" src="https://github.com/cursorless-dev/cursorless/assets/755842/0aaf4491-2c68-4be2-849d-ff5c72ac968a"> After: <img width="185" alt="image" src="https://github.com/cursorless-dev/cursorless/assets/755842/3058a007-73b0-48cc-81dd-6f5b126fa07a"> Unfortunately we have no good way to test this change until we have cursorless-dev#1524 **Edit**: I found a way to test it, but it's a bit hacky. ## Checklist - [ ] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [ ] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [ ] I have not broken the cheatsheet
1 parent e39cad5 commit 3dd52d9

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
languageId: typescript
2+
command:
3+
version: 6
4+
spokenForm: change next value
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: relativeScope
11+
scopeType: {type: value}
12+
offset: 1
13+
length: 1
14+
direction: forward
15+
usePrePhraseSnapshot: true
16+
initialState:
17+
documentContents: |-
18+
const aaa = 0;
19+
const bbb = 0;
20+
selections:
21+
- anchor: {line: 0, character: 0}
22+
active: {line: 0, character: 0}
23+
marks: {}
24+
finalState:
25+
documentContents: |-
26+
const aaa = 0;
27+
const bbb = ;
28+
selections:
29+
- anchor: {line: 1, character: 12}
30+
active: {line: 1, character: 12}

queries/javascript.core.scm

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,14 @@
353353

354354
;; Match nodes at field `value` of their parent node, setting leading delimiter
355355
;; to be the range until the previous named node
356-
(_
357-
(_)? @value.leading.start.endOf
358-
.
359-
value: (_) @value @value.leading.end.startOf
360-
) @_.domain
356+
(
357+
(_
358+
(_)? @value.leading.start.endOf
359+
.
360+
value: (_) @value @value.leading.end.startOf
361+
) @_.domain
362+
(#not-type? @_.domain variable_declarator)
363+
)
361364

362365
;;!! const aaa = {bbb};
363366
;;! ^^^

0 commit comments

Comments
 (0)