Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 22 additions & 0 deletions data/fixtures/recorded/modifiers/interior/changeHead.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: typescriptreact
command:
version: 7
spokenForm: change head
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- {type: extendThroughStartOf}
usePrePhraseSnapshot: false
initialState:
documentContents: <div>abcd</div>
selections:
- anchor: {line: 0, character: 7}
active: {line: 0, character: 7}
marks: {}
finalState:
documentContents: <div>cd</div>
selections:
- anchor: {line: 0, character: 5}
active: {line: 0, character: 5}
22 changes: 22 additions & 0 deletions data/fixtures/recorded/modifiers/interior/changeTail.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: typescriptreact
command:
version: 7
spokenForm: change tail
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- {type: extendThroughEndOf}
usePrePhraseSnapshot: false
initialState:
documentContents: <div>abcd</div>
selections:
- anchor: {line: 0, character: 7}
active: {line: 0, character: 7}
marks: {}
finalState:
documentContents: <div>ab</div>
selections:
- anchor: {line: 0, character: 7}
active: {line: 0, character: 7}
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ class BoundedLineStage implements ModifierStage {

run(target: Target, options: ModifierStateOptions): Target[] {
const line = this.getContainingLine(target, options);
const pairInterior = this.getContainingPairInterior(target, options);
const interior = this.getContainingInterior(target, options);

const intersection =
pairInterior != null
? line.contentRange.intersection(pairInterior.contentRange)
interior != null
? line.contentRange.intersection(interior.contentRange)
: null;

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

private getContainingPairInterior(
private getContainingInterior(
target: Target,
options: ModifierStateOptions,
): Target | undefined {
try {
return this.getContaining(target, options, {
type: "surroundingPairInterior",
delimiter: "any",
})[0];
type: "interior",
});
} catch (error) {
if (error instanceof NoContainingScopeError) {
return undefined;
Expand All @@ -117,16 +116,16 @@ class BoundedLineStage implements ModifierStage {
): Target {
return this.getContaining(target, options, {
type: "line",
})[0];
});
}

private getContaining(
target: Target,
options: ModifierStateOptions,
scopeType: ScopeType,
): Target[] {
): Target {
return this.modifierStageFactory
.create({ type: "containingScope", scopeType })
.run(target, options);
.run(target, options)[0];
}
}
Loading