mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
feat(code): display user-selected color themes
This commit is contained in:
parent
af187d1188
commit
b2aec4dfdb
@ -422,7 +422,6 @@ body.desktop #context-menu-container .dropdown-item > span {
|
|||||||
|
|
||||||
.cm-editor {
|
.cm-editor {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background: inherit;
|
|
||||||
outline: none !important;
|
outline: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,10 +81,6 @@ body ::-webkit-calendar-picker-indicator {
|
|||||||
filter: invert(1);
|
filter: invert(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
body .cm-editor {
|
|
||||||
filter: invert(90%) hue-rotate(180deg);
|
|
||||||
}
|
|
||||||
|
|
||||||
.excalidraw.theme--dark {
|
.excalidraw.theme--dark {
|
||||||
--theme-filter: invert(80%) hue-rotate(180deg) !important;
|
--theme-filter: invert(80%) hue-rotate(180deg) !important;
|
||||||
}
|
}
|
||||||
|
@ -244,10 +244,6 @@ body ::-webkit-calendar-picker-indicator {
|
|||||||
filter: invert(1);
|
filter: invert(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
body .cm-editor {
|
|
||||||
filter: invert(90%) hue-rotate(180deg);
|
|
||||||
}
|
|
||||||
|
|
||||||
.excalidraw.theme--dark {
|
.excalidraw.theme--dark {
|
||||||
--theme-filter: invert(80%) hue-rotate(180deg) !important;
|
--theme-filter: invert(80%) hue-rotate(180deg) !important;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { getThemeById } from "@triliumnext/codemirror";
|
||||||
import type FNote from "../../entities/fnote.js";
|
import type FNote from "../../entities/fnote.js";
|
||||||
import options from "../../services/options.js";
|
import options from "../../services/options.js";
|
||||||
import TypeWidget from "./type_widget.js";
|
import TypeWidget from "./type_widget.js";
|
||||||
@ -31,6 +32,12 @@ export default class AbstractCodeTypeWidget extends TypeWidget {
|
|||||||
lineWrapping: options.is("codeLineWrapEnabled"),
|
lineWrapping: options.is("codeLineWrapEnabled"),
|
||||||
...this.getExtraOpts()
|
...this.getExtraOpts()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Load the theme.
|
||||||
|
const theme = getThemeById(options.get("codeNoteTheme"));
|
||||||
|
if (theme) {
|
||||||
|
await this.codeEditor.setTheme(theme);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,4 +16,14 @@ const themes: ThemeDefinition[] = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
export function getThemeById(id: string) {
|
||||||
|
for (const theme of themes) {
|
||||||
|
if (theme.id === id) {
|
||||||
|
return theme;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
export default themes;
|
export default themes;
|
||||||
|
@ -8,7 +8,7 @@ import byMimeType from "./syntax_highlighting.js";
|
|||||||
import smartIndentWithTab from "./extensions/custom_tab.js";
|
import smartIndentWithTab from "./extensions/custom_tab.js";
|
||||||
import type { ThemeDefinition } from "./color_themes.js";
|
import type { ThemeDefinition } from "./color_themes.js";
|
||||||
|
|
||||||
export { default as ColorThemes, type ThemeDefinition } from "./color_themes.js";
|
export { default as ColorThemes, type ThemeDefinition, getThemeById } from "./color_themes.js";
|
||||||
|
|
||||||
type ContentChangedListener = () => void;
|
type ContentChangedListener = () => void;
|
||||||
|
|
||||||
@ -42,8 +42,9 @@ export default class CodeMirror extends EditorView {
|
|||||||
extensions = [
|
extensions = [
|
||||||
...extensions,
|
...extensions,
|
||||||
languageCompartment.of([]),
|
languageCompartment.of([]),
|
||||||
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
|
themeCompartment.of([
|
||||||
themeCompartment.of([]),
|
syntaxHighlighting(defaultHighlightStyle, { fallback: true })
|
||||||
|
]),
|
||||||
highlightActiveLine(),
|
highlightActiveLine(),
|
||||||
highlightSelectionMatches(),
|
highlightSelectionMatches(),
|
||||||
bracketMatching(),
|
bracketMatching(),
|
||||||
@ -108,7 +109,10 @@ export default class CodeMirror extends EditorView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async setTheme(theme: ThemeDefinition) {
|
async setTheme(theme: ThemeDefinition) {
|
||||||
this.themeCompartment.reconfigure(await theme.load());
|
const extension = await theme.load();
|
||||||
|
this.dispatch({
|
||||||
|
effects: [ this.themeCompartment.reconfigure([ extension ]) ]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user