Skip to content

Commit 9718dde

Browse files
AndreasArvidssonpokeypre-commit-ci-lite[bot]
authored
Added generation of spoken form (#1671)
## Checklist - [x] Use spoken form generation when recording tests. Update message with the generated spoken form. - [x] 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 - [x] Add tests for list targets with 0 and 1 element, ensuring there's no spoken form - [x] Add tests for list destination with 0 and 1 element, ensuring there's no spoken form --------- Co-authored-by: Pokey Rule <[email protected]> Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 039e6a9 commit 9718dde

29 files changed

+1661
-86
lines changed

packages/common/src/types/command/PartialTargetDescriptor.types.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export interface RangeMark {
3939
type: "range";
4040
anchor: PartialMark;
4141
active: PartialMark;
42-
excludeAnchor?: boolean;
43-
excludeActive?: boolean;
42+
excludeAnchor: boolean;
43+
excludeActive: boolean;
4444
}
4545

4646
interface SimplePosition {
@@ -344,8 +344,8 @@ export interface RangeModifier {
344344
type: "range";
345345
anchor: Modifier;
346346
active: Modifier;
347-
excludeAnchor?: boolean;
348-
excludeActive?: boolean;
347+
excludeAnchor: boolean;
348+
excludeActive: boolean;
349349
}
350350

351351
export type Modifier =
@@ -369,6 +369,8 @@ export type Modifier =
369369
| KeepEmptyFilterModifier
370370
| InferPreviousMarkModifier;
371371

372+
export type ModifierType = Modifier["type"];
373+
372374
// continuous is one single continuous selection between the two targets
373375
// vertical puts a selection on each line vertically between the two targets
374376
export type PartialRangeType = "continuous" | "vertical";

packages/common/src/types/command/legacy/PartialTargetDescriptorV4.types.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ interface LineNumberMark {
3333
*/
3434
interface RangeMark {
3535
type: "range";
36-
anchor: Mark;
37-
active: Mark;
36+
anchor: MarkV4;
37+
active: MarkV4;
3838
excludeAnchor?: boolean;
3939
excludeActive?: boolean;
4040
}
4141

42-
type Mark =
42+
export type MarkV4 =
4343
| CursorMark
4444
| ThatMark
4545
| SourceMark
@@ -255,13 +255,13 @@ interface PositionModifier {
255255

256256
export interface PartialPrimitiveTargetDescriptorV4 {
257257
type: "primitive";
258-
mark?: Mark;
259-
modifiers?: Modifier[];
258+
mark?: MarkV4;
259+
modifiers?: ModifierV4[];
260260
}
261261

262262
interface HeadTailModifier {
263263
type: "extendThroughStartOf" | "extendThroughEndOf";
264-
modifiers?: Modifier[];
264+
modifiers?: ModifierV4[];
265265
}
266266

267267
/**
@@ -274,7 +274,7 @@ interface ModifyIfUntypedModifier {
274274
/**
275275
* The modifier to apply if the target is untyped
276276
*/
277-
modifier: Modifier;
277+
modifier: ModifierV4;
278278
}
279279

280280
/**
@@ -288,7 +288,7 @@ interface CascadingModifier {
288288
/**
289289
* The modifiers to try in turn
290290
*/
291-
modifiers: Modifier[];
291+
modifiers: ModifierV4[];
292292
}
293293

294294
/**
@@ -297,13 +297,13 @@ interface CascadingModifier {
297297
*/
298298
interface RangeModifier {
299299
type: "range";
300-
anchor: Modifier;
301-
active: Modifier;
300+
anchor: ModifierV4;
301+
active: ModifierV4;
302302
excludeAnchor?: boolean;
303303
excludeActive?: boolean;
304304
}
305305

306-
type Modifier =
306+
export type ModifierV4 =
307307
| PositionModifier
308308
| InteriorOnlyModifier
309309
| ExcludeInteriorModifier

packages/common/src/types/command/legacy/PartialTargetDescriptorV5.types.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ interface LineNumberMark {
3333
*/
3434
interface RangeMark {
3535
type: "range";
36-
anchor: PartialMark;
37-
active: PartialMark;
38-
excludeAnchor?: boolean;
39-
excludeActive?: boolean;
36+
anchor: PartialMarkV5;
37+
active: PartialMarkV5;
38+
excludeAnchor: boolean;
39+
excludeActive: boolean;
4040
}
4141

42-
type PartialMark =
42+
export type PartialMarkV5 =
4343
| CursorMark
4444
| ThatMark
4545
| SourceMark
@@ -256,7 +256,7 @@ export interface PositionModifierV5 {
256256

257257
export interface PartialPrimitiveTargetDescriptorV5 {
258258
type: "primitive";
259-
mark?: PartialMark;
259+
mark?: PartialMarkV5;
260260
modifiers?: ModifierV5[];
261261
}
262262

@@ -300,8 +300,8 @@ interface RangeModifier {
300300
type: "range";
301301
anchor: ModifierV5;
302302
active: ModifierV5;
303-
excludeAnchor?: boolean;
304-
excludeActive?: boolean;
303+
excludeAnchor: boolean;
304+
excludeActive: boolean;
305305
}
306306

307307
export type ModifierV5 =

packages/cursorless-engine/src/core/commandVersionUpgrades/upgradeV1ToV2/upgradeV1ToV2.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ function upgradeModifier(modifier: ModifierV0V1): ModifierV2[] {
5555
scopeType: rest,
5656
} as const;
5757

58-
if (delimiterInclusion === "interiorOnly") {
59-
return [{ type: "interiorOnly" }, surroundingPairModifier];
60-
}
61-
62-
if (delimiterInclusion === "excludeInterior") {
63-
return [{ type: "excludeInterior" }, surroundingPairModifier];
58+
if (
59+
delimiterInclusion === "interiorOnly" ||
60+
delimiterInclusion === "excludeInterior"
61+
) {
62+
if (surroundingPairModifier.scopeType.delimiter === "any") {
63+
return [{ type: delimiterInclusion }];
64+
}
65+
return [{ type: delimiterInclusion }, surroundingPairModifier];
6466
}
6567

6668
return [surroundingPairModifier];

packages/cursorless-engine/src/core/commandVersionUpgrades/upgradeV2ToV3/upgradeV2ToV3.ts

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
import { isEqual } from "lodash";
2-
import { CommandV2 } from "@cursorless/common";
3-
import { CommandV3 } from "@cursorless/common";
41
import {
2+
CommandV2,
3+
CommandV3,
4+
LineNumberMarkV2,
55
LineNumberMarkV3,
6+
LineNumberPositionV2,
7+
MarkV2,
68
MarkV3,
9+
ModifierV2,
710
ModifierV3,
11+
OrdinalRangeModifierV2,
812
OrdinalScopeModifierV3,
13+
PartialPrimitiveTargetDescriptorV2,
914
PartialPrimitiveTargetDescriptorV3,
1015
PartialRangeTargetDescriptorV3,
16+
PartialTargetDescriptorV2,
1117
PartialTargetDescriptorV3,
1218
RangeMarkV3,
1319
RangeModifierV3,
14-
} from "@cursorless/common";
15-
import {
16-
LineNumberMarkV2,
17-
LineNumberPositionV2,
18-
MarkV2,
19-
ModifierV2,
20-
OrdinalRangeModifierV2,
21-
PartialPrimitiveTargetDescriptorV2,
22-
PartialTargetDescriptorV2,
2320
ScopeTypeV2,
2421
} from "@cursorless/common";
22+
import { isEqual } from "lodash";
2523

2624
export function upgradeV2ToV3(command: CommandV2): CommandV3 {
2725
return {
@@ -48,8 +46,12 @@ function upgradeTarget(
4846
case "range": {
4947
const { anchor, active, ...rest } = target;
5048
return {
51-
anchor: upgradePrimitiveTarget(anchor),
52-
active: upgradePrimitiveTarget(active),
49+
anchor: upgradePrimitiveTarget(
50+
anchor,
51+
) as PartialPrimitiveTargetDescriptorV3,
52+
active: upgradePrimitiveTarget(
53+
active,
54+
) as PartialPrimitiveTargetDescriptorV3,
5355
...rest,
5456
};
5557
}
@@ -60,14 +62,37 @@ function upgradeTarget(
6062

6163
function upgradePrimitiveTarget(
6264
target: PartialPrimitiveTargetDescriptorV2,
63-
): PartialPrimitiveTargetDescriptorV3 {
65+
): PartialPrimitiveTargetDescriptorV3 | PartialRangeTargetDescriptorV3 {
66+
const modifiers =
67+
target.modifiers != null ? target.modifiers.map(updateModifier) : undefined;
68+
69+
if (target.mark?.type === "lineNumber") {
70+
const { anchor, active } = target.mark!;
71+
if (
72+
anchor.type !== active.type ||
73+
anchor.lineNumber < 0 !== active.lineNumber < 0
74+
) {
75+
return {
76+
type: "range",
77+
anchor: {
78+
type: "primitive",
79+
mark: createLineNumberMarkFromPos(anchor),
80+
modifiers,
81+
},
82+
active: {
83+
type: "primitive",
84+
mark: createLineNumberMarkFromPos(active),
85+
},
86+
excludeAnchor: false,
87+
excludeActive: false,
88+
};
89+
}
90+
}
91+
6492
return {
6593
...target,
6694
mark: target.mark != null ? updateMark(target.mark) : undefined,
67-
modifiers:
68-
target.modifiers != null
69-
? target.modifiers.map(updateModifier)
70-
: undefined,
95+
modifiers,
7196
};
7297
}
7398

@@ -110,6 +135,22 @@ function createOrdinalModifier(
110135
return createAbsoluteOrdinalModifier(modifier.scopeType, modifier.anchor);
111136
}
112137

138+
if (modifier.anchor === 0 && modifier.active > modifier.anchor) {
139+
return createAbsoluteOrdinalModifier(
140+
modifier.scopeType,
141+
modifier.anchor,
142+
modifier.active - modifier.anchor + 1,
143+
);
144+
}
145+
146+
if (modifier.anchor < 0 && modifier.active === -1) {
147+
return createAbsoluteOrdinalModifier(
148+
modifier.scopeType,
149+
modifier.anchor,
150+
-modifier.anchor,
151+
);
152+
}
153+
113154
return {
114155
type: "range",
115156
anchor: createAbsoluteOrdinalModifier(modifier.scopeType, modifier.anchor),
@@ -132,11 +173,12 @@ function createLineNumberMarkFromPos(
132173
function createAbsoluteOrdinalModifier(
133174
scopeType: ScopeTypeV2,
134175
start: number,
176+
length = 1,
135177
): OrdinalScopeModifierV3 {
136178
return {
137179
type: "ordinalScope",
138180
scopeType,
139181
start,
140-
length: 1,
182+
length,
141183
};
142184
}

0 commit comments

Comments
 (0)