Skip to content

Commit 9a34030

Browse files
Added add pre and post
1 parent 6551bdc commit 9a34030

File tree

7 files changed

+77
-31
lines changed

7 files changed

+77
-31
lines changed

cursorless-talon/src/spoken_forms.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
"NOTE FOR USERS": "Please don't edit this json file; see https://www.cursorless.org/docs/user/customization",
33
"actions.csv": {
44
"simple_action": {
5-
"append": "appendSelection",
5+
"add post": "addSelectionAfter",
6+
"add pre": "addSelectionBefore",
7+
"add": "addSelection",
68
"bottom": "scrollToBottom",
7-
"break": "breakLine",
89
"break point": "toggleLineBreakpoint",
10+
"break": "breakLine",
911
"carve": "cutToClipboard",
1012
"center": "scrollToCenter",
1113
"change": "clearAndSetSelection",
@@ -23,8 +25,8 @@
2325
"extract": "extractVariable",
2426
"float": "insertEmptyLineAfter",
2527
"fold": "foldRegion",
26-
"follow": "followLink",
2728
"follow split": "followLinkAside",
29+
"follow": "followLink",
2830
"give": "deselect",
2931
"highlight": "highlight",
3032
"hover": "showHover",
@@ -40,8 +42,8 @@
4042
"reference": "showReferences",
4143
"rename": "rename",
4244
"reverse": "reverseTargets",
43-
"scout": "findInDocument",
4445
"scout all": "findInWorkspace",
46+
"scout": "findInDocument",
4547
"shuffle": "randomizeTargets",
4648
"snippet make": "generateSnippet",
4749
"sort": "sortTargets",

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import type { DestinationDescriptor } from "./DestinationDescriptor.types";
88
* A simple action takes only a single target and no other arguments.
99
*/
1010
export const simpleActionNames = [
11-
"appendSelection",
11+
"addSelection",
12+
"addSelectionAfter",
13+
"addSelectionBefore",
1214
"breakLine",
1315
"clearAndSetSelection",
1416
"copyToClipboard",
@@ -33,6 +35,9 @@ export const simpleActionNames = [
3335
"insertEmptyLinesAround",
3436
"joinLines",
3537
"outdentLine",
38+
"private.getTargets",
39+
"private.setKeyboardTarget",
40+
"private.showParseTree",
3641
"randomizeTargets",
3742
"remove",
3843
"rename",
@@ -53,9 +58,6 @@ export const simpleActionNames = [
5358
"toggleLineBreakpoint",
5459
"toggleLineComment",
5560
"unfoldRegion",
56-
"private.setKeyboardTarget",
57-
"private.showParseTree",
58-
"private.getTargets",
5961
] as const;
6062

6163
const complexActionNames = [

packages/cursorless-engine/src/CommandHistory.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ function sanitizeActionInPlace(action: ActionDescriptor): void {
130130
delete action.options?.commandArgs;
131131
break;
132132

133-
case "appendSelection":
133+
case "addSelection":
134+
case "addSelectionAfter":
135+
case "addSelectionBefore":
134136
case "breakLine":
135137
case "clearAndSetSelection":
136138
case "copyToClipboard":

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ import Replace from "./Replace";
3636
import Rewrap from "./Rewrap";
3737
import { ScrollToBottom, ScrollToCenter, ScrollToTop } from "./Scroll";
3838
import {
39-
AppendSelection,
39+
AddSelection,
40+
AddSelectionAfter,
41+
AddSelectionBefore,
4042
SetSelection,
4143
SetSelectionAfter,
4244
SetSelectionBefore,
@@ -74,7 +76,9 @@ export class Actions implements ActionRecord {
7476
private modifierStageFactory: ModifierStageFactory,
7577
) {}
7678

77-
appendSelection = new AppendSelection();
79+
addSelection = new AddSelection();
80+
addSelectionBefore = new AddSelectionBefore();
81+
addSelectionAfter = new AddSelectionAfter();
7882
callAsFunction = new Call(this);
7983
clearAndSetSelection = new Clear(this);
8084
copyToClipboard = new CopyToClipboard(this, this.rangeUpdater);

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

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ import type { Target } from "../typings/target.types";
44
import { ensureSingleEditor } from "../util/targetUtils";
55
import type { SimpleAction, ActionReturnValue } from "./actions.types";
66

7-
export class SetSelection implements SimpleAction {
8-
constructor(private append: boolean = false) {
7+
abstract class SetSelectionBase implements SimpleAction {
8+
constructor(
9+
private selectionMode: "set" | "add",
10+
private rangeMode: "content" | "before" | "after",
11+
) {
912
this.run = this.run.bind(this);
1013
}
1114

12-
protected getSelection(target: Target): Selection {
13-
return target.contentSelection;
14-
}
15-
1615
async run(targets: Target[]): Promise<ActionReturnValue> {
1716
const editor = ensureSingleEditor(targets);
1817

1918
const targetSelections = targets.map(this.getSelection);
2019

21-
const selections = this.append
22-
? editor.selections.concat(targetSelections)
23-
: targetSelections;
20+
const selections =
21+
this.selectionMode === "add"
22+
? editor.selections.concat(targetSelections)
23+
: targetSelections;
2424

2525
await ide()
2626
.getEditableTextEditor(editor)
@@ -30,22 +30,54 @@ export class SetSelection implements SimpleAction {
3030
thatTargets: targets,
3131
};
3232
}
33+
34+
private getSelection(target: Target): Selection {
35+
switch (this.rangeMode) {
36+
case "content":
37+
return target.contentSelection;
38+
case "before":
39+
return new Selection(
40+
target.contentRange.start,
41+
target.contentRange.start,
42+
);
43+
case "after":
44+
return new Selection(target.contentRange.end, target.contentRange.end);
45+
}
46+
}
47+
}
48+
49+
export class SetSelection extends SetSelectionBase {
50+
constructor() {
51+
super("set", "content");
52+
}
53+
}
54+
55+
export class SetSelectionBefore extends SetSelectionBase {
56+
constructor() {
57+
super("set", "before");
58+
}
3359
}
3460

35-
export class SetSelectionBefore extends SetSelection {
36-
protected getSelection(target: Target) {
37-
return new Selection(target.contentRange.start, target.contentRange.start);
61+
export class SetSelectionAfter extends SetSelectionBase {
62+
constructor() {
63+
super("set", "after");
3864
}
3965
}
4066

41-
export class SetSelectionAfter extends SetSelection {
42-
protected getSelection(target: Target) {
43-
return new Selection(target.contentRange.end, target.contentRange.end);
67+
export class AddSelection extends SetSelectionBase {
68+
constructor() {
69+
super("add", "content");
70+
}
71+
}
72+
73+
export class AddSelectionBefore extends SetSelectionBase {
74+
constructor() {
75+
super("add", "before");
4476
}
4577
}
4678

47-
export class AppendSelection extends SetSelection {
79+
export class AddSelectionAfter extends SetSelectionBase {
4880
constructor() {
49-
super(true);
81+
super("add", "after");
5082
}
5183
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ export const defaultSpokenFormMapCore: DefaultSpokenFormMapDefinition = {
144144

145145
customRegex: {},
146146
action: {
147-
appendSelection: "append",
147+
addSelection: "add",
148+
addSelectionAfter: "add post",
149+
addSelectionBefore: "add pre",
148150
breakLine: "break",
149151
scrollToBottom: "bottom",
150152
toggleLineBreakpoint: "break point",

packages/cursorless-org-docs/src/docs/user/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,12 @@ Despite the name cursorless, some of the most basic commands in cursorless are f
531531
532532
Note that when combined with list targets, `take`/`pre`/`post` commands will result in multiple cursors.
533533
534+
- `"take <TARGET>"`: Selects the given target.
534535
- `"pre <TARGET>"`: Places the cursor before the given target.
535536
- `"post <TARGET>"`: Places the cursor after the given target.
536-
- `"take <TARGET>"`: Selects the given target.
537-
- `"append <TARGET>"`: Selects the given target without removing existing selections.
537+
- `"add <TARGET>"`: Selects the given target while preserving removing existing selections.
538+
- `"add pre <TARGET>"`: Places the cursor before the given target while preserving removing existing selections.
539+
- `"add post <TARGET>"`: Places the cursor after the given target while preserving removing existing selections.
538540
- `"give <TARGET>"`: Deselects the given target.
539541
540542
eg:

0 commit comments

Comments
 (0)