Skip to content

Commit 4e454ba

Browse files
committed
fix: check theme by body className
1 parent 694e605 commit 4e454ba

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/app.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ const handlers = {
7575
}
7676
style.textContent = data || '';
7777
},
78-
setTheme(dark: boolean) {
79-
document.documentElement.classList[dark ? 'add' : 'remove']('markmap-dark');
80-
},
78+
checkTheme,
8179
downloadSvg(path: string) {
8280
const content = new XMLSerializer().serializeToString(mm.svg.node());
8381
vscode.postMessage({ type: 'downloadSvg', data: { content, path } });
@@ -132,12 +130,22 @@ toolbar.setItems([
132130
]);
133131
const highlightEl = document.createElement('div');
134132
highlightEl.className = 'markmap-highlight-area';
133+
checkTheme();
134+
135135
setTimeout(() => {
136136
toolbar.attach(mm);
137137
document.body.append(toolbar.el);
138138
checkHighlight();
139139
});
140140

141+
function checkTheme() {
142+
// https://code.visualstudio.com/api/extension-guides/webview#theming-webview-content
143+
const isDark = ['vscode-dark', 'vscode-high-contrast'].some((cls) =>
144+
document.body.classList.contains(cls),
145+
);
146+
document.documentElement.classList[isDark ? 'add' : 'remove']('markmap-dark');
147+
}
148+
141149
function createButton(text: string) {
142150
const el = document.createElement('div');
143151
el.className = 'btn-text';

src/extension.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { JSItem, type CSSItem } from 'markmap-common';
33
import { fillTemplate } from 'markmap-render';
44
import { type IMarkmapJSONOptions } from 'markmap-view';
55
import {
6-
ColorThemeKind,
76
CustomTextEditorProvider,
87
ExtensionContext,
98
Position,
@@ -150,12 +149,8 @@ class MarkmapEditor implements CustomTextEditorProvider {
150149
});
151150
};
152151
const updateTheme = () => {
153-
const dark = [ColorThemeKind.Dark, ColorThemeKind.HighContrast].includes(
154-
vscodeWindow.activeColorTheme.kind,
155-
);
156152
webviewPanel.webview.postMessage({
157-
type: 'setTheme',
158-
data: dark,
153+
type: 'checkTheme',
159154
});
160155
};
161156
const update = () => {

0 commit comments

Comments
 (0)