Skip to content

Commit 0a8bb2b

Browse files
Added target textual type (#2765)
Fixes #2075 ## Checklist - [/] 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 --------- Co-authored-by: Phil Cohen <[email protected]>
1 parent 328a934 commit 0a8bb2b

20 files changed

+58
-60
lines changed

packages/cursorless-engine/src/actions/InsertEmptyLines.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,6 @@ function constructChangeEdit(
142142
): EditWithFlashType {
143143
return {
144144
...target.toDestination(insertionMode).constructChangeEdit("", true),
145-
isLine: target.isLine,
145+
isLine: target.textualType === "line",
146146
};
147147
}

packages/cursorless-engine/src/actions/JoinLines.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ function getEdits(editor: TextEditor, targets: Target[]): Edit[] {
6161

6262
for (const target of targets) {
6363
const targetsEdits =
64-
target.joinAs === "line"
65-
? getLineTargetEdits(target)
66-
: getTokenTargetEdits(target);
64+
target.textualType === "token"
65+
? getTokenTargetEdits(target)
66+
: getLineTargetEdits(target);
6767

6868
edits.push(...targetsEdits);
6969
}

packages/cursorless-engine/src/processTargets/createContinuousRangeTarget.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { Target } from "../typings/target.types";
22
import { isSameType } from "../util/typeUtils";
3+
import { LineTarget, UntypedTarget } from "./targets";
34
import {
45
createContinuousLineRange,
56
createContinuousRange,
67
} from "./targets/util/createContinuousRange";
7-
import { LineTarget, UntypedTarget } from "./targets";
88

99
/**
1010
* Creates a target consisting of a range between two targets. If the targets
@@ -48,7 +48,7 @@ export function createContinuousRangeTarget(
4848
}
4949
}
5050

51-
if (startTarget.isLine && endTarget.isLine) {
51+
if (startTarget.textualType === "line" && endTarget.textualType === "line") {
5252
return new LineTarget({
5353
editor: startTarget.editor,
5454
isReversed,
@@ -71,7 +71,12 @@ export function createContinuousRangeTarget(
7171
includeStart,
7272
includeEnd,
7373
),
74-
isToken:
75-
includeStart && includeEnd && startTarget.isToken && endTarget.isToken,
74+
textualType:
75+
includeStart &&
76+
includeEnd &&
77+
startTarget.textualType === "token" &&
78+
endTarget.textualType === "token"
79+
? "token"
80+
: "character",
7681
});
7782
}

packages/cursorless-engine/src/processTargets/marks/CursorStage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class CursorStage implements MarkStage {
1313
isReversed: selection.selection.isReversed,
1414
contentRange: selection.selection,
1515
hasExplicitRange: !selection.selection.isEmpty,
16-
isToken: false,
16+
textualType: "character",
1717
}),
1818
);
1919
}

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class InstanceStage implements ModifierStage {
135135
contentRange: range,
136136
editor,
137137
isReversed: false,
138-
isToken: false,
138+
textualType: "character",
139139
}),
140140
);
141141

@@ -182,19 +182,14 @@ export class InstanceStage implements ModifierStage {
182182
}
183183

184184
function getFilterScopeType(target: Target): ScopeType | null {
185-
if (target.isLine) {
186-
return { type: "line" };
185+
switch (target.textualType) {
186+
case "line":
187+
case "token":
188+
case "word":
189+
return { type: target.textualType };
190+
default:
191+
return null;
187192
}
188-
189-
if (target.isToken) {
190-
return { type: "token" };
191-
}
192-
193-
if (target.isWord) {
194-
return { type: "word" };
195-
}
196-
197-
return null;
198193
}
199194

200195
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ abstract class PositionStage implements ModifierStage {
1515
return [
1616
target.isRaw
1717
? new RawSelectionTarget(parameters)
18-
: new PlainTarget({ ...parameters, isToken: false }),
18+
: new PlainTarget({ ...parameters, textualType: "character" }),
1919
];
2020
}
2121

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/CharacterScopeHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class CharacterScopeHandler extends NestedScopeHandler {
3939
editor,
4040
contentRange: range,
4141
isReversed,
42-
isToken: false,
42+
textualType: "character",
4343
}),
4444
],
4545
}),

packages/cursorless-engine/src/processTargets/targets/BaseTarget.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { isEqual } from "lodash-es";
1212
import type { EditWithRangeUpdater } from "../../typings/Types";
1313
import type {
1414
Destination,
15-
JoinAsType,
1615
Target,
16+
TextualType,
1717
} from "../../typings/target.types";
1818
import { toGeneralizedRange } from "../../util/targetUtils";
1919
import { DestinationImpl } from "./DestinationImpl";
@@ -47,15 +47,12 @@ export abstract class BaseTarget<
4747
{
4848
protected abstract readonly type: string;
4949
protected readonly state: EnforceUndefined<CommonTargetParameters>;
50-
isLine = false;
51-
isToken = true;
5250
hasExplicitScopeType = true;
5351
hasExplicitRange = true;
5452
isRaw = false;
5553
isImplicit = false;
5654
isNotebookCell = false;
57-
isWord = false;
58-
joinAs: JoinAsType = "line";
55+
textualType: TextualType = "token";
5956

6057
constructor(parameters: TParameters & CommonTargetParameters) {
6158
this.state = {

packages/cursorless-engine/src/processTargets/targets/BoundedParagraphTarget.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { toLineRange, type Range } from "@cursorless/common";
22
import type { InteriorTarget, ParagraphTarget } from ".";
3+
import type { TextualType } from "../../typings/target.types";
34
import { expandToFullLine } from "../../util/rangeUtils";
45
import type { MinimumTargetParameters } from "./BaseTarget";
56
import { BaseTarget } from "./BaseTarget";
@@ -12,8 +13,8 @@ interface BoundedParagraphTargetParameters extends MinimumTargetParameters {
1213

1314
export class BoundedParagraphTarget extends BaseTarget<BoundedParagraphTargetParameters> {
1415
readonly type = "BoundedParagraphTarget";
16+
readonly textualType: TextualType = "line";
1517
readonly insertionDelimiter = "\n\n";
16-
readonly isLine = true;
1718
private containingInterior: InteriorTarget;
1819
private paragraphTarget: ParagraphTarget;
1920
private startLineGap: number;

packages/cursorless-engine/src/processTargets/targets/DocumentTarget.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type { Range } from "@cursorless/common";
2+
import type { TextualType } from "../../typings/target.types";
23
import { shrinkRangeToFitContent } from "../../util/selectionUtils";
34
import { BaseTarget, type CommonTargetParameters } from "./BaseTarget";
45
import { PlainTarget } from "./PlainTarget";
56

67
export class DocumentTarget extends BaseTarget<CommonTargetParameters> {
78
type = "DocumentTarget";
9+
textualType: TextualType = "line";
810
insertionDelimiter = "\n";
9-
isLine = true;
1011

1112
constructor(parameters: CommonTargetParameters) {
1213
super(parameters);

0 commit comments

Comments
 (0)