Skip to content

Commit 5a905ea

Browse files
Added tests
1 parent bd86a64 commit 5a905ea

File tree

5 files changed

+132
-9
lines changed

5 files changed

+132
-9
lines changed

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/ContiguousScopeHandler.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,26 @@ function combineScopes(scope1: TargetScope, scope2: TargetScope): TargetScope {
8484
return {
8585
editor: scope1.editor,
8686
domain: scope1.domain.union(scope2.domain),
87-
getTargets: (isReversed) => [
88-
createContinuousRangeTarget(
89-
isReversed,
90-
scope1.getTargets(false)[0],
91-
scope2.getTargets(false)[0],
92-
true,
93-
true,
94-
),
95-
],
87+
getTargets: (isReversed) => {
88+
const target1 = scope1.getTargets(isReversed)[0];
89+
const target2 = scope2.getTargets(isReversed)[0];
90+
91+
const [startTarget, endTarget] = target1.contentRange.start.isBefore(
92+
target2.contentRange.start,
93+
)
94+
? [target1, target2]
95+
: [target2, target1];
96+
97+
return [
98+
createContinuousRangeTarget(
99+
isReversed,
100+
startTarget,
101+
endTarget,
102+
true,
103+
true,
104+
),
105+
];
106+
},
96107
};
97108
}
98109

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

0 commit comments

Comments
 (0)