Skip to content

Commit c6ee509

Browse files
Started working on target type
1 parent 181cd9f commit c6ee509

28 files changed

+127
-76
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class CutToClipboard implements SimpleAction {
2121
const { editor, contentRange } = target;
2222
const removalHighlightRange = target.getRemovalHighlightRange();
2323

24-
if (target.isLine) {
24+
if (isLine(target)) {
2525
return [
2626
{
2727
editor,
@@ -63,6 +63,11 @@ export class CutToClipboard implements SimpleAction {
6363
}
6464
}
6565

66+
function isLine(target: Target): boolean {
67+
const { type } = target;
68+
return type === "line" || type === "paragraph" || type === "document";
69+
}
70+
6671
/** Get the possible leading and trailing overflow ranges of the outside range compared to the inside range */
6772
function getOutsideOverflow(insideRange: Range, outsideRange: Range): Range[] {
6873
const { start: insideStart, end: insideEnd } = insideRange;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class EditNew {
1818
}
1919

2020
async run(destinations: Destination[]): Promise<ActionReturnValue> {
21-
if (destinations.some(({ target }) => target.isNotebookCell)) {
21+
if (destinations.some(({ target }) => target.type === "notebookCell")) {
2222
// It is not possible to "pour" a notebook cell and something else,
2323
// because each notebook cell is its own editor, and you can't have
2424
// cursors in multiple editors.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ function constructChangeEdit(
142142
): EditWithFlashType {
143143
return {
144144
...target.toDestination(insertionMode).constructChangeEdit("", true),
145-
isLine: target.isLine,
145+
isLine: isLine(target),
146146
};
147147
}
148+
149+
function isLine(target: Target): boolean {
150+
const { type } = target;
151+
return type === "line" || type === "paragraph" || type === "document";
152+
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default class ToggleBreakpoint implements SimpleAction {
2525
const breakpointDescriptors: BreakpointDescriptor[] = targets.map(
2626
(target) => {
2727
const range = target.contentRange;
28-
return target.isLine
28+
return isLine(target)
2929
? {
3030
type: "line",
3131
startLine: range.start.line,
@@ -48,3 +48,8 @@ export default class ToggleBreakpoint implements SimpleAction {
4848
};
4949
}
5050
}
51+
52+
function isLine(target: Target): boolean {
53+
const { type } = target;
54+
return type === "line" || type === "paragraph" || type === "document";
55+
}

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function createContinuousRangeTarget(
4848
}
4949
}
5050

51-
if (startTarget.isLine && endTarget.isLine) {
51+
if (isLine(startTarget) && isLine(endTarget)) {
5252
return new LineTarget({
5353
editor: startTarget.editor,
5454
isReversed,
@@ -71,7 +71,17 @@ export function createContinuousRangeTarget(
7171
includeStart,
7272
includeEnd,
7373
),
74-
isToken:
75-
includeStart && includeEnd && startTarget.isToken && endTarget.isToken,
74+
type:
75+
includeStart &&
76+
includeEnd &&
77+
startTarget.type === "token" &&
78+
endTarget.type === "token"
79+
? "token"
80+
: "character",
7681
});
7782
}
83+
84+
function isLine(target: Target): boolean {
85+
const { type } = target;
86+
return type === "line" || type === "paragraph" || type === "document";
87+
}

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+
type: "character",
1717
}),
1818
);
1919
}

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

Lines changed: 10 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+
type: "character",
139139
}),
140140
);
141141

@@ -182,19 +182,16 @@ 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.type) {
186+
case "line":
187+
return { type: "line" };
188+
case "token":
189+
return { type: "token" };
190+
case "word":
191+
return { type: "word" };
192+
default:
193+
return null;
187194
}
188-
189-
if (target.isToken) {
190-
return { type: "token" };
191-
}
192-
193-
if (target.isWord) {
194-
return { type: "word" };
195-
}
196-
197-
return null;
198195
}
199196

200197
/**

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, type: "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+
type: "character",
4343
}),
4444
],
4545
}),

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
Destination,
1414
JoinAsType,
1515
Target,
16+
TargetType,
1617
} from "../../typings/target.types";
1718
import { DestinationImpl } from "./DestinationImpl";
1819
import { createContinuousRange } from "./util/createContinuousRange";
@@ -43,17 +44,15 @@ export abstract class BaseTarget<
4344
in out TParameters extends MinimumTargetParameters,
4445
> implements Target
4546
{
46-
protected abstract readonly type: string;
47+
protected abstract readonly instanceType: string;
4748
protected readonly state: EnforceUndefined<CommonTargetParameters>;
48-
isLine = false;
49-
isToken = true;
5049
hasExplicitScopeType = true;
5150
hasExplicitRange = true;
5251
isRaw = false;
5352
isImplicit = false;
5453
isNotebookCell = false;
55-
isWord = false;
5654
joinAs: JoinAsType = "line";
55+
type: TargetType = "token";
5756

5857
constructor(parameters: TParameters & CommonTargetParameters) {
5958
this.state = {
@@ -177,14 +176,14 @@ export abstract class BaseTarget<
177176
*
178177
* Note that this implementation is quite incomplete, but is suitable for
179178
* round-tripping {@link UntypedTarget} objects and capturing the fact that an
180-
* object is not an un typed target if it is not, via the {@link type}
179+
* object is not an un typed target if it is not, via the {@link instanceType}
181180
* attribute. In the future, we should override this method in subclasses to
182181
* provide a more complete representation.
183182
* @returns A plain object representation of the target
184183
*/
185184
toPlainObject(): TargetPlainObject {
186185
return {
187-
type: this.type,
186+
type: this.instanceType,
188187
contentRange: rangeToPlainObject(this.contentRange),
189188
isReversed: this.isReversed,
190189
hasExplicitRange: this.hasExplicitRange,

0 commit comments

Comments
 (0)