Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions data/fixtures/recorded/actions/moveBlockAfterFile.yml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 10 additions & 3 deletions packages/cursorless-engine/src/actions/BringMoveSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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];
}
Expand All @@ -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
Expand Down
Loading