Skip to content
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

Invert color settings #280

Merged
merged 2 commits into from
Sep 21, 2021
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
108 changes: 60 additions & 48 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 4 additions & 12 deletions src/core/Decorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -138,28 +138,20 @@ export default class Decorations {
const { color, shape } = this.hatStyleMap[styleName];
const { svg, svgWidthPx, svgHeightPx } = hatSvgMap[shape];

const colorSetting = vscode.workspace
.getConfiguration("cursorless.colors")
.get<DecorationColorSetting>(color)!;
const { light, dark } = getHatThemeColors(color);

return {
name: styleName,
decoration: vscode.window.createTextEditorDecorationType({
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: {
Expand Down
28 changes: 28 additions & 0 deletions src/core/getHatThemeColors.ts
Original file line number Diff line number Diff line change
@@ -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<OldDecorationColorSetting>(colorName);

const dark =
oldStyleColorSetting?.dark ??
vscode.workspace
.getConfiguration("cursorless.colors.dark")
.get<string>(colorName)!;

const light =
oldStyleColorSetting?.light ??
vscode.workspace
.getConfiguration("cursorless.colors.light")
.get<string>(colorName)!;

return { light, dark };
}
6 changes: 0 additions & 6 deletions src/typings/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down