From 32ae67b2c6bfd7574a6c15eba1cbfacc1e2d5bdb Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Fri, 15 Dec 2023 16:15:18 +0100 Subject: [PATCH] writing some very shady logic --- src/API.ts | 4 ++++ src/EditorSetup.ts | 7 ++----- src/main.ts | 16 +++++++++++----- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/API.ts b/src/API.ts index 3e36155..e956db2 100644 --- a/src/API.ts +++ b/src/API.ts @@ -2272,4 +2272,8 @@ export class UserAPI { this.cueTimes[functionName] = this.app.clock.pulses_since_origin; }; + public theme = (color_scheme: string): void => { + this.app.readTheme(color_scheme); + console.log("Changing color scheme for: ", color_scheme) + } } diff --git a/src/EditorSetup.ts b/src/EditorSetup.ts index 4e7984a..624ca14 100644 --- a/src/EditorSetup.ts +++ b/src/EditorSetup.ts @@ -8,8 +8,6 @@ import { drawSelection, highlightActiveLine, dropCursor, - // rectangularSelection, - // crosshairCursor, highlightActiveLineGutter, } from "@codemirror/view"; import { Extension, EditorState } from "@codemirror/state"; @@ -32,13 +30,12 @@ import { lintKeymap } from "@codemirror/lint"; import { Compartment } from "@codemirror/state"; import { Editor } from "./main"; import { EditorView } from "codemirror"; -import { toposTheme } from "./themes/toposTheme"; import { javascript } from "@codemirror/lang-javascript"; import { inlineHoveringTips } from "./documentation/inlineHelp"; import { toposCompletions, soundCompletions } from "./documentation/inlineHelp"; import { javascriptLanguage } from "@codemirror/lang-javascript"; -export const updateCodeMirrorTheme = (theme: {[key: string]: string}): Extension => { +export const getCodeMirrorTheme = (theme: {[key: string]: string}): Extension => { const color0 = theme["color0"], color1 = theme["color1"], color2 = theme["color2"], @@ -300,7 +297,7 @@ export const installEditor = (app: Editor) => { app.settings.completions ? [jsCompletions, toposSoundCompletions] : [], ), editorSetup, - toposTheme, + getCodeMirrorTheme(app.getColorScheme("Tomorrow Night Burns")), app.chosenLanguage.of(javascript()), ]; app.dynamicPlugins = new Compartment(); diff --git a/src/main.ts b/src/main.ts index 43c4c0f..067a0da 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,6 +5,7 @@ import { javascript } from "@codemirror/lang-javascript"; import { markdown } from "@codemirror/lang-markdown"; import { Extension } from "@codemirror/state"; import { outputSocket } from "./IO/OSC"; +import { getCodeMirrorTheme } from "./EditorSetup"; import { initializeSelectedUniverse, AppSettings, @@ -572,19 +573,24 @@ export class Editor { } private updateInterfaceTheme(selected_theme: {[key: string]: string}): void { - // We will update CSS variables to change the theme for (const [key, value] of Object.entries(selected_theme)) { - document.documentElement.style.setProperty(key, value); + document.documentElement.style.setProperty("--" + key, value); } } - private readTheme(theme_name: string): void { + getColorScheme(theme_name: string): {[key: string]: string} { + // Check if the theme exists in colors.json + let themes: Record = colors; + return themes[theme_name]; + } + + readTheme(theme_name: string): void { // Check if the theme exists in colors.json let themes: Record = colors; let selected_theme = themes[theme_name]; - if (selected_theme) { + if (selected_theme) { this.updateInterfaceTheme(selected_theme); - updateCodeMirrorTheme(selected_theme); + let codeMirrorTheme = getCodeMirrorTheme(selected_theme); } } }