fix(code): align syntax highlight settings

This commit is contained in:
Elian Doran
2025-05-11 21:40:13 +03:00
parent b2aec4dfdb
commit 340dec725c
2 changed files with 9 additions and 4 deletions

View File

@@ -4,6 +4,8 @@ import options from "../../services/options.js";
import TypeWidget from "./type_widget.js"; import TypeWidget from "./type_widget.js";
import CodeMirror, { type EditorConfig } from "@triliumnext/codemirror"; import CodeMirror, { type EditorConfig } from "@triliumnext/codemirror";
export const DEFAULT_PREFIX = "default:";
/** /**
* An abstract {@link TypeWidget} which implements the CodeMirror editor, meant to be used as a parent for * An abstract {@link TypeWidget} which implements the CodeMirror editor, meant to be used as a parent for
* widgets requiring the editor. * widgets requiring the editor.
@@ -34,11 +36,14 @@ export default class AbstractCodeTypeWidget extends TypeWidget {
}); });
// Load the theme. // Load the theme.
const theme = getThemeById(options.get("codeNoteTheme")); const themeId = options.get("codeNoteTheme");
if (themeId?.startsWith(DEFAULT_PREFIX)) {
const theme = getThemeById(themeId.substring(DEFAULT_PREFIX.length));
if (theme) { if (theme) {
await this.codeEditor.setTheme(theme); await this.codeEditor.setTheme(theme);
} }
} }
}
/** /**
* Can be extended in derived classes to add extra options to the CodeMirror constructor. The options are appended * Can be extended in derived classes to add extra options to the CodeMirror constructor. The options are appended

View File

@@ -197,7 +197,7 @@ function getSyntaxHighlightingThemes() {
function getCodeNoteThemes() { function getCodeNoteThemes() {
return ColorThemes.map((theme) => ({ return ColorThemes.map((theme) => ({
val: theme.id, val: `default:${theme.id}`,
title: theme.id title: theme.id
})); }));
} }