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
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,6 @@ function constructChangeEdit(
): EditWithFlashType {
return {
...target.toDestination(insertionMode).constructChangeEdit("", true),
isLine: target.isLine,
isLine: target.textualType === "line",
};
}
6 changes: 3 additions & 3 deletions packages/cursorless-engine/src/actions/JoinLines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ function getEdits(editor: TextEditor, targets: Target[]): Edit[] {

for (const target of targets) {
const targetsEdits =
target.joinAs === "line"
? getLineTargetEdits(target)
: getTokenTargetEdits(target);
target.textualType === "token"
? getTokenTargetEdits(target)
: getLineTargetEdits(target);

edits.push(...targetsEdits);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Target } from "../typings/target.types";
import { isSameType } from "../util/typeUtils";
import { LineTarget, UntypedTarget } from "./targets";
import {
createContinuousLineRange,
createContinuousRange,
} from "./targets/util/createContinuousRange";
import { LineTarget, UntypedTarget } from "./targets";

/**
* Creates a target consisting of a range between two targets. If the targets
Expand Down Expand Up @@ -48,7 +48,7 @@ export function createContinuousRangeTarget(
}
}

if (startTarget.isLine && endTarget.isLine) {
if (startTarget.textualType === "line" && endTarget.textualType === "line") {
return new LineTarget({
editor: startTarget.editor,
isReversed,
Expand All @@ -71,7 +71,12 @@ export function createContinuousRangeTarget(
includeStart,
includeEnd,
),
isToken:
includeStart && includeEnd && startTarget.isToken && endTarget.isToken,
textualType:
includeStart &&
includeEnd &&
startTarget.textualType === "token" &&
endTarget.textualType === "token"
? "token"
: "character",
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class CursorStage implements MarkStage {
isReversed: selection.selection.isReversed,
contentRange: selection.selection,
hasExplicitRange: !selection.selection.isEmpty,
isToken: false,
textualType: "character",
}),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class InstanceStage implements ModifierStage {
contentRange: range,
editor,
isReversed: false,
isToken: false,
textualType: "character",
}),
);

Expand Down Expand Up @@ -182,19 +182,14 @@ export class InstanceStage implements ModifierStage {
}

function getFilterScopeType(target: Target): ScopeType | null {
if (target.isLine) {
return { type: "line" };
switch (target.textualType) {
case "line":
case "token":
case "word":
return { type: target.textualType };
default:
return null;
}

if (target.isToken) {
return { type: "token" };
}

if (target.isWord) {
return { type: "word" };
}

return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class PositionStage implements ModifierStage {
return [
target.isRaw
? new RawSelectionTarget(parameters)
: new PlainTarget({ ...parameters, isToken: false }),
: new PlainTarget({ ...parameters, textualType: "character" }),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class CharacterScopeHandler extends NestedScopeHandler {
editor,
contentRange: range,
isReversed,
isToken: false,
textualType: "character",
}),
],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { isEqual } from "lodash-es";
import type { EditWithRangeUpdater } from "../../typings/Types";
import type {
Destination,
JoinAsType,
Target,
TextualType,
} from "../../typings/target.types";
import { toGeneralizedRange } from "../../util/targetUtils";
import { DestinationImpl } from "./DestinationImpl";
Expand Down Expand Up @@ -47,15 +47,12 @@ export abstract class BaseTarget<
{
protected abstract readonly type: string;
protected readonly state: EnforceUndefined<CommonTargetParameters>;
isLine = false;
isToken = true;
hasExplicitScopeType = true;
hasExplicitRange = true;
isRaw = false;
isImplicit = false;
isNotebookCell = false;
isWord = false;
joinAs: JoinAsType = "line";
textualType: TextualType = "token";

constructor(parameters: TParameters & CommonTargetParameters) {
this.state = {
Expand All @@ -69,6 +66,7 @@ export abstract class BaseTarget<
get editor() {
return this.state.editor;
}

get isReversed() {
return this.state.isReversed;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { toLineRange, type Range } from "@cursorless/common";
import type { InteriorTarget, ParagraphTarget } from ".";
import type { TextualType } from "../../typings/target.types";
import { expandToFullLine } from "../../util/rangeUtils";
import type { MinimumTargetParameters } from "./BaseTarget";
import { BaseTarget } from "./BaseTarget";
Expand All @@ -12,8 +13,8 @@ interface BoundedParagraphTargetParameters extends MinimumTargetParameters {

export class BoundedParagraphTarget extends BaseTarget<BoundedParagraphTargetParameters> {
readonly type = "BoundedParagraphTarget";
readonly textualType: TextualType = "line";
readonly insertionDelimiter = "\n\n";
readonly isLine = true;
private containingInterior: InteriorTarget;
private paragraphTarget: ParagraphTarget;
private startLineGap: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { Range } from "@cursorless/common";
import type { TextualType } from "../../typings/target.types";
import { shrinkRangeToFitContent } from "../../util/selectionUtils";
import type { CommonTargetParameters } from "./BaseTarget";
import { BaseTarget } from "./BaseTarget";
import { PlainTarget } from "./PlainTarget";

export class DocumentTarget extends BaseTarget<CommonTargetParameters> {
type = "DocumentTarget";
textualType: TextualType = "line";
insertionDelimiter = "\n";
isLine = true;

constructor(parameters: CommonTargetParameters) {
super(parameters);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { EnforceUndefined } from "@cursorless/common";
import type { TextualType } from "../../typings/target.types";
import type { CommonTargetParameters } from "./BaseTarget";
import { BaseTarget } from "./BaseTarget";

Expand All @@ -10,11 +11,11 @@ import { BaseTarget } from "./BaseTarget";
*/
export class ImplicitTarget extends BaseTarget<CommonTargetParameters> {
type = "ImplicitTarget";
textualType: TextualType = "character";
insertionDelimiter = "";
isRaw = true;
hasExplicitScopeType = false;
isImplicit = true;
isToken = false;

getLeadingDelimiterTarget = () => undefined;
getTrailingDelimiterTarget = () => undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { TextEditor } from "@cursorless/common";
import { Position, Range, toLineRange } from "@cursorless/common";
import type { TextualType } from "../../typings/target.types";
import { expandToFullLine } from "../../util/rangeUtils";
import { tryConstructTarget } from "../../util/tryConstructTarget";
import type { CommonTargetParameters } from "./BaseTarget";
Expand All @@ -9,8 +10,8 @@ import { createContinuousLineRange } from "./util/createContinuousRange";

export class LineTarget extends BaseTarget<CommonTargetParameters> {
type = "LineTarget";
textualType: TextualType = "line";
insertionDelimiter = "\n";
isLine = true;

private get fullLineContentRange() {
return expandToFullLine(this.editor, this.contentRange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
TextLine,
} from "@cursorless/common";
import { Position, Range, toLineRange } from "@cursorless/common";
import type { TextualType } from "../../typings/target.types";
import { expandToFullLine } from "../../util/rangeUtils";
import type { CommonTargetParameters } from "./BaseTarget";
import { BaseTarget } from "./BaseTarget";
Expand All @@ -13,8 +14,8 @@ import { createContinuousLineRange } from "./util/createContinuousRange";

export class ParagraphTarget extends BaseTarget<CommonTargetParameters> {
type = "ParagraphTarget";
textualType: TextualType = "line";
insertionDelimiter = "\n\n";
isLine = true;

getLeadingDelimiterTarget() {
return constructLineTarget(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { Range, TextEditor } from "@cursorless/common";
import type { TextualType } from "../../typings/target.types";
import { tryConstructTarget } from "../../util/tryConstructTarget";
import type { TextEditor, Range } from "@cursorless/common";
import type { CommonTargetParameters } from "./BaseTarget";
import { BaseTarget } from "./BaseTarget";

interface PlainTargetParameters extends CommonTargetParameters {
readonly isToken?: boolean;
readonly textualType?: TextualType;
readonly insertionDelimiter?: string;
}

Expand All @@ -19,7 +20,7 @@ export class PlainTarget extends BaseTarget<PlainTargetParameters> {

constructor(parameters: PlainTargetParameters) {
super(parameters);
this.isToken = parameters.isToken ?? true;
this.textualType = parameters.textualType ?? "token";
this.insertionDelimiter = parameters.insertionDelimiter ?? "";
}

Expand All @@ -30,7 +31,7 @@ export class PlainTarget extends BaseTarget<PlainTargetParameters> {
protected getCloneParameters() {
return {
...this.state,
isToken: this.isToken,
textualType: this.textualType,
insertionDelimiter: this.insertionDelimiter,
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { EnforceUndefined } from "@cursorless/common";
import type { TextualType } from "../../typings/target.types";
import type { CommonTargetParameters } from "./BaseTarget";
import { BaseTarget } from "./BaseTarget";

Expand All @@ -9,9 +10,9 @@ import { BaseTarget } from "./BaseTarget";
*/
export class RawSelectionTarget extends BaseTarget<CommonTargetParameters> {
type = "RawSelectionTarget";
textualType: TextualType = "character";
insertionDelimiter = "";
isRaw = true;
isToken = false;

getLeadingDelimiterTarget = () => undefined;
getTrailingDelimiterTarget = () => undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Range } from "@cursorless/common";
import type { TextualType } from "../../typings/target.types";
import type { CommonTargetParameters } from "./BaseTarget";
import { BaseTarget } from "./BaseTarget";
import { tryConstructPlainTarget } from "./PlainTarget";
Expand All @@ -13,11 +14,10 @@ export interface SubTokenTargetParameters extends CommonTargetParameters {

export class SubTokenWordTarget extends BaseTarget<SubTokenTargetParameters> {
type = "SubTokenWordTarget";
textualType: TextualType = "word";
private leadingDelimiterRange_?: Range;
private trailingDelimiterRange_?: Range;
insertionDelimiter: string;
isToken = false;
isWord = true;

constructor(parameters: SubTokenTargetParameters) {
super(parameters);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Range } from "@cursorless/common";
import type { JoinAsType, Target } from "../../typings/target.types";
import type { Target, TextualType } from "../../typings/target.types";
import type { CommonTargetParameters } from "./BaseTarget";
import { BaseTarget } from "./BaseTarget";
import {
Expand All @@ -10,8 +10,8 @@ import {

export class TokenTarget extends BaseTarget<CommonTargetParameters> {
type = "TokenTarget";
textualType: TextualType = "token";
insertionDelimiter = " ";
joinAs: JoinAsType = "token";

getLeadingDelimiterTarget(): Target | undefined {
return getTokenLeadingDelimiterTarget(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Range } from "@cursorless/common";
import type { Target, TextualType } from "../../typings/target.types";
import type { CommonTargetParameters } from "./BaseTarget";
import { BaseTarget } from "./BaseTarget";
import type { Target } from "../../typings/target.types";
import {
getTokenLeadingDelimiterTarget,
getTokenRemovalRange,
Expand All @@ -10,7 +10,7 @@ import {

interface UntypedTargetParameters extends CommonTargetParameters {
readonly hasExplicitRange: boolean;
readonly isToken?: boolean;
readonly textualType?: TextualType;
}

/**
Expand All @@ -26,7 +26,7 @@ export class UntypedTarget extends BaseTarget<UntypedTargetParameters> {
constructor(parameters: UntypedTargetParameters) {
super(parameters);
this.hasExplicitRange = parameters.hasExplicitRange;
this.isToken = parameters.isToken ?? true;
this.textualType = parameters.textualType ?? "token";
}

getLeadingDelimiterTarget(): Target | undefined {
Expand All @@ -52,7 +52,7 @@ export class UntypedTarget extends BaseTarget<UntypedTargetParameters> {
protected getCloneParameters() {
return {
...this.state,
isToken: this.isToken,
textualType: this.textualType,
hasExplicitRange: this.hasExplicitRange,
};
}
Expand Down
16 changes: 4 additions & 12 deletions packages/cursorless-engine/src/typings/target.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import type {
import type { EditWithRangeUpdater } from "./Types";

export type EditNewActionType = "edit" | "insertLineAfter";
export type JoinAsType = "line" | "token";

export type TextualType = "character" | "word" | "token" | "line";

export interface Target {
/** The text editor used for all ranges */
Expand All @@ -47,17 +48,8 @@ export interface Target {
/** Optional prefix. For example, dash or asterisk for a markdown item */
readonly prefixRange?: Range;

/** If true this target should be treated as a line */
readonly isLine: boolean;

/** If true this target should be treated as a token */
readonly isToken: boolean;

/** If true this target should be treated as a word */
readonly isWord: boolean;

/** Specifies how a target should be joined */
readonly joinAs: JoinAsType;
/** Targets textual type. Is this target a line, a token, etc... */
readonly textualType: TextualType;

/**
* If `true`, then this target has an explicit scope type, and so should never
Expand Down
Loading
Loading