Skip to content

Commit 5c56ccb

Browse files
Added append action
1 parent 25a838f commit 5c56ccb

File tree

7 files changed

+54
-4
lines changed

7 files changed

+54
-4
lines changed

cursorless-talon/src/spoken_forms.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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",
56
"bottom": "scrollToBottom",
67
"break": "breakLine",
78
"break point": "toggleLineBreakpoint",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
languageId: plaintext
2+
command:
3+
version: 7
4+
spokenForm: append whale
5+
action:
6+
name: appendSelection
7+
target:
8+
type: primitive
9+
mark: {type: decoratedSymbol, symbolColor: default, character: w}
10+
usePrePhraseSnapshot: true
11+
initialState:
12+
documentContents: hello world
13+
selections:
14+
- anchor: {line: 0, character: 0}
15+
active: {line: 0, character: 0}
16+
marks:
17+
default.w:
18+
start: {line: 0, character: 6}
19+
end: {line: 0, character: 11}
20+
finalState:
21+
documentContents: hello world
22+
selections:
23+
- anchor: {line: 0, character: 0}
24+
active: {line: 0, character: 0}
25+
- anchor: {line: 0, character: 6}
26+
active: {line: 0, character: 11}
27+
thatMark:
28+
- type: UntypedTarget
29+
contentRange:
30+
start: {line: 0, character: 6}
31+
end: {line: 0, character: 11}
32+
isReversed: false
33+
hasExplicitRange: false

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ 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",
1112
"breakLine",
1213
"clearAndSetSelection",
1314
"copyToClipboard",

packages/cursorless-engine/src/CommandHistory.ts

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

133+
case "appendSelection":
133134
case "breakLine":
134135
case "clearAndSetSelection":
135136
case "copyToClipboard":

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import GenerateSnippet from "./GenerateSnippet";
1818
import GetTargets from "./GetTargets";
1919
import GetText from "./GetText";
2020
import Highlight from "./Highlight";
21+
import { IndentLine, OutdentLine } from "./IndentLine";
2122
import {
2223
CopyContentAfter as InsertCopyAfter,
2324
CopyContentBefore as InsertCopyBefore,
@@ -35,13 +36,13 @@ import Replace from "./Replace";
3536
import Rewrap from "./Rewrap";
3637
import { ScrollToBottom, ScrollToCenter, ScrollToTop } from "./Scroll";
3738
import {
39+
AppendSelection,
3840
SetSelection,
3941
SetSelectionAfter,
4042
SetSelectionBefore,
4143
} from "./SetSelection";
4244
import { SetSpecialTarget } from "./SetSpecialTarget";
4345
import ShowParseTree from "./ShowParseTree";
44-
import { IndentLine, OutdentLine } from "./IndentLine";
4546
import {
4647
ExtractVariable,
4748
Fold,
@@ -73,6 +74,7 @@ export class Actions implements ActionRecord {
7374
private modifierStageFactory: ModifierStageFactory,
7475
) {}
7576

77+
appendSelection = new AppendSelection();
7678
callAsFunction = new Call(this);
7779
clearAndSetSelection = new Clear(this);
7880
copyToClipboard = new CopyToClipboard(this, this.rangeUpdater);

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@ import { ensureSingleEditor } from "../util/targetUtils";
55
import type { SimpleAction, ActionReturnValue } from "./actions.types";
66

77
export class SetSelection implements SimpleAction {
8-
constructor() {
8+
constructor(private append: boolean = false) {
99
this.run = this.run.bind(this);
1010
}
1111

12-
protected getSelection(target: Target) {
12+
protected getSelection(target: Target): Selection {
1313
return target.contentSelection;
1414
}
1515

1616
async run(targets: Target[]): Promise<ActionReturnValue> {
1717
const editor = ensureSingleEditor(targets);
1818

19-
const selections = targets.map(this.getSelection);
19+
const targetSelections = targets.map(this.getSelection);
20+
21+
const selections = this.append
22+
? editor.selections.concat(targetSelections)
23+
: targetSelections;
24+
2025
await ide()
2126
.getEditableTextEditor(editor)
2227
.setSelections(selections, { focusEditor: true });
@@ -38,3 +43,9 @@ export class SetSelectionAfter extends SetSelection {
3843
return new Selection(target.contentRange.end, target.contentRange.end);
3944
}
4045
}
46+
47+
export class AppendSelection extends SetSelection {
48+
constructor() {
49+
super(true);
50+
}
51+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export const defaultSpokenFormMapCore: DefaultSpokenFormMapDefinition = {
144144

145145
customRegex: {},
146146
action: {
147+
appendSelection: "append",
147148
breakLine: "break",
148149
scrollToBottom: "bottom",
149150
toggleLineBreakpoint: "break point",

0 commit comments

Comments
 (0)