From ef4a4f0ad374944ddec28a18624197c03526a10e Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Fri, 1 Aug 2025 13:26:36 +0200 Subject: [PATCH 1/2] Fixed bug where move source were incorrectly dropped --- .../recorded/actions/moveBlockAfterFile.yml | 51 +++++++++++++++++++ .../src/actions/BringMoveSwap.ts | 14 +++-- 2 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 data/fixtures/recorded/actions/moveBlockAfterFile.yml diff --git a/data/fixtures/recorded/actions/moveBlockAfterFile.yml b/data/fixtures/recorded/actions/moveBlockAfterFile.yml new file mode 100644 index 0000000000..5ab73e85e5 --- /dev/null +++ b/data/fixtures/recorded/actions/moveBlockAfterFile.yml @@ -0,0 +1,51 @@ +languageId: plaintext +command: + version: 7 + spokenForm: move block after file + action: + name: moveToTarget + source: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: paragraph} + destination: + type: primitive + insertionMode: after + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: document} + usePrePhraseSnapshot: false +initialState: + documentContents: |- + a + + b + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: {} +finalState: + documentContents: |- + b + + a + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + thatMark: + - type: UntypedTarget + contentRange: + start: {line: 2, character: 0} + end: {line: 2, character: 1} + isReversed: false + hasExplicitRange: true + sourceMark: + - type: UntypedTarget + contentRange: + start: {line: 0, character: 0} + end: {line: 0, character: 0} + isReversed: false + hasExplicitRange: true diff --git a/packages/cursorless-engine/src/actions/BringMoveSwap.ts b/packages/cursorless-engine/src/actions/BringMoveSwap.ts index 5681afb061..d7c8c460bc 100644 --- a/packages/cursorless-engine/src/actions/BringMoveSwap.ts +++ b/packages/cursorless-engine/src/actions/BringMoveSwap.ts @@ -70,6 +70,8 @@ abstract class BringMoveSwap { sources.forEach((source, i) => { let destination = destinations[i]; + let destinationEdit: ExtendedEdit | undefined; + if ((source == null || destination == null) && !shouldJoinSources) { throw new Error("Targets must have same number of args"); } @@ -89,13 +91,14 @@ abstract class BringMoveSwap { } else { text = source.contentText; } - // Add destination edit - results.push({ + destinationEdit = { edit: destination.constructChangeEdit(text), editor: destination.editor, originalTarget: destination.target, isSource: false, - }); + }; + // Add destination edit + results.push(destinationEdit); } else { destination = destinations[0]; } @@ -105,8 +108,9 @@ abstract class BringMoveSwap { if (!usedSources.includes(source)) { // Allow move where the destination contains the source. eg "bring token to line" if ( - this.type !== "move" || - !destination.target.getRemovalRange().contains(source.contentRange) + destinationEdit == null || + destinationEdit.editor.id !== source.editor.id || + !destinationEdit.edit.range.contains(source.contentRange) ) { usedSources.push(source); } From cffcdf757f5b9c443b6d28e1daa535537c40e660 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Fri, 1 Aug 2025 13:33:39 +0200 Subject: [PATCH 2/2] Clean up --- packages/cursorless-engine/src/actions/BringMoveSwap.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/cursorless-engine/src/actions/BringMoveSwap.ts b/packages/cursorless-engine/src/actions/BringMoveSwap.ts index d7c8c460bc..5bf7224620 100644 --- a/packages/cursorless-engine/src/actions/BringMoveSwap.ts +++ b/packages/cursorless-engine/src/actions/BringMoveSwap.ts @@ -91,13 +91,14 @@ abstract class BringMoveSwap { } else { text = source.contentText; } + + // Add destination edit destinationEdit = { edit: destination.constructChangeEdit(text), editor: destination.editor, originalTarget: destination.target, isSource: false, }; - // Add destination edit results.push(destinationEdit); } else { destination = destinations[0]; @@ -108,12 +109,14 @@ abstract class BringMoveSwap { if (!usedSources.includes(source)) { // Allow move where the destination contains the source. eg "bring token to line" if ( + this.type !== "move" || destinationEdit == null || destinationEdit.editor.id !== source.editor.id || !destinationEdit.edit.range.contains(source.contentRange) ) { usedSources.push(source); } + if (this.type === "bring") { results.push({ edit: source