Skip to content

Commit bce929c

Browse files
Added visible modifier (#2094)
Fixes #1607 Tested with `"from visible chuck every instance air"` and folded regions will be untouched. ## Checklist - [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
1 parent 7a51850 commit bce929c

File tree

7 files changed

+125
-1
lines changed

7 files changed

+125
-1
lines changed

cursorless-talon/src/spoken_forms.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
"trailing": "trailing",
7777
"content": "keepContentFilter",
7878
"empty": "keepEmptyFilter",
79-
"its": "inferPreviousMark"
79+
"its": "inferPreviousMark",
80+
"visible": "visible"
8081
},
8182
"simple_scope_modifier": { "every": "every" },
8283
"interior_modifier": {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ export interface ExcludeInteriorModifier {
232232
type: "excludeInterior";
233233
}
234234

235+
export interface VisibleModifier {
236+
type: "visible";
237+
}
238+
235239
export interface ContainingScopeModifier {
236240
type: "containingScope";
237241
scopeType: ScopeType;
@@ -375,6 +379,7 @@ export type Modifier =
375379
| EndOfModifier
376380
| InteriorOnlyModifier
377381
| ExcludeInteriorModifier
382+
| VisibleModifier
378383
| ContainingScopeModifier
379384
| EveryScopeModifier
380385
| OrdinalScopeModifier

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { RangeModifierStage } from "./modifiers/RangeModifierStage";
3030
import { RawSelectionStage } from "./modifiers/RawSelectionStage";
3131
import { RelativeScopeStage } from "./modifiers/RelativeScopeStage";
3232
import { SurroundingPairStage } from "./modifiers/SurroundingPairStage";
33+
import { VisibleStage } from "./modifiers/VisibleStage";
3334
import { ScopeHandlerFactory } from "./modifiers/scopeHandlers/ScopeHandlerFactory";
3435
import { BoundedNonWhitespaceSequenceStage } from "./modifiers/scopeTypeStages/BoundedNonWhitespaceStage";
3536
import {
@@ -68,6 +69,8 @@ export class ModifierStageFactoryImpl implements ModifierStageFactory {
6869
return new LeadingStage(this, modifier);
6970
case "trailing":
7071
return new TrailingStage(this, modifier);
72+
case "visible":
73+
return new VisibleStage(modifier);
7174
case "containingScope":
7275
return new ContainingScopeStage(
7376
this,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { VisibleModifier } from "@cursorless/common";
2+
import { Target } from "../../typings/target.types";
3+
import { ModifierStage } from "../PipelineStages.types";
4+
import { PlainTarget } from "../targets";
5+
6+
export class VisibleStage implements ModifierStage {
7+
constructor(private modifier: VisibleModifier) {}
8+
9+
run(target: Target): Target[] {
10+
return target.editor.visibleRanges.map(
11+
(range) =>
12+
new PlainTarget({
13+
editor: target.editor,
14+
isReversed: target.isReversed,
15+
contentRange: range,
16+
}),
17+
);
18+
}
19+
}

packages/cursorless-engine/src/spokenForms/defaultSpokenFormMapCore.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export const defaultSpokenFormMapCore: DefaultSpokenFormMapDefinition = {
117117
startOf: "start of",
118118
endOf: "end of",
119119
interiorOnly: "inside",
120+
visible: "visible",
120121
extendThroughStartOf: "head",
121122
extendThroughEndOf: "tail",
122123
everyScope: "every",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: typescript
2+
command:
3+
version: 6
4+
spokenForm: change visible
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- {type: visible}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: |-
14+
// Hello
15+
16+
function helloWorld() {
17+
// Hello
18+
}
19+
20+
// Hello
21+
selections:
22+
- anchor: {line: 0, character: 0}
23+
active: {line: 0, character: 0}
24+
marks: {}
25+
finalState:
26+
documentContents: ""
27+
selections:
28+
- anchor: {line: 0, character: 0}
29+
active: {line: 0, character: 0}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import * as assert from "assert";
2+
import * as vscode from "vscode";
3+
import { openNewEditor } from "@cursorless/vscode-common";
4+
import { endToEndTestSetup } from "../endToEndTestSetup";
5+
import { runCursorlessCommand } from "@cursorless/vscode-common";
6+
7+
suite("visible", async function () {
8+
endToEndTestSetup(this);
9+
10+
test("visible multiple regions", testMultipleRegions);
11+
});
12+
13+
async function testMultipleRegions() {
14+
const editor = await openEditor();
15+
16+
await foldRegion();
17+
18+
assert.equal(editor.visibleRanges.length, 2);
19+
20+
await clearVisible();
21+
22+
assert.equal(editor.selections.length, 2);
23+
24+
assert.equal(editor.document.getText(), "\n // 2\n");
25+
}
26+
27+
const content = `
28+
// 1
29+
30+
function myFunk() {
31+
// 2
32+
}
33+
34+
// 3
35+
`;
36+
37+
function openEditor() {
38+
return openNewEditor(content, {
39+
languageId: "typescript",
40+
});
41+
}
42+
43+
function foldRegion() {
44+
return vscode.commands.executeCommand("editor.fold", {
45+
levels: 1,
46+
direction: "down",
47+
selectionLines: [3],
48+
});
49+
}
50+
51+
function clearVisible() {
52+
return runCursorlessCommand({
53+
version: 6,
54+
usePrePhraseSnapshot: false,
55+
action: {
56+
name: "clearAndSetSelection",
57+
target: {
58+
type: "primitive",
59+
mark: {
60+
type: "cursor",
61+
},
62+
modifiers: [{ type: "visible" }],
63+
},
64+
},
65+
});
66+
}

0 commit comments

Comments
 (0)