Skip to content

Fix inside ranges #895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/processTargets/targets/InteriorTarget.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Range } from "vscode";
import { Target } from "../../typings/target.types";
import { shrinkRangeToFitContent } from "../../util/selectionUtils";
import { isSameType } from "../../util/typeUtils";
import {
createContinuousRangeFromRanges,
createContinuousRangeUntypedTarget,
} from "../targetUtil/createContinuousRange";
import BaseTarget, { CommonTargetParameters } from "./BaseTarget";

export interface InteriorTargetParameters
Expand Down Expand Up @@ -32,4 +38,34 @@ export default class InteriorTarget extends BaseTarget {
fullInteriorRange: this.fullInteriorRange,
};
}

createContinuousRangeTarget(
isReversed: boolean,
endTarget: Target,
includeStart: boolean,
includeEnd: boolean
): Target {
if (isSameType(this, endTarget)) {
const constructor = Object.getPrototypeOf(this).constructor;

return new constructor({
...this.getCloneParameters(),
isReversed,
fullInteriorRange: createContinuousRangeFromRanges(
this.fullInteriorRange,
endTarget.fullInteriorRange,
includeStart,
includeEnd
),
});
}

return createContinuousRangeUntypedTarget(
isReversed,
this,
endTarget,
includeStart,
includeEnd
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
languageId: plaintext
command:
spokenForm: clear core risk past harp
version: 2
targets:
- type: range
anchor:
type: primitive
modifiers:
- {type: interiorOnly}
mark: {type: decoratedSymbol, symbolColor: default, character: r}
active:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: h}
excludeAnchor: false
excludeActive: false
usePrePhraseSnapshot: true
action: {name: clearAndSetSelection}
initialState:
documentContents: |-
( hello world )
[ hello world ]
selections:
- anchor: {line: 1, character: 15}
active: {line: 1, character: 15}
marks:
default.r:
start: {line: 0, character: 8}
end: {line: 0, character: 13}
default.h:
start: {line: 1, character: 2}
end: {line: 1, character: 7}
finalState:
documentContents: ( ]
selections:
- anchor: {line: 0, character: 2}
active: {line: 0, character: 2}
thatMark:
- anchor: {line: 0, character: 2}
active: {line: 0, character: 2}
fullTargets: [{type: range, excludeAnchor: false, excludeActive: false, rangeType: continuous, anchor: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: r}, modifiers: [{type: interiorOnly}]}, active: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: h}, modifiers: [{type: interiorOnly}]}}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
languageId: plaintext
command:
spokenForm: ditch core each past whale
version: 2
targets:
- type: range
anchor:
type: primitive
modifiers:
- {type: interiorOnly}
mark: {type: decoratedSymbol, symbolColor: default, character: e}
active:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: w}
excludeAnchor: false
excludeActive: false
usePrePhraseSnapshot: true
action: {name: remove}
initialState:
documentContents: |
( hello world )
( hello world )
selections:
- anchor: {line: 2, character: 0}
active: {line: 2, character: 0}
marks:
default.e:
start: {line: 0, character: 2}
end: {line: 0, character: 7}
default.w:
start: {line: 1, character: 8}
end: {line: 1, character: 13}
finalState:
documentContents: |
()
selections:
- anchor: {line: 1, character: 0}
active: {line: 1, character: 0}
thatMark:
- anchor: {line: 0, character: 1}
active: {line: 0, character: 1}
fullTargets: [{type: range, excludeAnchor: false, excludeActive: false, rangeType: continuous, anchor: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: e}, modifiers: [{type: interiorOnly}]}, active: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: w}, modifiers: [{type: interiorOnly}]}}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
languageId: plaintext
command:
spokenForm: take core risk past just harp
version: 2
targets:
- type: range
anchor:
type: primitive
modifiers:
- {type: interiorOnly}
mark: {type: decoratedSymbol, symbolColor: default, character: r}
active:
type: primitive
modifiers:
- {type: toRawSelection}
mark: {type: decoratedSymbol, symbolColor: default, character: h}
excludeAnchor: false
excludeActive: false
usePrePhraseSnapshot: true
action: {name: setSelection}
initialState:
documentContents: |-
( hello world )
(hello world)
selections:
- anchor: {line: 1, character: 13}
active: {line: 1, character: 13}
marks:
default.r:
start: {line: 0, character: 8}
end: {line: 0, character: 13}
default.h:
start: {line: 1, character: 1}
end: {line: 1, character: 6}
finalState:
documentContents: |-
( hello world )
(hello world)
selections:
- anchor: {line: 0, character: 2}
active: {line: 1, character: 6}
thatMark:
- anchor: {line: 0, character: 2}
active: {line: 1, character: 6}
fullTargets: [{type: range, excludeAnchor: false, excludeActive: false, rangeType: continuous, anchor: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: r}, modifiers: [{type: interiorOnly}]}, active: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: h}, modifiers: [{type: toRawSelection}]}}]