Skip to content

Commit c9f5e3d

Browse files
Allow move action where destination contains source (#3056)
eg `"bring token to line"` Fixes #3054
1 parent 343be34 commit c9f5e3d

File tree

4 files changed

+94
-2
lines changed

4 files changed

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

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,13 @@ abstract class BringMoveSwap {
103103
// Add source edit
104104
// Prevent multiple instances of the same expanded source.
105105
if (!usedSources.includes(source)) {
106-
usedSources.push(source);
106+
// Allow move where the destination contains the source. eg "bring token to line"
107+
if (
108+
this.type !== "move" ||
109+
!destination.target.getRemovalRange().contains(source.contentRange)
110+
) {
111+
usedSources.push(source);
112+
}
107113
if (this.type === "bring") {
108114
results.push({
109115
edit: source

packages/cursorless-engine/src/util/unifyRanges.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,7 @@ function mergeTargets(targets: Target[]): Target {
5656
}
5757

5858
function intersects(targetA: Target, targetB: Target) {
59-
return !!targetA.getRemovalRange().intersection(targetB.getRemovalRange());
59+
return (
60+
targetA.getRemovalRange().intersection(targetB.getRemovalRange()) != null
61+
);
6062
}

0 commit comments

Comments
 (0)