Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use multiline pairs for head/tail modifier. #2659

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,31 @@ 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) => ({
editor,
domain: scope.domain,
getTargets(isReversed) {
return scope
.getTargets(isReversed)
.flatMap((target) => target.getInterior()!);
},
}),
const scopes = this.surroundingPairScopeHandler.generateScopes(
editor,
position,
direction,
hints,
);

for (const scope of scopes) {
if (!this.scopeType.requireSingleLine || scope.domain.isSingleLine) {
AndreasArvidsson marked this conversation as resolved.
Show resolved Hide resolved
yield {
editor,
domain: scope.domain,
getTargets(isReversed) {
return scope
.getTargets(isReversed)
.flatMap((target) => target.getInterior()!);
},
};
}
}
}
}
Loading