File tree Expand file tree Collapse file tree 2 files changed +12
-9
lines changed
Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Original file line number Diff line number Diff 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] ) ;
133131const highlightEl = document . createElement ( 'div' ) ;
134132highlightEl . className = 'markmap-highlight-area' ;
133+ checkTheme ( ) ;
134+
135135setTimeout ( ( ) => {
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+
141149function createButton ( text : string ) {
142150 const el = document . createElement ( 'div' ) ;
143151 el . className = 'btn-text' ;
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ import { JSItem, type CSSItem } from 'markmap-common';
33import { fillTemplate } from 'markmap-render' ;
44import { type IMarkmapJSONOptions } from 'markmap-view' ;
55import {
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 = ( ) => {
You can’t perform that action at this time.
0 commit comments