From dc4ec906a0d30fd4d325dd9e90b45320730cd3b7 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Mon, 27 Jan 2025 16:20:23 +0100 Subject: [PATCH 1/3] Properly expand to token when using `"end of this"` --- .../implicitExpansion/bringAirToEndOfThis.yml | 36 ++++++++++++++ .../processTargets/TargetPipelineRunner.ts | 48 ++++++++++++++++--- 2 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 data/fixtures/recorded/implicitExpansion/bringAirToEndOfThis.yml diff --git a/data/fixtures/recorded/implicitExpansion/bringAirToEndOfThis.yml b/data/fixtures/recorded/implicitExpansion/bringAirToEndOfThis.yml new file mode 100644 index 0000000000..ff63e89211 --- /dev/null +++ b/data/fixtures/recorded/implicitExpansion/bringAirToEndOfThis.yml @@ -0,0 +1,36 @@ +languageId: plaintext +command: + version: 7 + spokenForm: bring air to end of this + action: + name: replaceWithTarget + source: + type: primitive + mark: {type: decoratedSymbol, symbolColor: default, character: a} + destination: + type: primitive + insertionMode: to + target: + type: primitive + mark: {type: cursor} + modifiers: + - {type: endOf} + usePrePhraseSnapshot: false +initialState: + documentContents: |- + a + bbb + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.a: + start: {line: 0, character: 0} + end: {line: 0, character: 1} +finalState: + documentContents: |- + a + bbba + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} diff --git a/packages/cursorless-engine/src/processTargets/TargetPipelineRunner.ts b/packages/cursorless-engine/src/processTargets/TargetPipelineRunner.ts index 7491f8cde3..9b141157b0 100644 --- a/packages/cursorless-engine/src/processTargets/TargetPipelineRunner.ts +++ b/packages/cursorless-engine/src/processTargets/TargetPipelineRunner.ts @@ -208,6 +208,7 @@ class TargetPipeline { ): Target[] { let markStage: MarkStage; let targetModifierStages: ModifierStage[]; + let automaticTokenExpansionBefore = false; if (targetDescriptor.type === "implicit") { markStage = new ImplicitStage(); @@ -218,28 +219,63 @@ class TargetPipeline { this.modifierStageFactory, targetDescriptor.modifiers, ); + automaticTokenExpansionBefore = + doAutomaticTokenExpansionBefore(targetDescriptor); } // First, get the targets output by the mark const markOutputTargets = markStage.run(); + const [preStages, postStages] = this.getPreAndPostStages( + automaticTokenExpansionBefore, + ); + /** + * The modifier pipeline that will be applied to construct our final targets */ const modifierStages = [ + ...preStages, ...targetModifierStages, ...this.opts.actionFinalStages, - - // This performs auto-expansion to token when you say eg "take this" with an - // empty selection - ...(this.opts.noAutomaticTokenExpansion - ? [] - : [new ContainingTokenIfUntypedEmptyStage(this.modifierStageFactory)]), + ...postStages, ]; // Run all targets through the modifier stages return processModifierStages(modifierStages, markOutputTargets); } + + private getPreAndPostStages( + automaticTokenExpansionBefore: boolean, + ): [ModifierStage[], ModifierStage[]] { + if (this.opts.noAutomaticTokenExpansion) { + return [[], []]; + } + // This performs auto-expansion to token when you say eg "take this" with an + // empty selection + const stage = new ContainingTokenIfUntypedEmptyStage( + this.modifierStageFactory, + ); + if (automaticTokenExpansionBefore) { + return [[stage], []]; + } + return [[], [stage]]; + } +} + +/** + * Determines whether we should automatically expand the token before the target. + * True if the target has modifiers that are all "startOf" or "endOf". + */ +function doAutomaticTokenExpansionBefore( + targetDescriptor: PrimitiveTargetDescriptor, +): boolean { + return ( + targetDescriptor.modifiers.length > 0 && + targetDescriptor.modifiers.every( + ({ type }) => type === "startOf" || type === "endOf", + ) + ); } /** Convert a list of target modifiers to modifier stages */ From 2212951cd39ceb63b17b6fd527724da7f1a7f752 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 27 Jan 2025 15:23:13 +0000 Subject: [PATCH 2/3] [pre-commit.ci lite] apply automatic fixes --- .../src/processTargets/TargetPipelineRunner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cursorless-engine/src/processTargets/TargetPipelineRunner.ts b/packages/cursorless-engine/src/processTargets/TargetPipelineRunner.ts index 9b141157b0..3773472c65 100644 --- a/packages/cursorless-engine/src/processTargets/TargetPipelineRunner.ts +++ b/packages/cursorless-engine/src/processTargets/TargetPipelineRunner.ts @@ -231,7 +231,7 @@ class TargetPipeline { ); /** - + * The modifier pipeline that will be applied to construct our final targets */ const modifierStages = [ From c289fe1e9b2edc0d44f2e167b47e984a964d06d8 Mon Sep 17 00:00:00 2001 From: Phil Cohen Date: Tue, 28 Jan 2025 11:27:02 -0800 Subject: [PATCH 3/3] Update packages/cursorless-engine/src/processTargets/TargetPipelineRunner.ts --- .../cursorless-engine/src/processTargets/TargetPipelineRunner.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/cursorless-engine/src/processTargets/TargetPipelineRunner.ts b/packages/cursorless-engine/src/processTargets/TargetPipelineRunner.ts index 3773472c65..2f9c325894 100644 --- a/packages/cursorless-engine/src/processTargets/TargetPipelineRunner.ts +++ b/packages/cursorless-engine/src/processTargets/TargetPipelineRunner.ts @@ -231,7 +231,6 @@ class TargetPipeline { ); /** - * The modifier pipeline that will be applied to construct our final targets */ const modifierStages = [