From 2ad4abef211788c11dbc1d2d664210ca610066bf Mon Sep 17 00:00:00 2001 From: Pokey Rule Date: Mon, 6 Sep 2021 18:11:05 +0100 Subject: [PATCH] Rename purple to pink (#263) * Rename purple to pink * Cleanup --- package.json | 12 ++++----- src/canonicalizeTargets.ts | 50 +++++++++++++++++++++++++++++--------- src/core/constants.ts | 2 +- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 738af4e3a1..a2a2460783 100644 --- a/package.json +++ b/package.json @@ -165,8 +165,8 @@ "highContrast": "#f0b800" } }, - "cursorless.colors.purple": { - "description": "Color to use for purple symbols", + "cursorless.colors.pink": { + "description": "Color to use for pink symbols", "type": "object", "default": { "dark": "#de25ff", @@ -199,7 +199,7 @@ "yellow": { "type": "boolean" }, - "purple": { + "pink": { "type": "boolean" } }, @@ -208,7 +208,7 @@ "green": true, "red": true, "yellow": true, - "purple": true + "pink": true }, "additionalProperties": false }, @@ -265,7 +265,7 @@ "yellow": { "type": "number" }, - "purple": { + "pink": { "type": "number" } }, @@ -274,7 +274,7 @@ "green": 1, "red": 1, "yellow": 1, - "purple": 1 + "pink": 1 }, "additionalProperties": false }, diff --git a/src/canonicalizeTargets.ts b/src/canonicalizeTargets.ts index c24956cf9b..10d8d554fd 100755 --- a/src/canonicalizeTargets.ts +++ b/src/canonicalizeTargets.ts @@ -1,22 +1,50 @@ -import { PartialTarget, ScopeType } from "./typings/Types"; +import { + PartialPrimitiveTarget, + PartialTarget, + ScopeType, +} from "./typings/Types"; import update from "immutability-helper"; import { transformPrimitiveTargets } from "./util/targetUtils"; +import { HatStyleName } from "./core/constants"; +import { flow } from "lodash"; -const scopeTypeAliasToCanonicalName: Record = { +const SCOPE_TYPE_CANONICALIZATION_MAPPING: Record = { arrowFunction: "anonymousFunction", dictionary: "map", regex: "regularExpression", }; +const COLOR_CANONICALIZATION_MAPPING: Record = { + purple: "pink", +}; + +const canonicalizeScopeTypes = ( + target: PartialPrimitiveTarget +): PartialPrimitiveTarget => + target.modifier?.type === "containingScope" + ? update(target, { + modifier: { + scopeType: (scopeType: string) => + SCOPE_TYPE_CANONICALIZATION_MAPPING[scopeType] ?? scopeType, + }, + }) + : target; + +const canonicalizeColors = ( + target: PartialPrimitiveTarget +): PartialPrimitiveTarget => + target.mark?.type === "decoratedSymbol" + ? update(target, { + mark: { + symbolColor: (symbolColor: string) => + COLOR_CANONICALIZATION_MAPPING[symbolColor] ?? symbolColor, + }, + }) + : target; + export default function canonicalizeTargets(partialTargets: PartialTarget[]) { - return transformPrimitiveTargets(partialTargets, (target) => - target.modifier?.type === "containingScope" - ? update(target, { - modifier: { - scopeType: (scopeType) => - scopeTypeAliasToCanonicalName[scopeType] ?? scopeType, - }, - }) - : target + return transformPrimitiveTargets( + partialTargets, + flow(canonicalizeScopeTypes, canonicalizeColors) ); } diff --git a/src/core/constants.ts b/src/core/constants.ts index 55c9d67871..3460f68f49 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -7,8 +7,8 @@ export const HAT_COLORS = [ "blue", "green", "red", + "pink", "yellow", - "purple", ] as const; export const HAT_NON_DEFAULT_SHAPES = [