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..5bf7224620 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,15 @@ 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, - }); + }; + results.push(destinationEdit); } else { destination = destinations[0]; } @@ -106,10 +110,13 @@ abstract class BringMoveSwap { // 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); } + if (this.type === "bring") { results.push({ edit: source