Skip to content

Added generation of spoken form #1671

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

Merged
merged 8 commits into from
Aug 1, 2023
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 @@ -39,8 +39,8 @@ export interface RangeMark {
type: "range";
anchor: PartialMark;
active: PartialMark;
excludeAnchor?: boolean;
excludeActive?: boolean;
excludeAnchor: boolean;
excludeActive: boolean;
}

interface SimplePosition {
Expand Down Expand Up @@ -344,8 +344,8 @@ export interface RangeModifier {
type: "range";
anchor: Modifier;
active: Modifier;
excludeAnchor?: boolean;
excludeActive?: boolean;
excludeAnchor: boolean;
excludeActive: boolean;
}

export type Modifier =
Expand All @@ -369,6 +369,8 @@ export type Modifier =
| KeepEmptyFilterModifier
| InferPreviousMarkModifier;

export type ModifierType = Modifier["type"];

// continuous is one single continuous selection between the two targets
// vertical puts a selection on each line vertically between the two targets
export type PartialRangeType = "continuous" | "vertical";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ interface LineNumberMark {
*/
interface RangeMark {
type: "range";
anchor: Mark;
active: Mark;
anchor: MarkV4;
active: MarkV4;
excludeAnchor?: boolean;
excludeActive?: boolean;
}

type Mark =
export type MarkV4 =
| CursorMark
| ThatMark
| SourceMark
Expand Down Expand Up @@ -255,13 +255,13 @@ interface PositionModifier {

export interface PartialPrimitiveTargetDescriptorV4 {
type: "primitive";
mark?: Mark;
modifiers?: Modifier[];
mark?: MarkV4;
modifiers?: ModifierV4[];
}

interface HeadTailModifier {
type: "extendThroughStartOf" | "extendThroughEndOf";
modifiers?: Modifier[];
modifiers?: ModifierV4[];
}

/**
Expand All @@ -274,7 +274,7 @@ interface ModifyIfUntypedModifier {
/**
* The modifier to apply if the target is untyped
*/
modifier: Modifier;
modifier: ModifierV4;
}

/**
Expand All @@ -288,7 +288,7 @@ interface CascadingModifier {
/**
* The modifiers to try in turn
*/
modifiers: Modifier[];
modifiers: ModifierV4[];
}

/**
Expand All @@ -297,13 +297,13 @@ interface CascadingModifier {
*/
interface RangeModifier {
type: "range";
anchor: Modifier;
active: Modifier;
anchor: ModifierV4;
active: ModifierV4;
excludeAnchor?: boolean;
excludeActive?: boolean;
}

type Modifier =
export type ModifierV4 =
| PositionModifier
| InteriorOnlyModifier
| ExcludeInteriorModifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ interface LineNumberMark {
*/
interface RangeMark {
type: "range";
anchor: PartialMark;
active: PartialMark;
excludeAnchor?: boolean;
excludeActive?: boolean;
anchor: PartialMarkV5;
active: PartialMarkV5;
excludeAnchor: boolean;
excludeActive: boolean;
}

type PartialMark =
export type PartialMarkV5 =
| CursorMark
| ThatMark
| SourceMark
Expand Down Expand Up @@ -256,7 +256,7 @@ export interface PositionModifierV5 {

export interface PartialPrimitiveTargetDescriptorV5 {
type: "primitive";
mark?: PartialMark;
mark?: PartialMarkV5;
modifiers?: ModifierV5[];
}

Expand Down Expand Up @@ -300,8 +300,8 @@ interface RangeModifier {
type: "range";
anchor: ModifierV5;
active: ModifierV5;
excludeAnchor?: boolean;
excludeActive?: boolean;
excludeAnchor: boolean;
excludeActive: boolean;
}

export type ModifierV5 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ function upgradeModifier(modifier: ModifierV0V1): ModifierV2[] {
scopeType: rest,
} as const;

if (delimiterInclusion === "interiorOnly") {
return [{ type: "interiorOnly" }, surroundingPairModifier];
}

if (delimiterInclusion === "excludeInterior") {
return [{ type: "excludeInterior" }, surroundingPairModifier];
if (
delimiterInclusion === "interiorOnly" ||
delimiterInclusion === "excludeInterior"
) {
if (surroundingPairModifier.scopeType.delimiter === "any") {
return [{ type: delimiterInclusion }];
}
return [{ type: delimiterInclusion }, surroundingPairModifier];
}

return [surroundingPairModifier];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import { isEqual } from "lodash";
import { CommandV2 } from "@cursorless/common";
import { CommandV3 } from "@cursorless/common";
import {
CommandV2,
CommandV3,
LineNumberMarkV2,
LineNumberMarkV3,
LineNumberPositionV2,
MarkV2,
MarkV3,
ModifierV2,
ModifierV3,
OrdinalRangeModifierV2,
OrdinalScopeModifierV3,
PartialPrimitiveTargetDescriptorV2,
PartialPrimitiveTargetDescriptorV3,
PartialRangeTargetDescriptorV3,
PartialTargetDescriptorV2,
PartialTargetDescriptorV3,
RangeMarkV3,
RangeModifierV3,
} from "@cursorless/common";
import {
LineNumberMarkV2,
LineNumberPositionV2,
MarkV2,
ModifierV2,
OrdinalRangeModifierV2,
PartialPrimitiveTargetDescriptorV2,
PartialTargetDescriptorV2,
ScopeTypeV2,
} from "@cursorless/common";
import { isEqual } from "lodash";

export function upgradeV2ToV3(command: CommandV2): CommandV3 {
return {
Expand All @@ -48,8 +46,12 @@ function upgradeTarget(
case "range": {
const { anchor, active, ...rest } = target;
return {
anchor: upgradePrimitiveTarget(anchor),
active: upgradePrimitiveTarget(active),
anchor: upgradePrimitiveTarget(
anchor,
) as PartialPrimitiveTargetDescriptorV3,
active: upgradePrimitiveTarget(
active,
) as PartialPrimitiveTargetDescriptorV3,
...rest,
};
}
Expand All @@ -60,14 +62,37 @@ function upgradeTarget(

function upgradePrimitiveTarget(
target: PartialPrimitiveTargetDescriptorV2,
): PartialPrimitiveTargetDescriptorV3 {
): PartialPrimitiveTargetDescriptorV3 | PartialRangeTargetDescriptorV3 {
const modifiers =
target.modifiers != null ? target.modifiers.map(updateModifier) : undefined;

if (target.mark?.type === "lineNumber") {
const { anchor, active } = target.mark!;
if (
anchor.type !== active.type ||
anchor.lineNumber < 0 !== active.lineNumber < 0
) {
return {
type: "range",
anchor: {
type: "primitive",
mark: createLineNumberMarkFromPos(anchor),
modifiers,
},
active: {
type: "primitive",
mark: createLineNumberMarkFromPos(active),
},
excludeAnchor: false,
excludeActive: false,
};
}
}

return {
...target,
mark: target.mark != null ? updateMark(target.mark) : undefined,
modifiers:
target.modifiers != null
? target.modifiers.map(updateModifier)
: undefined,
modifiers,
};
}

Expand Down Expand Up @@ -110,6 +135,22 @@ function createOrdinalModifier(
return createAbsoluteOrdinalModifier(modifier.scopeType, modifier.anchor);
}

if (modifier.anchor === 0 && modifier.active > modifier.anchor) {
return createAbsoluteOrdinalModifier(
modifier.scopeType,
modifier.anchor,
modifier.active - modifier.anchor + 1,
);
}

if (modifier.anchor < 0 && modifier.active === -1) {
return createAbsoluteOrdinalModifier(
modifier.scopeType,
modifier.anchor,
-modifier.anchor,
);
}

return {
type: "range",
anchor: createAbsoluteOrdinalModifier(modifier.scopeType, modifier.anchor),
Expand All @@ -132,11 +173,12 @@ function createLineNumberMarkFromPos(
function createAbsoluteOrdinalModifier(
scopeType: ScopeTypeV2,
start: number,
length = 1,
): OrdinalScopeModifierV3 {
return {
type: "ordinalScope",
scopeType,
start,
length: 1,
length,
};
}
Loading