diff --git a/package.json b/package.json index de1263cc9f..de8930bffd 100644 --- a/package.json +++ b/package.json @@ -129,59 +129,71 @@ "default": 0, "description": "How much to vertically shift the hats as a percentage of font size; positive is up" }, - "cursorless.colors.default": { - "description": "Color to use for default symbols", - "type": "object", - "default": { - "dark": "#aaa7bb", - "light": "#666666", - "highContrast": "#ffffff" - } - }, - "cursorless.colors.blue": { - "description": "Color to use for blue symbols", - "type": "object", - "default": { - "dark": "#089ad3", - "light": "#089ad3", - "highContrast": "#089ad3" - } - }, - "cursorless.colors.green": { - "description": "Color to use for green symbols", - "type": "object", - "default": { - "dark": "#05b623", - "light": "#05b623", - "highContrast": "#05b623" - } - }, - "cursorless.colors.red": { - "description": "Color to use for red symbols", - "type": "object", - "default": { - "dark": "#ca2a15", - "light": "#ca2a15", - "highContrast": "#ca2a15" - } - }, - "cursorless.colors.pink": { - "description": "Color to use for pink symbols", + "cursorless.colors.dark": { + "description": "Colors to use for dark theme", "type": "object", + "properties": { + "default": { + "type": "string" + }, + "blue": { + "type": "string" + }, + "green": { + "type": "string" + }, + "red": { + "type": "string" + }, + "pink": { + "type": "string" + }, + "yellow": { + "type": "string" + } + }, "default": { - "dark": "#e17fab", - "light": "#e17fab", - "highContrast": "#e17fab" - } + "default": "#aaa7bb", + "blue": "#089ad3", + "green": "#05b623", + "red": "#ca2a15", + "pink": "#e17fab", + "yellow": "#e5c300" + }, + "additionalProperties": false }, - "cursorless.colors.yellow": { - "description": "Color to use for yellow symbols", + "cursorless.colors.light": { + "description": "Colors to use for light theme", "type": "object", + "properties": { + "default": { + "type": "string" + }, + "blue": { + "type": "string" + }, + "green": { + "type": "string" + }, + "red": { + "type": "string" + }, + "pink": { + "type": "string" + }, + "yellow": { + "type": "string" + } + }, "default": { - "dark": "#e5c300", - "light": "#e5c300", - "highContrast": "#e5c300" - } + "default": "#666666", + "blue": "#089ad3", + "green": "#05b623", + "red": "#ca2a15", + "pink": "#e17fab", + "yellow": "#e5c300" + }, + "additionalProperties": false }, "cursorless.hatEnablement.colors": { "description": "Which colors to enable", diff --git a/src/core/Decorations.ts b/src/core/Decorations.ts index a4c6bd47d1..313696a0da 100644 --- a/src/core/Decorations.ts +++ b/src/core/Decorations.ts @@ -10,9 +10,9 @@ import { HatColor, } from "./constants"; import { readFileSync } from "fs"; -import { DecorationColorSetting } from "../typings/Types"; import FontMeasurements from "./FontMeasurements"; import { sortBy } from "lodash"; +import getHatThemeColors from "./getHatThemeColors"; interface ShapeMeasurements { hatWidthToCharacterWidthRatio: number; @@ -138,9 +138,7 @@ export default class Decorations { const { color, shape } = this.hatStyleMap[styleName]; const { svg, svgWidthPx, svgHeightPx } = hatSvgMap[shape]; - const colorSetting = vscode.workspace - .getConfiguration("cursorless.colors") - .get(color)!; + const { light, dark } = getHatThemeColors(color); return { name: styleName, @@ -148,18 +146,12 @@ export default class Decorations { rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed, light: { before: { - contentIconPath: this.constructColoredSvgDataUri( - svg, - colorSetting.light - ), + contentIconPath: this.constructColoredSvgDataUri(svg, light), }, }, dark: { before: { - contentIconPath: this.constructColoredSvgDataUri( - svg, - colorSetting.dark - ), + contentIconPath: this.constructColoredSvgDataUri(svg, dark), }, }, before: { diff --git a/src/core/getHatThemeColors.ts b/src/core/getHatThemeColors.ts new file mode 100644 index 0000000000..e7ca4283af --- /dev/null +++ b/src/core/getHatThemeColors.ts @@ -0,0 +1,28 @@ +import * as vscode from "vscode"; +import { HatColor } from "./constants"; + +interface OldDecorationColorSetting { + dark: string; + light: string; + highContrast: string; +} + +export default function getHatThemeColors(colorName: HatColor) { + const oldStyleColorSetting = vscode.workspace + .getConfiguration("cursorless.colors") + .get(colorName); + + const dark = + oldStyleColorSetting?.dark ?? + vscode.workspace + .getConfiguration("cursorless.colors.dark") + .get(colorName)!; + + const light = + oldStyleColorSetting?.light ?? + vscode.workspace + .getConfiguration("cursorless.colors.light") + .get(colorName)!; + + return { light, dark }; +} diff --git a/src/typings/Types.ts b/src/typings/Types.ts index d4880b4a79..c582d98f49 100644 --- a/src/typings/Types.ts +++ b/src/typings/Types.ts @@ -321,12 +321,6 @@ export interface Graph { readonly navigationMap: NavigationMap; } -export interface DecorationColorSetting { - dark: string; - light: string; - highContrast: string; -} - export type NodeMatcherValue = { node: SyntaxNode; selection: SelectionWithContext;