From 5c56ccb362e12c7b8e5ee9de229362066c80f0eb Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 4 Jan 2025 04:46:38 +0100 Subject: [PATCH 01/11] Added append action --- cursorless-talon/src/spoken_forms.json | 1 + .../fixtures/recorded/actions/appendWhale.yml | 33 +++++++++++++++++++ .../src/types/command/ActionDescriptor.ts | 1 + .../cursorless-engine/src/CommandHistory.ts | 1 + .../cursorless-engine/src/actions/Actions.ts | 4 ++- .../src/actions/SetSelection.ts | 17 ++++++++-- .../spokenForms/defaultSpokenFormMapCore.ts | 1 + 7 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 data/fixtures/recorded/actions/appendWhale.yml diff --git a/cursorless-talon/src/spoken_forms.json b/cursorless-talon/src/spoken_forms.json index 8f1034afe3..eef3925666 100644 --- a/cursorless-talon/src/spoken_forms.json +++ b/cursorless-talon/src/spoken_forms.json @@ -2,6 +2,7 @@ "NOTE FOR USERS": "Please don't edit this json file; see https://www.cursorless.org/docs/user/customization", "actions.csv": { "simple_action": { + "append": "appendSelection", "bottom": "scrollToBottom", "break": "breakLine", "break point": "toggleLineBreakpoint", diff --git a/data/fixtures/recorded/actions/appendWhale.yml b/data/fixtures/recorded/actions/appendWhale.yml new file mode 100644 index 0000000000..7370616eca --- /dev/null +++ b/data/fixtures/recorded/actions/appendWhale.yml @@ -0,0 +1,33 @@ +languageId: plaintext +command: + version: 7 + spokenForm: append whale + action: + name: appendSelection + target: + type: primitive + mark: {type: decoratedSymbol, symbolColor: default, character: w} + usePrePhraseSnapshot: true +initialState: + documentContents: hello world + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: + default.w: + start: {line: 0, character: 6} + end: {line: 0, character: 11} +finalState: + documentContents: hello world + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + - anchor: {line: 0, character: 6} + active: {line: 0, character: 11} + thatMark: + - type: UntypedTarget + contentRange: + start: {line: 0, character: 6} + end: {line: 0, character: 11} + isReversed: false + hasExplicitRange: false diff --git a/packages/common/src/types/command/ActionDescriptor.ts b/packages/common/src/types/command/ActionDescriptor.ts index 200918604d..04f871d44d 100644 --- a/packages/common/src/types/command/ActionDescriptor.ts +++ b/packages/common/src/types/command/ActionDescriptor.ts @@ -8,6 +8,7 @@ import type { DestinationDescriptor } from "./DestinationDescriptor.types"; * A simple action takes only a single target and no other arguments. */ export const simpleActionNames = [ + "appendSelection", "breakLine", "clearAndSetSelection", "copyToClipboard", diff --git a/packages/cursorless-engine/src/CommandHistory.ts b/packages/cursorless-engine/src/CommandHistory.ts index b68f256b38..8e2c0bade2 100644 --- a/packages/cursorless-engine/src/CommandHistory.ts +++ b/packages/cursorless-engine/src/CommandHistory.ts @@ -130,6 +130,7 @@ function sanitizeActionInPlace(action: ActionDescriptor): void { delete action.options?.commandArgs; break; + case "appendSelection": case "breakLine": case "clearAndSetSelection": case "copyToClipboard": diff --git a/packages/cursorless-engine/src/actions/Actions.ts b/packages/cursorless-engine/src/actions/Actions.ts index 18258bf4bb..3fa34fdbcb 100644 --- a/packages/cursorless-engine/src/actions/Actions.ts +++ b/packages/cursorless-engine/src/actions/Actions.ts @@ -18,6 +18,7 @@ import GenerateSnippet from "./GenerateSnippet"; import GetTargets from "./GetTargets"; import GetText from "./GetText"; import Highlight from "./Highlight"; +import { IndentLine, OutdentLine } from "./IndentLine"; import { CopyContentAfter as InsertCopyAfter, CopyContentBefore as InsertCopyBefore, @@ -35,13 +36,13 @@ import Replace from "./Replace"; import Rewrap from "./Rewrap"; import { ScrollToBottom, ScrollToCenter, ScrollToTop } from "./Scroll"; import { + AppendSelection, SetSelection, SetSelectionAfter, SetSelectionBefore, } from "./SetSelection"; import { SetSpecialTarget } from "./SetSpecialTarget"; import ShowParseTree from "./ShowParseTree"; -import { IndentLine, OutdentLine } from "./IndentLine"; import { ExtractVariable, Fold, @@ -73,6 +74,7 @@ export class Actions implements ActionRecord { private modifierStageFactory: ModifierStageFactory, ) {} + appendSelection = new AppendSelection(); callAsFunction = new Call(this); clearAndSetSelection = new Clear(this); copyToClipboard = new CopyToClipboard(this, this.rangeUpdater); diff --git a/packages/cursorless-engine/src/actions/SetSelection.ts b/packages/cursorless-engine/src/actions/SetSelection.ts index 2bab32a858..d7e2683e90 100644 --- a/packages/cursorless-engine/src/actions/SetSelection.ts +++ b/packages/cursorless-engine/src/actions/SetSelection.ts @@ -5,18 +5,23 @@ import { ensureSingleEditor } from "../util/targetUtils"; import type { SimpleAction, ActionReturnValue } from "./actions.types"; export class SetSelection implements SimpleAction { - constructor() { + constructor(private append: boolean = false) { this.run = this.run.bind(this); } - protected getSelection(target: Target) { + protected getSelection(target: Target): Selection { return target.contentSelection; } async run(targets: Target[]): Promise { const editor = ensureSingleEditor(targets); - const selections = targets.map(this.getSelection); + const targetSelections = targets.map(this.getSelection); + + const selections = this.append + ? editor.selections.concat(targetSelections) + : targetSelections; + await ide() .getEditableTextEditor(editor) .setSelections(selections, { focusEditor: true }); @@ -38,3 +43,9 @@ export class SetSelectionAfter extends SetSelection { return new Selection(target.contentRange.end, target.contentRange.end); } } + +export class AppendSelection extends SetSelection { + constructor() { + super(true); + } +} diff --git a/packages/cursorless-engine/src/spokenForms/defaultSpokenFormMapCore.ts b/packages/cursorless-engine/src/spokenForms/defaultSpokenFormMapCore.ts index 7717823ec9..7288d4d2e1 100644 --- a/packages/cursorless-engine/src/spokenForms/defaultSpokenFormMapCore.ts +++ b/packages/cursorless-engine/src/spokenForms/defaultSpokenFormMapCore.ts @@ -144,6 +144,7 @@ export const defaultSpokenFormMapCore: DefaultSpokenFormMapDefinition = { customRegex: {}, action: { + appendSelection: "append", breakLine: "break", scrollToBottom: "bottom", toggleLineBreakpoint: "break point", From 6551bdcc4a2e35dd216cc8b3edb88a70da9b211c Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 4 Jan 2025 04:51:30 +0100 Subject: [PATCH 02/11] Update docks --- packages/cursorless-org-docs/src/docs/user/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cursorless-org-docs/src/docs/user/README.md b/packages/cursorless-org-docs/src/docs/user/README.md index fbf667ee25..06abf36b11 100644 --- a/packages/cursorless-org-docs/src/docs/user/README.md +++ b/packages/cursorless-org-docs/src/docs/user/README.md @@ -534,6 +534,7 @@ Note that when combined with list targets, `take`/`pre`/`post` commands will res - `"pre "`: Places the cursor before the given target. - `"post "`: Places the cursor after the given target. - `"take "`: Selects the given target. +- `"append "`: Selects the given target without removing existing selections. - `"give "`: Deselects the given target. eg: From 9a340305afe5614e412eff16795f37bedbe983b9 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 4 Jan 2025 09:26:53 +0100 Subject: [PATCH 03/11] Added add pre and post --- cursorless-talon/src/spoken_forms.json | 10 +-- .../src/types/command/ActionDescriptor.ts | 10 +-- .../cursorless-engine/src/CommandHistory.ts | 4 +- .../cursorless-engine/src/actions/Actions.ts | 8 ++- .../src/actions/SetSelection.ts | 66 ++++++++++++++----- .../spokenForms/defaultSpokenFormMapCore.ts | 4 +- .../src/docs/user/README.md | 6 +- 7 files changed, 77 insertions(+), 31 deletions(-) diff --git a/cursorless-talon/src/spoken_forms.json b/cursorless-talon/src/spoken_forms.json index eef3925666..c71891d0f1 100644 --- a/cursorless-talon/src/spoken_forms.json +++ b/cursorless-talon/src/spoken_forms.json @@ -2,10 +2,12 @@ "NOTE FOR USERS": "Please don't edit this json file; see https://www.cursorless.org/docs/user/customization", "actions.csv": { "simple_action": { - "append": "appendSelection", + "add post": "addSelectionAfter", + "add pre": "addSelectionBefore", + "add": "addSelection", "bottom": "scrollToBottom", - "break": "breakLine", "break point": "toggleLineBreakpoint", + "break": "breakLine", "carve": "cutToClipboard", "center": "scrollToCenter", "change": "clearAndSetSelection", @@ -23,8 +25,8 @@ "extract": "extractVariable", "float": "insertEmptyLineAfter", "fold": "foldRegion", - "follow": "followLink", "follow split": "followLinkAside", + "follow": "followLink", "give": "deselect", "highlight": "highlight", "hover": "showHover", @@ -40,8 +42,8 @@ "reference": "showReferences", "rename": "rename", "reverse": "reverseTargets", - "scout": "findInDocument", "scout all": "findInWorkspace", + "scout": "findInDocument", "shuffle": "randomizeTargets", "snippet make": "generateSnippet", "sort": "sortTargets", diff --git a/packages/common/src/types/command/ActionDescriptor.ts b/packages/common/src/types/command/ActionDescriptor.ts index 04f871d44d..4719c16757 100644 --- a/packages/common/src/types/command/ActionDescriptor.ts +++ b/packages/common/src/types/command/ActionDescriptor.ts @@ -8,7 +8,9 @@ import type { DestinationDescriptor } from "./DestinationDescriptor.types"; * A simple action takes only a single target and no other arguments. */ export const simpleActionNames = [ - "appendSelection", + "addSelection", + "addSelectionAfter", + "addSelectionBefore", "breakLine", "clearAndSetSelection", "copyToClipboard", @@ -33,6 +35,9 @@ export const simpleActionNames = [ "insertEmptyLinesAround", "joinLines", "outdentLine", + "private.getTargets", + "private.setKeyboardTarget", + "private.showParseTree", "randomizeTargets", "remove", "rename", @@ -53,9 +58,6 @@ export const simpleActionNames = [ "toggleLineBreakpoint", "toggleLineComment", "unfoldRegion", - "private.setKeyboardTarget", - "private.showParseTree", - "private.getTargets", ] as const; const complexActionNames = [ diff --git a/packages/cursorless-engine/src/CommandHistory.ts b/packages/cursorless-engine/src/CommandHistory.ts index 8e2c0bade2..65a148539c 100644 --- a/packages/cursorless-engine/src/CommandHistory.ts +++ b/packages/cursorless-engine/src/CommandHistory.ts @@ -130,7 +130,9 @@ function sanitizeActionInPlace(action: ActionDescriptor): void { delete action.options?.commandArgs; break; - case "appendSelection": + case "addSelection": + case "addSelectionAfter": + case "addSelectionBefore": case "breakLine": case "clearAndSetSelection": case "copyToClipboard": diff --git a/packages/cursorless-engine/src/actions/Actions.ts b/packages/cursorless-engine/src/actions/Actions.ts index 3fa34fdbcb..3bdd24e28c 100644 --- a/packages/cursorless-engine/src/actions/Actions.ts +++ b/packages/cursorless-engine/src/actions/Actions.ts @@ -36,7 +36,9 @@ import Replace from "./Replace"; import Rewrap from "./Rewrap"; import { ScrollToBottom, ScrollToCenter, ScrollToTop } from "./Scroll"; import { - AppendSelection, + AddSelection, + AddSelectionAfter, + AddSelectionBefore, SetSelection, SetSelectionAfter, SetSelectionBefore, @@ -74,7 +76,9 @@ export class Actions implements ActionRecord { private modifierStageFactory: ModifierStageFactory, ) {} - appendSelection = new AppendSelection(); + addSelection = new AddSelection(); + addSelectionBefore = new AddSelectionBefore(); + addSelectionAfter = new AddSelectionAfter(); callAsFunction = new Call(this); clearAndSetSelection = new Clear(this); copyToClipboard = new CopyToClipboard(this, this.rangeUpdater); diff --git a/packages/cursorless-engine/src/actions/SetSelection.ts b/packages/cursorless-engine/src/actions/SetSelection.ts index d7e2683e90..d591001b77 100644 --- a/packages/cursorless-engine/src/actions/SetSelection.ts +++ b/packages/cursorless-engine/src/actions/SetSelection.ts @@ -4,23 +4,23 @@ import type { Target } from "../typings/target.types"; import { ensureSingleEditor } from "../util/targetUtils"; import type { SimpleAction, ActionReturnValue } from "./actions.types"; -export class SetSelection implements SimpleAction { - constructor(private append: boolean = false) { +abstract class SetSelectionBase implements SimpleAction { + constructor( + private selectionMode: "set" | "add", + private rangeMode: "content" | "before" | "after", + ) { this.run = this.run.bind(this); } - protected getSelection(target: Target): Selection { - return target.contentSelection; - } - async run(targets: Target[]): Promise { const editor = ensureSingleEditor(targets); const targetSelections = targets.map(this.getSelection); - const selections = this.append - ? editor.selections.concat(targetSelections) - : targetSelections; + const selections = + this.selectionMode === "add" + ? editor.selections.concat(targetSelections) + : targetSelections; await ide() .getEditableTextEditor(editor) @@ -30,22 +30,54 @@ export class SetSelection implements SimpleAction { thatTargets: targets, }; } + + private getSelection(target: Target): Selection { + switch (this.rangeMode) { + case "content": + return target.contentSelection; + case "before": + return new Selection( + target.contentRange.start, + target.contentRange.start, + ); + case "after": + return new Selection(target.contentRange.end, target.contentRange.end); + } + } +} + +export class SetSelection extends SetSelectionBase { + constructor() { + super("set", "content"); + } +} + +export class SetSelectionBefore extends SetSelectionBase { + constructor() { + super("set", "before"); + } } -export class SetSelectionBefore extends SetSelection { - protected getSelection(target: Target) { - return new Selection(target.contentRange.start, target.contentRange.start); +export class SetSelectionAfter extends SetSelectionBase { + constructor() { + super("set", "after"); } } -export class SetSelectionAfter extends SetSelection { - protected getSelection(target: Target) { - return new Selection(target.contentRange.end, target.contentRange.end); +export class AddSelection extends SetSelectionBase { + constructor() { + super("add", "content"); + } +} + +export class AddSelectionBefore extends SetSelectionBase { + constructor() { + super("add", "before"); } } -export class AppendSelection extends SetSelection { +export class AddSelectionAfter extends SetSelectionBase { constructor() { - super(true); + super("add", "after"); } } diff --git a/packages/cursorless-engine/src/spokenForms/defaultSpokenFormMapCore.ts b/packages/cursorless-engine/src/spokenForms/defaultSpokenFormMapCore.ts index 7288d4d2e1..bacc7cc88b 100644 --- a/packages/cursorless-engine/src/spokenForms/defaultSpokenFormMapCore.ts +++ b/packages/cursorless-engine/src/spokenForms/defaultSpokenFormMapCore.ts @@ -144,7 +144,9 @@ export const defaultSpokenFormMapCore: DefaultSpokenFormMapDefinition = { customRegex: {}, action: { - appendSelection: "append", + addSelection: "add", + addSelectionAfter: "add post", + addSelectionBefore: "add pre", breakLine: "break", scrollToBottom: "bottom", toggleLineBreakpoint: "break point", diff --git a/packages/cursorless-org-docs/src/docs/user/README.md b/packages/cursorless-org-docs/src/docs/user/README.md index 06abf36b11..a15211c30b 100644 --- a/packages/cursorless-org-docs/src/docs/user/README.md +++ b/packages/cursorless-org-docs/src/docs/user/README.md @@ -531,10 +531,12 @@ Despite the name cursorless, some of the most basic commands in cursorless are f Note that when combined with list targets, `take`/`pre`/`post` commands will result in multiple cursors. +- `"take "`: Selects the given target. - `"pre "`: Places the cursor before the given target. - `"post "`: Places the cursor after the given target. -- `"take "`: Selects the given target. -- `"append "`: Selects the given target without removing existing selections. +- `"add "`: Selects the given target while preserving removing existing selections. +- `"add pre "`: Places the cursor before the given target while preserving removing existing selections. +- `"add post "`: Places the cursor after the given target while preserving removing existing selections. - `"give "`: Deselects the given target. eg: From 1e8d19a971de587e1ecf52647d594a279c326a8d Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 4 Jan 2025 09:32:15 +0100 Subject: [PATCH 04/11] Updated tests --- .../recorded/actions/addPostWhale.yml | 33 +++++++++++++++++++ .../fixtures/recorded/actions/addPreWhale.yml | 33 +++++++++++++++++++ .../actions/{appendWhale.yml => addWhale.yml} | 4 +-- .../src/actions/SetSelection.ts | 1 + 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 data/fixtures/recorded/actions/addPostWhale.yml create mode 100644 data/fixtures/recorded/actions/addPreWhale.yml rename data/fixtures/recorded/actions/{appendWhale.yml => addWhale.yml} (93%) diff --git a/data/fixtures/recorded/actions/addPostWhale.yml b/data/fixtures/recorded/actions/addPostWhale.yml new file mode 100644 index 0000000000..c15ae9cb37 --- /dev/null +++ b/data/fixtures/recorded/actions/addPostWhale.yml @@ -0,0 +1,33 @@ +languageId: plaintext +command: + version: 7 + spokenForm: add post whale + action: + name: addSelectionAfter + target: + type: primitive + mark: {type: decoratedSymbol, symbolColor: default, character: w} + usePrePhraseSnapshot: true +initialState: + documentContents: hello world + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: + default.w: + start: {line: 0, character: 6} + end: {line: 0, character: 11} +finalState: + documentContents: hello world + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + - anchor: {line: 0, character: 11} + active: {line: 0, character: 11} + thatMark: + - type: UntypedTarget + contentRange: + start: {line: 0, character: 6} + end: {line: 0, character: 11} + isReversed: false + hasExplicitRange: false diff --git a/data/fixtures/recorded/actions/addPreWhale.yml b/data/fixtures/recorded/actions/addPreWhale.yml new file mode 100644 index 0000000000..f3475e21db --- /dev/null +++ b/data/fixtures/recorded/actions/addPreWhale.yml @@ -0,0 +1,33 @@ +languageId: plaintext +command: + version: 7 + spokenForm: add pre whale + action: + name: addSelectionBefore + target: + type: primitive + mark: {type: decoratedSymbol, symbolColor: default, character: w} + usePrePhraseSnapshot: true +initialState: + documentContents: hello world + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: + default.w: + start: {line: 0, character: 6} + end: {line: 0, character: 11} +finalState: + documentContents: hello world + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + - anchor: {line: 0, character: 6} + active: {line: 0, character: 6} + thatMark: + - type: UntypedTarget + contentRange: + start: {line: 0, character: 6} + end: {line: 0, character: 11} + isReversed: false + hasExplicitRange: false diff --git a/data/fixtures/recorded/actions/appendWhale.yml b/data/fixtures/recorded/actions/addWhale.yml similarity index 93% rename from data/fixtures/recorded/actions/appendWhale.yml rename to data/fixtures/recorded/actions/addWhale.yml index 7370616eca..0c4162e66c 100644 --- a/data/fixtures/recorded/actions/appendWhale.yml +++ b/data/fixtures/recorded/actions/addWhale.yml @@ -1,9 +1,9 @@ languageId: plaintext command: version: 7 - spokenForm: append whale + spokenForm: add whale action: - name: appendSelection + name: addSelection target: type: primitive mark: {type: decoratedSymbol, symbolColor: default, character: w} diff --git a/packages/cursorless-engine/src/actions/SetSelection.ts b/packages/cursorless-engine/src/actions/SetSelection.ts index d591001b77..1dbe724106 100644 --- a/packages/cursorless-engine/src/actions/SetSelection.ts +++ b/packages/cursorless-engine/src/actions/SetSelection.ts @@ -10,6 +10,7 @@ abstract class SetSelectionBase implements SimpleAction { private rangeMode: "content" | "before" | "after", ) { this.run = this.run.bind(this); + this.getSelection = this.getSelection.bind(this); } async run(targets: Target[]): Promise { From 20df6d7c252615ae24cd3d8bb22b33b43e76ad57 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 4 Jan 2025 09:34:26 +0100 Subject: [PATCH 05/11] Reorder --- packages/common/src/types/command/ActionDescriptor.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/common/src/types/command/ActionDescriptor.ts b/packages/common/src/types/command/ActionDescriptor.ts index 4719c16757..c064f28339 100644 --- a/packages/common/src/types/command/ActionDescriptor.ts +++ b/packages/common/src/types/command/ActionDescriptor.ts @@ -35,9 +35,6 @@ export const simpleActionNames = [ "insertEmptyLinesAround", "joinLines", "outdentLine", - "private.getTargets", - "private.setKeyboardTarget", - "private.showParseTree", "randomizeTargets", "remove", "rename", @@ -58,6 +55,9 @@ export const simpleActionNames = [ "toggleLineBreakpoint", "toggleLineComment", "unfoldRegion", + "private.getTargets", + "private.setKeyboardTarget", + "private.showParseTree", ] as const; const complexActionNames = [ From a74b4cfb54c07e3a2794e642a8b04a17a687657f Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 4 Jan 2025 09:38:39 +0100 Subject: [PATCH 06/11] Update readme --- packages/cursorless-org-docs/src/docs/user/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cursorless-org-docs/src/docs/user/README.md b/packages/cursorless-org-docs/src/docs/user/README.md index a15211c30b..4376d39ee1 100644 --- a/packages/cursorless-org-docs/src/docs/user/README.md +++ b/packages/cursorless-org-docs/src/docs/user/README.md @@ -534,9 +534,9 @@ Note that when combined with list targets, `take`/`pre`/`post` commands will res - `"take "`: Selects the given target. - `"pre "`: Places the cursor before the given target. - `"post "`: Places the cursor after the given target. -- `"add "`: Selects the given target while preserving removing existing selections. -- `"add pre "`: Places the cursor before the given target while preserving removing existing selections. -- `"add post "`: Places the cursor after the given target while preserving removing existing selections. +- `"add "`: Selects the given target while preserving existing selections. +- `"add pre "`: Places the cursor before the given target while preserving existing selections. +- `"add post "`: Places the cursor after the given target while preserving existing selections. - `"give "`: Deselects the given target. eg: From 3c61e7bc5347b664234b1c35529e4af00ae83ecf Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 4 Jan 2025 12:02:50 +0100 Subject: [PATCH 07/11] Clean up --- .../src/actions/SetSelection.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/cursorless-engine/src/actions/SetSelection.ts b/packages/cursorless-engine/src/actions/SetSelection.ts index 1dbe724106..d45301f72a 100644 --- a/packages/cursorless-engine/src/actions/SetSelection.ts +++ b/packages/cursorless-engine/src/actions/SetSelection.ts @@ -10,13 +10,12 @@ abstract class SetSelectionBase implements SimpleAction { private rangeMode: "content" | "before" | "after", ) { this.run = this.run.bind(this); - this.getSelection = this.getSelection.bind(this); } async run(targets: Target[]): Promise { const editor = ensureSingleEditor(targets); - const targetSelections = targets.map(this.getSelection); + const targetSelections = this.getSelections(targets); const selections = this.selectionMode === "add" @@ -32,17 +31,20 @@ abstract class SetSelectionBase implements SimpleAction { }; } - private getSelection(target: Target): Selection { + private getSelections(targets: Target[]): Selection[] { switch (this.rangeMode) { case "content": - return target.contentSelection; + return targets.map((target) => target.contentSelection); case "before": - return new Selection( - target.contentRange.start, - target.contentRange.start, + return targets.map( + (target) => + new Selection(target.contentRange.start, target.contentRange.start), ); case "after": - return new Selection(target.contentRange.end, target.contentRange.end); + return targets.map( + (target) => + new Selection(target.contentRange.end, target.contentRange.end), + ); } } } From ccec29181a4ea8e108642c4677acd4c8348e0af1 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 4 Jan 2025 12:03:15 +0100 Subject: [PATCH 08/11] clean up --- packages/cursorless-engine/src/actions/SetSelection.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/cursorless-engine/src/actions/SetSelection.ts b/packages/cursorless-engine/src/actions/SetSelection.ts index d45301f72a..db46311631 100644 --- a/packages/cursorless-engine/src/actions/SetSelection.ts +++ b/packages/cursorless-engine/src/actions/SetSelection.ts @@ -14,7 +14,6 @@ abstract class SetSelectionBase implements SimpleAction { async run(targets: Target[]): Promise { const editor = ensureSingleEditor(targets); - const targetSelections = this.getSelections(targets); const selections = From 1e0cf76dc4a84de77873629642d16c73d9863ada Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Wed, 8 Jan 2025 20:02:50 +0100 Subject: [PATCH 09/11] Change add to append --- cursorless-talon/src/spoken_forms.json | 6 +++--- .../actions/{addPostWhale.yml => appendPostWhale.yml} | 2 +- .../actions/{addPreWhale.yml => appendPreWhale.yml} | 2 +- .../recorded/actions/{addWhale.yml => appendWhale.yml} | 2 +- .../src/spokenForms/defaultSpokenFormMapCore.ts | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) rename data/fixtures/recorded/actions/{addPostWhale.yml => appendPostWhale.yml} (96%) rename data/fixtures/recorded/actions/{addPreWhale.yml => appendPreWhale.yml} (96%) rename data/fixtures/recorded/actions/{addWhale.yml => appendWhale.yml} (96%) diff --git a/cursorless-talon/src/spoken_forms.json b/cursorless-talon/src/spoken_forms.json index c71891d0f1..249b75abcf 100644 --- a/cursorless-talon/src/spoken_forms.json +++ b/cursorless-talon/src/spoken_forms.json @@ -2,9 +2,9 @@ "NOTE FOR USERS": "Please don't edit this json file; see https://www.cursorless.org/docs/user/customization", "actions.csv": { "simple_action": { - "add post": "addSelectionAfter", - "add pre": "addSelectionBefore", - "add": "addSelection", + "append post": "addSelectionAfter", + "append pre": "addSelectionBefore", + "append": "addSelection", "bottom": "scrollToBottom", "break point": "toggleLineBreakpoint", "break": "breakLine", diff --git a/data/fixtures/recorded/actions/addPostWhale.yml b/data/fixtures/recorded/actions/appendPostWhale.yml similarity index 96% rename from data/fixtures/recorded/actions/addPostWhale.yml rename to data/fixtures/recorded/actions/appendPostWhale.yml index c15ae9cb37..dd266c1a93 100644 --- a/data/fixtures/recorded/actions/addPostWhale.yml +++ b/data/fixtures/recorded/actions/appendPostWhale.yml @@ -1,7 +1,7 @@ languageId: plaintext command: version: 7 - spokenForm: add post whale + spokenForm: append post whale action: name: addSelectionAfter target: diff --git a/data/fixtures/recorded/actions/addPreWhale.yml b/data/fixtures/recorded/actions/appendPreWhale.yml similarity index 96% rename from data/fixtures/recorded/actions/addPreWhale.yml rename to data/fixtures/recorded/actions/appendPreWhale.yml index f3475e21db..765c092161 100644 --- a/data/fixtures/recorded/actions/addPreWhale.yml +++ b/data/fixtures/recorded/actions/appendPreWhale.yml @@ -1,7 +1,7 @@ languageId: plaintext command: version: 7 - spokenForm: add pre whale + spokenForm: append pre whale action: name: addSelectionBefore target: diff --git a/data/fixtures/recorded/actions/addWhale.yml b/data/fixtures/recorded/actions/appendWhale.yml similarity index 96% rename from data/fixtures/recorded/actions/addWhale.yml rename to data/fixtures/recorded/actions/appendWhale.yml index 0c4162e66c..9acc5078e4 100644 --- a/data/fixtures/recorded/actions/addWhale.yml +++ b/data/fixtures/recorded/actions/appendWhale.yml @@ -1,7 +1,7 @@ languageId: plaintext command: version: 7 - spokenForm: add whale + spokenForm: append whale action: name: addSelection target: diff --git a/packages/cursorless-engine/src/spokenForms/defaultSpokenFormMapCore.ts b/packages/cursorless-engine/src/spokenForms/defaultSpokenFormMapCore.ts index bacc7cc88b..0aeefabcd8 100644 --- a/packages/cursorless-engine/src/spokenForms/defaultSpokenFormMapCore.ts +++ b/packages/cursorless-engine/src/spokenForms/defaultSpokenFormMapCore.ts @@ -144,9 +144,9 @@ export const defaultSpokenFormMapCore: DefaultSpokenFormMapDefinition = { customRegex: {}, action: { - addSelection: "add", - addSelectionAfter: "add post", - addSelectionBefore: "add pre", + addSelection: "append", + addSelectionAfter: "append post", + addSelectionBefore: "append pre", breakLine: "break", scrollToBottom: "bottom", toggleLineBreakpoint: "break point", From a2d3ca969b32d2c631c560eaeb0ff46623a5383b Mon Sep 17 00:00:00 2001 From: Phil Cohen Date: Thu, 9 Jan 2025 10:03:29 -0800 Subject: [PATCH 10/11] Update packages/cursorless-org-docs/src/docs/user/README.md --- packages/cursorless-org-docs/src/docs/user/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cursorless-org-docs/src/docs/user/README.md b/packages/cursorless-org-docs/src/docs/user/README.md index 4376d39ee1..b0de9819f2 100644 --- a/packages/cursorless-org-docs/src/docs/user/README.md +++ b/packages/cursorless-org-docs/src/docs/user/README.md @@ -534,9 +534,9 @@ Note that when combined with list targets, `take`/`pre`/`post` commands will res - `"take "`: Selects the given target. - `"pre "`: Places the cursor before the given target. - `"post "`: Places the cursor after the given target. -- `"add "`: Selects the given target while preserving existing selections. -- `"add pre "`: Places the cursor before the given target while preserving existing selections. -- `"add post "`: Places the cursor after the given target while preserving existing selections. +- `"append "`: Selects the given target, while preserving your existing selections. +- `"append pre "`: Adds a new cursor before the given target while preserving your existing selections. +- `"append post "`: Adds a new cursor after the given target, while preserving your existing selections. - `"give "`: Deselects the given target. eg: From dff8a4216182de1ecba49fdfc36f4a4acc4636e5 Mon Sep 17 00:00:00 2001 From: Phil Cohen Date: Thu, 9 Jan 2025 10:03:55 -0800 Subject: [PATCH 11/11] Update packages/cursorless-org-docs/src/docs/user/README.md --- packages/cursorless-org-docs/src/docs/user/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cursorless-org-docs/src/docs/user/README.md b/packages/cursorless-org-docs/src/docs/user/README.md index b0de9819f2..a6b43c6a45 100644 --- a/packages/cursorless-org-docs/src/docs/user/README.md +++ b/packages/cursorless-org-docs/src/docs/user/README.md @@ -535,7 +535,7 @@ Note that when combined with list targets, `take`/`pre`/`post` commands will res - `"pre "`: Places the cursor before the given target. - `"post "`: Places the cursor after the given target. - `"append "`: Selects the given target, while preserving your existing selections. -- `"append pre "`: Adds a new cursor before the given target while preserving your existing selections. +- `"append pre "`: Adds a new cursor before the given target, while preserving your existing selections. - `"append post "`: Adds a new cursor after the given target, while preserving your existing selections. - `"give "`: Deselects the given target.