Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/text editor/extended code blocks: allow CSS tweaks depending of the CodeMirror theme, tweak the background of the "VS Code" theme
Adorian Doran3dd6fe0c094c
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.cssindex 64b0409cd6..9e028735e4 100644--- a/apps/client/src/stylesheets/style.css+++ b/apps/client/src/stylesheets/style.css@@ -1537,6 +1537,14 @@ pre.code-embed-editor.read-only .cm-activeLine {padding-block: var(--padding-size, 1em);padding-inline-start: calc(var(--padding-size, 1em) - 6px);}++ .cm-editor[data-theme-name="vs-code-light"] {+ background-color: #f6f6f6;+ }++ .cm-editor[data-theme-name="vs-code-dark"] {+ background-color: #1c1b1b;+ }}/* CodeMirror scrolls in place of the box, so that the language label stays put. */diff --git a/packages/codemirror/src/index.spec.ts b/packages/codemirror/src/index.spec.tsindex cb36ae57bb..547750c762 100644--- a/packages/codemirror/src/index.spec.ts+++ b/packages/codemirror/src/index.spec.ts@@ -268,14 +268,19 @@ describe("CodeMirror", () => {});describe("configuration changes", () => {- it("swaps the theme", async () => {+ it("swaps the theme, and names the one it shows", async () => {editor = build();const theme = getThemeById("abyss");- expect(theme).not.toBeNull();- if (!theme) return;+ const otherTheme = getThemeById("github-light");+ expect([ theme, otherTheme ]).not.toContain(null);+ if (!theme || !otherTheme) return;await editor.setTheme(theme);expect(editor.getText()).toBe("");+ expect(editor.dom.getAttribute("data-theme-name")).toBe("abyss");++ await editor.setTheme(otherTheme);+ expect(editor.dom.getAttribute("data-theme-name")).toBe("github-light");});it("applies a theme it has loaded before without waiting", async () => {diff --git a/packages/codemirror/src/index.ts b/packages/codemirror/src/index.tsindex 7d5d1a5cb1..ecf8382179 100644--- a/packages/codemirror/src/index.ts+++ b/packages/codemirror/src/index.ts@@ -383,7 +383,10 @@ export default class CodeMirror extends EditorView {}}- /** Applies `theme`, at once if an editor has loaded it before. */+ /**+ * Applies `theme`, at once if an editor has loaded it before, and names it in the+ * `data-theme-name` attribute of `dom`.+ */async setTheme(theme: ThemeDefinition) {let extension = loadedThemes.get(theme);if (!extension) {@@ -391,7 +394,9 @@ export default class CodeMirror extends EditorView {loadedThemes.set(theme, extension);}this.dispatch({- effects: [ this.themeCompartment.reconfigure([ extension ]) ]+ effects: [ this.themeCompartment.reconfigure([+ extension, EditorView.editorAttributes.of({ "data-theme-name": theme.id })+ ]) ]});}