fix: sync global theme on construct when theme option is explicitly provided

This commit is contained in:
2026-07-23 17:10:52 +08:00
parent 616e9311e9
commit 234907b27f
+8 -1
View File
@@ -11,7 +11,7 @@ import { injectStyles } from './styles.js';
import { t as i18nT, getCurrentLocale, getLocaleDirection } from './i18n.js'; import { t as i18nT, getCurrentLocale, getLocaleDirection } from './i18n.js';
import { parseMarkdown } from './parser.js'; import { parseMarkdown } from './parser.js';
import { presetPlugins } from './plugins.js'; import { presetPlugins } from './plugins.js';
import { getTheme } from './themes.js'; import { getTheme, applyTheme, saveTheme } from './themes.js';
const MODES = ['edit', 'split', 'preview']; const MODES = ['edit', 'split', 'preview'];
@@ -97,6 +97,13 @@ class MarkdownEditor {
injectStyles(); injectStyles();
this._buildDOM(); this._buildDOM();
// 主题同步:用户显式传 theme 时覆盖全局 CSS 变量并持久化,否则尊重 localStorage
if (options.theme) {
applyTheme(this.config.theme);
saveTheme(this.config.theme);
}
this._buildToolbar(); this._buildToolbar();
this._bindEvents(); this._bindEvents();