Skip to content

Commit 2298c73

Browse files
head/tail are bounded by all interiors not just pair (#3070)
Today if you don't specify a scope after head/tail we default to the line bounded by optional surrounding pair interior. This change makes it so we use any interior. I gotten really used to head/tail being bounded by interior, but lately I've been doing a lot of jsx and I keep trying to use head and tail inside of a jsx element and accidentally removing half the line.
1 parent 5d57ea4 commit 2298c73

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: typescriptreact
2+
command:
3+
version: 7
4+
spokenForm: change head
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- {type: extendThroughStartOf}
11+
usePrePhraseSnapshot: false
12+
initialState:
13+
documentContents: <div>abcd</div>
14+
selections:
15+
- anchor: {line: 0, character: 7}
16+
active: {line: 0, character: 7}
17+
marks: {}
18+
finalState:
19+
documentContents: <div>cd</div>
20+
selections:
21+
- anchor: {line: 0, character: 5}
22+
active: {line: 0, character: 5}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: typescriptreact
2+
command:
3+
version: 7
4+
spokenForm: change tail
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- {type: extendThroughEndOf}
11+
usePrePhraseSnapshot: false
12+
initialState:
13+
documentContents: <div>abcd</div>
14+
selections:
15+
- anchor: {line: 0, character: 7}
16+
active: {line: 0, character: 7}
17+
marks: {}
18+
finalState:
19+
documentContents: <div>ab</div>
20+
selections:
21+
- anchor: {line: 0, character: 7}
22+
active: {line: 0, character: 7}

packages/cursorless-engine/src/processTargets/modifiers/HeadTailStage.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ class BoundedLineStage implements ModifierStage {
7474

7575
run(target: Target, options: ModifierStateOptions): Target[] {
7676
const line = this.getContainingLine(target, options);
77-
const pairInterior = this.getContainingPairInterior(target, options);
77+
const interior = this.getContainingInterior(target, options);
7878

7979
const intersection =
80-
pairInterior != null
81-
? line.contentRange.intersection(pairInterior.contentRange)
80+
interior != null
81+
? line.contentRange.intersection(interior.contentRange)
8282
: null;
8383

8484
if (intersection == null || intersection.isEmpty) {
@@ -94,15 +94,14 @@ class BoundedLineStage implements ModifierStage {
9494
];
9595
}
9696

97-
private getContainingPairInterior(
97+
private getContainingInterior(
9898
target: Target,
9999
options: ModifierStateOptions,
100100
): Target | undefined {
101101
try {
102102
return this.getContaining(target, options, {
103-
type: "surroundingPairInterior",
104-
delimiter: "any",
105-
})[0];
103+
type: "interior",
104+
});
106105
} catch (error) {
107106
if (error instanceof NoContainingScopeError) {
108107
return undefined;
@@ -117,16 +116,16 @@ class BoundedLineStage implements ModifierStage {
117116
): Target {
118117
return this.getContaining(target, options, {
119118
type: "line",
120-
})[0];
119+
});
121120
}
122121

123122
private getContaining(
124123
target: Target,
125124
options: ModifierStateOptions,
126125
scopeType: ScopeType,
127-
): Target[] {
126+
): Target {
128127
return this.modifierStageFactory
129128
.create({ type: "containingScope", scopeType })
130-
.run(target, options);
129+
.run(target, options)[0];
131130
}
132131
}

0 commit comments

Comments
 (0)