-
-
Notifications
You must be signed in to change notification settings - Fork 88
implement 'short paint' scope type #737
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
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
5a9d592
implement 'small paint' scope type
AndrewDant 6caf71c
additional test with white space on each side
AndrewDant b12268c
Merge remote-tracking branch 'origin/main' into small-paint
AndrewDant aa18213
updates to get small paint working besides removal range
AndrewDant dc864a9
stage refactors recommended during pair programming
AndrewDant d173bc9
Merge remote-tracking branch 'origin/main' into small-paint
AndrewDant 87498e2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] cf6cc31
revert some refactors after merging
AndrewDant 079642a
Merge remote-tracking branch 'AndrewDant/small-paint' into small-paint
AndrewDant b13f110
Merge remote-tracking branch 'origin/main' into small-paint
AndrewDant 3506d29
Updates small paint to stop on any surrounding pairs' delimiter
AndrewDant b085811
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 59012b4
some additional small paint tests
AndrewDant 7c87e2e
Merge remote-tracking branch 'AndrewDant/small-paint' into small-paint
AndrewDant e66d129
Merge branch 'main' into small-paint
AndreasArvidsson a0b62d7
rename small paint stage
AndrewDant 5ce21ca
remove unnecessary changed
AndrewDant 3bad85d
Merge branch 'main' into small-paint
AndrewDant 00080e4
update default phrase from small paint to short paint
AndrewDant 4f3ab2f
Merge remote-tracking branch 'AndrewDant/small-paint' into small-paint
AndrewDant bb3d2c2
update short paint every behavior
AndrewDant 3d2fdca
update short paint to call process surrounding pair directly
AndrewDant fa6d7c2
fix short paint stage capitalization
AndrewDant 23cf6bd
fix short paint modifier capitalization
AndrewDant 831604c
Merge branch 'main' into small-paint
AndrewDant c66e219
update small paint every tests and scope type in tests
AndrewDant df27e7d
refactor short paint
AndrewDant 4111578
Merge remote-tracking branch 'AndrewDant/small-paint' into small-paint
AndrewDant c8c1db9
Switch to strong containment implementation
pokey 18c33c4
Merge branch 'main' into small-paint
AndreasArvidsson a0feece
fix bug with paint selection type
AndrewDant a887b04
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9f51cce
fix a reference to short paint stage name
AndrewDant e69e682
remove outdated tests
AndrewDant 61523c3
boundedNonWhitespaceStage -> BoundedNonWhitespaceStage
pokey 03c0500
Cleanup
pokey 23bc193
paint and short paint tests
AndrewDant 8d19fac
Merge remote-tracking branch 'AndrewDant/small-paint' into small-paint
AndrewDant ca690e4
better change every paint pair tests
AndrewDant 436b0df
Merge branch 'main' into small-paint
AndreasArvidsson 65c4181
Merge branch 'main' into small-paint
AndrewDant d111942
Merge branch 'main' into small-paint
pokey be1a56c
Merge branch 'main' into small-paint
pokey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Target } from "../../typings/target.types"; | ||
import { | ||
ContainingScopeModifier, | ||
EveryScopeModifier, | ||
} from "../../typings/targetDescriptor.types"; | ||
import { ProcessedTargetsContext } from "../../typings/Types"; | ||
import { ModifierStage } from "../PipelineStages.types"; | ||
import { TokenTarget } from "../targets"; | ||
import getModifierStage from "../getModifierStage"; | ||
import { processSurroundingPair } from "./surroundingPair"; | ||
import { NoContainingScopeError } from "../../errors"; | ||
|
||
export type BoundedNonWhitespaceSequenceModifier = ( | ||
| ContainingScopeModifier | ||
| EveryScopeModifier | ||
) & { | ||
scopeType: { type: "boundedNonWhitespaceSequence" }; | ||
}; | ||
|
||
/** | ||
* Intersection of NonWhitespaceSequenceStage and a surrounding pair | ||
* Expand the target until reaching a white space or surrounding pair. | ||
* If there is no surrounding pair defaults to the non white space sequence | ||
*/ | ||
export default class BoundedNonWhitespaceSequenceStage | ||
implements ModifierStage | ||
{ | ||
constructor(private modifier: BoundedNonWhitespaceSequenceModifier) {} | ||
|
||
run(context: ProcessedTargetsContext, target: Target): Target[] { | ||
const paintStage = getModifierStage({ | ||
type: this.modifier.type, | ||
scopeType: { type: "nonWhitespaceSequence" }, | ||
}); | ||
|
||
const paintTargets = paintStage.run(context, target); | ||
|
||
const pairInfo = processSurroundingPair( | ||
context, | ||
target.editor, | ||
target.contentRange, | ||
{ | ||
type: "surroundingPair", | ||
delimiter: "any", | ||
requireStrongContainment: true, | ||
} | ||
); | ||
|
||
if (pairInfo == null) { | ||
return paintTargets; | ||
} | ||
|
||
const targets = paintTargets.flatMap((paintTarget) => { | ||
const contentRange = paintTarget.contentRange.intersection( | ||
pairInfo.interiorRange | ||
); | ||
|
||
if (contentRange == null || contentRange.isEmpty) { | ||
return []; | ||
} | ||
|
||
return [ | ||
new TokenTarget({ | ||
editor: target.editor, | ||
isReversed: target.isReversed, | ||
contentRange, | ||
}), | ||
]; | ||
}); | ||
|
||
if (targets.length === 0) { | ||
throw new NoContainingScopeError(this.modifier.scopeType.type); | ||
} | ||
|
||
return targets; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/processTargets/modifiers/surroundingPair/weaklyContains.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Offsets } from "./types"; | ||
|
||
/** | ||
* Determines whether {@link offsets1} weakly contains {@link offsets2}, which | ||
* defined as the boundaries of {@link offsets1} being inside or equal to the | ||
* boundaries of {@link offsets2}. | ||
* @param offsets1 The first set of offsets | ||
* @param offsets2 The second set of offsets | ||
* @returns `true` if {@link offsets1} weakly contains {@link offsets2} | ||
*/ | ||
export function weaklyContains(offsets1: Offsets, offsets2: Offsets) { | ||
return offsets1.start <= offsets2.start && offsets1.end >= offsets2.end; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.