Skip to content

Commit ee1e033

Browse files
Use correct delimited ranges for sub token words (#1563)
Fixes #1162 ## Checklist - [x] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [ ] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [ ] I have not broken the cheatsheet
1 parent 0e4c9d9 commit ee1e033

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

packages/cursorless-engine/src/processTargets/targets/SubTokenWordTarget.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { Range } from "@cursorless/common";
2+
import { Target } from "../../typings/target.types";
23
import { tryConstructPlainTarget } from "../../util/tryConstructTarget";
4+
import { isSameType } from "../../util/typeUtils";
5+
import { createContinuousRange } from "../targetUtil/createContinuousRange";
36
import { getDelimitedSequenceRemovalRange } from "../targetUtil/insertionRemovalBehaviors/DelimitedSequenceInsertionRemovalBehavior";
47
import BaseTarget, { CommonTargetParameters } from "./BaseTarget";
58

@@ -43,6 +46,34 @@ export default class SubTokenWordTarget extends BaseTarget<SubTokenTargetParamet
4346
return getDelimitedSequenceRemovalRange(this);
4447
}
4548

49+
createContinuousRangeTarget(
50+
isReversed: boolean,
51+
endTarget: Target,
52+
includeStart: boolean,
53+
includeEnd: boolean,
54+
): Target {
55+
if (isSameType(this, endTarget)) {
56+
return new SubTokenWordTarget({
57+
...this.getCloneParameters(),
58+
isReversed,
59+
contentRange: createContinuousRange(
60+
this,
61+
endTarget,
62+
includeStart,
63+
includeEnd,
64+
),
65+
trailingDelimiterRange: endTarget.trailingDelimiterRange_,
66+
});
67+
}
68+
69+
return super.createContinuousRangeTarget(
70+
isReversed,
71+
endTarget,
72+
includeStart,
73+
includeEnd,
74+
);
75+
}
76+
4677
protected getCloneParameters(): SubTokenTargetParameters {
4778
return {
4879
...this.state,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
languageId: plaintext
2+
command:
3+
version: 5
4+
spokenForm: chuck final two words
5+
action: {name: remove}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: ordinalScope
10+
scopeType: {type: word}
11+
start: -2
12+
length: 2
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: a_b_c
16+
selections:
17+
- anchor: {line: 0, character: 0}
18+
active: {line: 0, character: 0}
19+
marks: {}
20+
finalState:
21+
documentContents: a
22+
selections:
23+
- anchor: {line: 0, character: 0}
24+
active: {line: 0, character: 0}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
languageId: plaintext
2+
command:
3+
version: 5
4+
spokenForm: chuck first two words
5+
action: {name: remove}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: ordinalScope
10+
scopeType: {type: word}
11+
start: 0
12+
length: 2
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: a_b_c
16+
selections:
17+
- anchor: {line: 0, character: 0}
18+
active: {line: 0, character: 0}
19+
marks: {}
20+
finalState:
21+
documentContents: c
22+
selections:
23+
- anchor: {line: 0, character: 0}
24+
active: {line: 0, character: 0}

0 commit comments

Comments
 (0)