Skip to content

Commit 0e0529c

Browse files
Fixed bug where move source were incorrectly dropped (#3061)
1 parent af35ab2 commit 0e0529c

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
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: 10 additions & 3 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,15 @@ abstract class BringMoveSwap {
8991
} else {
9092
text = source.contentText;
9193
}
94+
9295
// Add destination edit
93-
results.push({
96+
destinationEdit = {
9497
edit: destination.constructChangeEdit(text),
9598
editor: destination.editor,
9699
originalTarget: destination.target,
97100
isSource: false,
98-
});
101+
};
102+
results.push(destinationEdit);
99103
} else {
100104
destination = destinations[0];
101105
}
@@ -106,10 +110,13 @@ abstract class BringMoveSwap {
106110
// Allow move where the destination contains the source. eg "bring token to line"
107111
if (
108112
this.type !== "move" ||
109-
!destination.target.getRemovalRange().contains(source.contentRange)
113+
destinationEdit == null ||
114+
destinationEdit.editor.id !== source.editor.id ||
115+
!destinationEdit.edit.range.contains(source.contentRange)
110116
) {
111117
usedSources.push(source);
112118
}
119+
113120
if (this.type === "bring") {
114121
results.push({
115122
edit: source

0 commit comments

Comments
 (0)