Skip to content

Commit ef4a4f0

Browse files
Fixed bug where move source were incorrectly dropped
1 parent af35ab2 commit ef4a4f0

File tree

2 files changed

+60
-5
lines changed

2 files changed

+60
-5
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
languageId: plaintext
2+
command:
3+
version: 7
4+
spokenForm: move block after file
5+
action:
6+
name: moveToTarget
7+
source:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: paragraph}
12+
destination:
13+
type: primitive
14+
insertionMode: after
15+
target:
16+
type: primitive
17+
modifiers:
18+
- type: containingScope
19+
scopeType: {type: document}
20+
usePrePhraseSnapshot: false
21+
initialState:
22+
documentContents: |-
23+
a
24+
25+
b
26+
selections:
27+
- anchor: {line: 0, character: 0}
28+
active: {line: 0, character: 0}
29+
marks: {}
30+
finalState:
31+
documentContents: |-
32+
b
33+
34+
a
35+
selections:
36+
- anchor: {line: 0, character: 0}
37+
active: {line: 0, character: 0}
38+
thatMark:
39+
- type: UntypedTarget
40+
contentRange:
41+
start: {line: 2, character: 0}
42+
end: {line: 2, character: 1}
43+
isReversed: false
44+
hasExplicitRange: true
45+
sourceMark:
46+
- type: UntypedTarget
47+
contentRange:
48+
start: {line: 0, character: 0}
49+
end: {line: 0, character: 0}
50+
isReversed: false
51+
hasExplicitRange: true

packages/cursorless-engine/src/actions/BringMoveSwap.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ abstract class BringMoveSwap {
7070

7171
sources.forEach((source, i) => {
7272
let destination = destinations[i];
73+
let destinationEdit: ExtendedEdit | undefined;
74+
7375
if ((source == null || destination == null) && !shouldJoinSources) {
7476
throw new Error("Targets must have same number of args");
7577
}
@@ -89,13 +91,14 @@ abstract class BringMoveSwap {
8991
} else {
9092
text = source.contentText;
9193
}
92-
// Add destination edit
93-
results.push({
94+
destinationEdit = {
9495
edit: destination.constructChangeEdit(text),
9596
editor: destination.editor,
9697
originalTarget: destination.target,
9798
isSource: false,
98-
});
99+
};
100+
// Add destination edit
101+
results.push(destinationEdit);
99102
} else {
100103
destination = destinations[0];
101104
}
@@ -105,8 +108,9 @@ abstract class BringMoveSwap {
105108
if (!usedSources.includes(source)) {
106109
// Allow move where the destination contains the source. eg "bring token to line"
107110
if (
108-
this.type !== "move" ||
109-
!destination.target.getRemovalRange().contains(source.contentRange)
111+
destinationEdit == null ||
112+
destinationEdit.editor.id !== source.editor.id ||
113+
!destinationEdit.edit.range.contains(source.contentRange)
110114
) {
111115
usedSources.push(source);
112116
}

0 commit comments

Comments
 (0)