Skip to content

Commit

Permalink
Don't use multiline pairs for head/tail modifier. (#2659)
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
AndreasArvidsson authored Sep 18, 2024
1 parent 5448c2e commit 72c46b7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
28 changes: 28 additions & 0 deletions data/fixtures/recorded/headTail/changeTail3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
languageId: python
command:
version: 7
spokenForm: change tail
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- {type: extendThroughEndOf}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
"""foo
bar
"""
selections:
- anchor: {line: 0, character: 3}
active: {line: 0, character: 3}
marks: {}
finalState:
documentContents: |-
"""
bar
"""
selections:
- anchor: {line: 0, character: 3}
active: {line: 0, character: 3}
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ export interface SurroundingPairScopeType {
export interface SurroundingPairInteriorScopeType {
type: "surroundingPairInterior";
delimiter: SurroundingPairName;
// If true don't yield multiline pairs
requireSingleLine?: boolean;
}

export interface OneOfScopeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class HeadTailStage implements ModifierStage {
{
type: "surroundingPairInterior",
delimiter: "any",
requireSingleLine: true,
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { TargetScope } from "../scope.types";
import type { ScopeIteratorRequirements } from "../scopeHandler.types";
import { type ScopeHandler } from "../scopeHandler.types";
import type { ScopeHandlerFactory } from "../ScopeHandlerFactory";
import { map } from "itertools";

export class SurroundingPairInteriorScopeHandler extends BaseScopeHandler {
protected isHierarchical = true;
Expand All @@ -32,28 +31,33 @@ export class SurroundingPairInteriorScopeHandler extends BaseScopeHandler {
return this.surroundingPairScopeHandler.iterationScopeType;
}

generateScopeCandidates(
*generateScopeCandidates(
editor: TextEditor,
position: Position,
direction: Direction,
hints: ScopeIteratorRequirements,
): Iterable<TargetScope> {
return map(
this.surroundingPairScopeHandler.generateScopes(
editor,
position,
direction,
hints,
),
(scope) => ({
const scopes = this.surroundingPairScopeHandler.generateScopes(
editor,
position,
direction,
hints,
);

for (const scope of scopes) {
if (this.scopeType.requireSingleLine && !scope.domain.isSingleLine) {
continue;
}

yield {
editor,
domain: scope.domain,
getTargets(isReversed) {
return scope
.getTargets(isReversed)
.flatMap((target) => target.getInterior()!);
},
}),
);
};
}
}
}

0 comments on commit 72c46b7

Please sign in to comment.