Skip to content

Commit 3917870

Browse files
Allow duplicate targets for bring action (#3083)
Fixes #3082
1 parent 1ecae85 commit 3917870

File tree

4 files changed

+95
-3
lines changed

4 files changed

+95
-3
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
languageId: typescript
2+
command:
3+
version: 7
4+
spokenForm: bring name
5+
action:
6+
name: replaceWithTarget
7+
source:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: name}
12+
destination: {type: implicit}
13+
usePrePhraseSnapshot: false
14+
initialState:
15+
documentContents: |-
16+
function aaa() {
17+
;
18+
;
19+
}
20+
21+
function bbb() {
22+
;
23+
}
24+
selections:
25+
- anchor: {line: 1, character: 2}
26+
active: {line: 1, character: 2}
27+
- anchor: {line: 2, character: 2}
28+
active: {line: 2, character: 2}
29+
- anchor: {line: 6, character: 2}
30+
active: {line: 6, character: 2}
31+
marks: {}
32+
finalState:
33+
documentContents: |-
34+
function aaa() {
35+
aaa;
36+
aaa;
37+
}
38+
39+
function bbb() {
40+
bbb;
41+
}
42+
selections:
43+
- anchor: {line: 1, character: 5}
44+
active: {line: 1, character: 5}
45+
- anchor: {line: 2, character: 5}
46+
active: {line: 2, character: 5}
47+
- anchor: {line: 6, character: 5}
48+
active: {line: 6, character: 5}
49+
thatMark:
50+
- type: UntypedTarget
51+
contentRange:
52+
start: {line: 1, character: 2}
53+
end: {line: 1, character: 5}
54+
isReversed: false
55+
hasExplicitRange: true
56+
- type: UntypedTarget
57+
contentRange:
58+
start: {line: 2, character: 2}
59+
end: {line: 2, character: 5}
60+
isReversed: false
61+
hasExplicitRange: true
62+
- type: UntypedTarget
63+
contentRange:
64+
start: {line: 6, character: 2}
65+
end: {line: 6, character: 5}
66+
isReversed: false
67+
hasExplicitRange: true
68+
sourceMark:
69+
- type: UntypedTarget
70+
contentRange:
71+
start: {line: 0, character: 9}
72+
end: {line: 0, character: 12}
73+
isReversed: false
74+
hasExplicitRange: true
75+
- type: UntypedTarget
76+
contentRange:
77+
start: {line: 0, character: 9}
78+
end: {line: 0, character: 12}
79+
isReversed: false
80+
hasExplicitRange: true
81+
- type: UntypedTarget
82+
contentRange:
83+
start: {line: 5, character: 9}
84+
end: {line: 5, character: 12}
85+
isReversed: false
86+
hasExplicitRange: true

data/fixtures/recorded/hatTokenMap/bringPointAndHarpToEndOfThisAndEndOfWhaleTakeWhale.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ finalState:
5656
end: {line: 0, character: 5}
5757
default.w:
5858
start: {line: 0, character: 7}
59-
end: {line: 0, character: 12}
59+
end: {line: 0, character: 18}

packages/cursorless-engine/src/core/commandRunner/CommandRunnerImpl.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class CommandRunnerImpl implements CommandRunner {
2727
private inferenceContext: InferenceContext;
2828
private finalStages: ModifierStage[] = [];
2929
private noAutomaticTokenExpansion: boolean | undefined;
30+
private allowDuplicateTargets: boolean | undefined;
3031

3132
constructor(
3233
private commandServerApi: CommandServerApi,
@@ -103,6 +104,7 @@ export class CommandRunnerImpl implements CommandRunner {
103104

104105
switch (actionDescriptor.name) {
105106
case "replaceWithTarget":
107+
this.allowDuplicateTargets = true;
106108
return this.actions.replaceWithTarget.run(
107109
this.getTargets(actionDescriptor.source),
108110
this.getDestinations(actionDescriptor.destination),
@@ -239,6 +241,7 @@ export class CommandRunnerImpl implements CommandRunner {
239241
return this.pipelineRunner.run(targetDescriptor, {
240242
actionFinalStages: this.finalStages,
241243
noAutomaticTokenExpansion: this.noAutomaticTokenExpansion,
244+
allowDuplicateTargets: this.allowDuplicateTargets,
242245
});
243246
}
244247

packages/cursorless-engine/src/processTargets/TargetPipelineRunner.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { PlainTarget } from "./targets";
2727
interface TargetPipelineRunnerOpts {
2828
actionFinalStages?: ModifierStage[];
2929
noAutomaticTokenExpansion?: boolean;
30+
allowDuplicateTargets?: boolean;
3031
}
3132

3233
export class TargetPipelineRunner {
@@ -53,13 +54,14 @@ export class TargetPipelineRunner {
5354
{
5455
actionFinalStages = [],
5556
noAutomaticTokenExpansion = false,
57+
allowDuplicateTargets = false,
5658
}: TargetPipelineRunnerOpts = {},
5759
): Target[] {
5860
return new TargetPipeline(
5961
this.modifierStageFactory,
6062
this.markStageFactory,
6163
target,
62-
{ actionFinalStages, noAutomaticTokenExpansion },
64+
{ actionFinalStages, noAutomaticTokenExpansion, allowDuplicateTargets },
6365
).run();
6466
}
6567
}
@@ -87,7 +89,8 @@ class TargetPipeline {
8789
* the target
8890
*/
8991
run(): Target[] {
90-
return uniqTargets(this.processTarget(this.target));
92+
const targets = this.processTarget(this.target);
93+
return this.opts.allowDuplicateTargets ? targets : uniqTargets(targets);
9194
}
9295

9396
processTarget(target: TargetDescriptor): Target[] {

0 commit comments

Comments
 (0)