Skip to content

Commit 72c46b7

Browse files
Don't use multiline pairs for head/tail modifier. (#2659)
`change tail` did the wrong thing in this case ```py """|foo bar """ ``` ## Checklist - [x] 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 5448c2e commit 72c46b7

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
languageId: python
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: true
12+
initialState:
13+
documentContents: |-
14+
"""foo
15+
bar
16+
"""
17+
selections:
18+
- anchor: {line: 0, character: 3}
19+
active: {line: 0, character: 3}
20+
marks: {}
21+
finalState:
22+
documentContents: |-
23+
"""
24+
bar
25+
"""
26+
selections:
27+
- anchor: {line: 0, character: 3}
28+
active: {line: 0, character: 3}

packages/common/src/types/command/PartialTargetDescriptor.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ export interface SurroundingPairScopeType {
251251
export interface SurroundingPairInteriorScopeType {
252252
type: "surroundingPairInterior";
253253
delimiter: SurroundingPairName;
254+
// If true don't yield multiline pairs
255+
requireSingleLine?: boolean;
254256
}
255257

256258
export interface OneOfScopeType {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class HeadTailStage implements ModifierStage {
2727
{
2828
type: "surroundingPairInterior",
2929
delimiter: "any",
30+
requireSingleLine: true,
3031
},
3132
],
3233
},

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/SurroundingPairInteriorScopeHandler.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type { TargetScope } from "../scope.types";
55
import type { ScopeIteratorRequirements } from "../scopeHandler.types";
66
import { type ScopeHandler } from "../scopeHandler.types";
77
import type { ScopeHandlerFactory } from "../ScopeHandlerFactory";
8-
import { map } from "itertools";
98

109
export class SurroundingPairInteriorScopeHandler extends BaseScopeHandler {
1110
protected isHierarchical = true;
@@ -32,28 +31,33 @@ export class SurroundingPairInteriorScopeHandler extends BaseScopeHandler {
3231
return this.surroundingPairScopeHandler.iterationScopeType;
3332
}
3433

35-
generateScopeCandidates(
34+
*generateScopeCandidates(
3635
editor: TextEditor,
3736
position: Position,
3837
direction: Direction,
3938
hints: ScopeIteratorRequirements,
4039
): Iterable<TargetScope> {
41-
return map(
42-
this.surroundingPairScopeHandler.generateScopes(
43-
editor,
44-
position,
45-
direction,
46-
hints,
47-
),
48-
(scope) => ({
40+
const scopes = this.surroundingPairScopeHandler.generateScopes(
41+
editor,
42+
position,
43+
direction,
44+
hints,
45+
);
46+
47+
for (const scope of scopes) {
48+
if (this.scopeType.requireSingleLine && !scope.domain.isSingleLine) {
49+
continue;
50+
}
51+
52+
yield {
4953
editor,
5054
domain: scope.domain,
5155
getTargets(isReversed) {
5256
return scope
5357
.getTargets(isReversed)
5458
.flatMap((target) => target.getInterior()!);
5559
},
56-
}),
57-
);
60+
};
61+
}
5862
}
5963
}

0 commit comments

Comments
 (0)