From cafb6759af1fb640f53054ff0c20663e33c31656 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Wed, 27 Jul 2022 20:51:18 +0100 Subject: [PATCH 1/2] Fix inside ranges --- src/processTargets/targets/InteriorTarget.ts | 36 +++++++++++++++ .../surroundingPair/takeCoreRiskPastHarp.yml | 43 ++++++++++++++++++ .../takeCoreRiskPastJustHarp.yml | 45 +++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 src/test/suite/fixtures/recorded/surroundingPair/takeCoreRiskPastHarp.yml create mode 100644 src/test/suite/fixtures/recorded/surroundingPair/takeCoreRiskPastJustHarp.yml diff --git a/src/processTargets/targets/InteriorTarget.ts b/src/processTargets/targets/InteriorTarget.ts index 629a22fc5c..c5a4ee8a84 100644 --- a/src/processTargets/targets/InteriorTarget.ts +++ b/src/processTargets/targets/InteriorTarget.ts @@ -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 @@ -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 + ); + } } diff --git a/src/test/suite/fixtures/recorded/surroundingPair/takeCoreRiskPastHarp.yml b/src/test/suite/fixtures/recorded/surroundingPair/takeCoreRiskPastHarp.yml new file mode 100644 index 0000000000..4348a88701 --- /dev/null +++ b/src/test/suite/fixtures/recorded/surroundingPair/takeCoreRiskPastHarp.yml @@ -0,0 +1,43 @@ +languageId: plaintext +command: + spokenForm: take 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: setSelection} +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: |- + ( hello world ) + ( hello world ) + selections: + - anchor: {line: 0, character: 2} + active: {line: 1, character: 13} + thatMark: + - anchor: {line: 0, character: 2} + active: {line: 1, character: 13} +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}]}}] diff --git a/src/test/suite/fixtures/recorded/surroundingPair/takeCoreRiskPastJustHarp.yml b/src/test/suite/fixtures/recorded/surroundingPair/takeCoreRiskPastJustHarp.yml new file mode 100644 index 0000000000..4dee6711ca --- /dev/null +++ b/src/test/suite/fixtures/recorded/surroundingPair/takeCoreRiskPastJustHarp.yml @@ -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}]}}] From 53295b820db780adadc5d3202bef4fbbcd1e20c4 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 28 Jul 2022 11:20:37 +0100 Subject: [PATCH 2/2] Cleanup tests --- ...PastHarp.yml => clearCoreRiskPastHarp.yml} | 14 +++---- .../ditchCoreEachPastWhale.yml | 42 +++++++++++++++++++ 2 files changed, 48 insertions(+), 8 deletions(-) rename src/test/suite/fixtures/recorded/surroundingPair/{takeCoreRiskPastHarp.yml => clearCoreRiskPastHarp.yml} (84%) create mode 100644 src/test/suite/fixtures/recorded/surroundingPair/ditchCoreEachPastWhale.yml diff --git a/src/test/suite/fixtures/recorded/surroundingPair/takeCoreRiskPastHarp.yml b/src/test/suite/fixtures/recorded/surroundingPair/clearCoreRiskPastHarp.yml similarity index 84% rename from src/test/suite/fixtures/recorded/surroundingPair/takeCoreRiskPastHarp.yml rename to src/test/suite/fixtures/recorded/surroundingPair/clearCoreRiskPastHarp.yml index 4348a88701..21c8442ef9 100644 --- a/src/test/suite/fixtures/recorded/surroundingPair/takeCoreRiskPastHarp.yml +++ b/src/test/suite/fixtures/recorded/surroundingPair/clearCoreRiskPastHarp.yml @@ -1,6 +1,6 @@ languageId: plaintext command: - spokenForm: take core risk past harp + spokenForm: clear core risk past harp version: 2 targets: - type: range @@ -15,11 +15,11 @@ command: excludeAnchor: false excludeActive: false usePrePhraseSnapshot: true - action: {name: setSelection} + action: {name: clearAndSetSelection} initialState: documentContents: |- ( hello world ) - ( hello world ) + [ hello world ] selections: - anchor: {line: 1, character: 15} active: {line: 1, character: 15} @@ -31,13 +31,11 @@ initialState: start: {line: 1, character: 2} end: {line: 1, character: 7} finalState: - documentContents: |- - ( hello world ) - ( hello world ) + documentContents: ( ] selections: - anchor: {line: 0, character: 2} - active: {line: 1, character: 13} + active: {line: 0, character: 2} thatMark: - anchor: {line: 0, character: 2} - active: {line: 1, character: 13} + 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}]}}] diff --git a/src/test/suite/fixtures/recorded/surroundingPair/ditchCoreEachPastWhale.yml b/src/test/suite/fixtures/recorded/surroundingPair/ditchCoreEachPastWhale.yml new file mode 100644 index 0000000000..c919f93305 --- /dev/null +++ b/src/test/suite/fixtures/recorded/surroundingPair/ditchCoreEachPastWhale.yml @@ -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}]}}]