Skip to content

Commit a8bb029

Browse files
committed
fix: reset options after removing
1 parent 1509f3d commit a8bb029

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/extension.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import debounce from 'lodash.debounce';
22
import { JSItem, type CSSItem } from 'markmap-common';
33
import { fillTemplate } from 'markmap-render';
4-
import type { IMarkmapJSONOptions } from 'markmap-view';
4+
import { defaultOptions, type IMarkmapJSONOptions } from 'markmap-view';
55
import {
66
CancellationToken,
77
ColorThemeKind,
@@ -35,7 +35,7 @@ const renderToolbar = () => {
3535
};
3636

3737
class MarkmapEditor implements CustomTextEditorProvider {
38-
constructor(private context: ExtensionContext) { }
38+
constructor(private context: ExtensionContext) {}
3939

4040
private resolveAssetPath(relPath: string) {
4141
return Utils.joinPath(this.context.extensionUri, relPath);
@@ -100,16 +100,16 @@ class MarkmapEditor implements CustomTextEditorProvider {
100100
});
101101
}
102102
};
103-
let defaultOptions: IMarkmapJSONOptions;
103+
let globalOptions: IMarkmapJSONOptions;
104104
let customCSS: string;
105105
const updateOptions = () => {
106106
const raw = workspace
107107
.getConfiguration('markmap')
108108
.get<string>('defaultOptions');
109109
try {
110-
defaultOptions = raw && JSON.parse(raw);
110+
globalOptions = raw && JSON.parse(raw);
111111
} catch {
112-
defaultOptions = null;
112+
globalOptions = null;
113113
}
114114
update();
115115
};
@@ -123,7 +123,9 @@ class MarkmapEditor implements CustomTextEditorProvider {
123123
});
124124
};
125125
const updateTheme = () => {
126-
const dark = [ColorThemeKind.Dark, ColorThemeKind.HighContrast].includes(vscodeWindow.activeColorTheme.kind);
126+
const dark = [ColorThemeKind.Dark, ColorThemeKind.HighContrast].includes(
127+
vscodeWindow.activeColorTheme.kind,
128+
);
127129
webviewPanel.webview.postMessage({
128130
type: 'setTheme',
129131
data: dark,
@@ -138,6 +140,7 @@ class MarkmapEditor implements CustomTextEditorProvider {
138140
root,
139141
jsonOptions: {
140142
...defaultOptions,
143+
...globalOptions,
141144
...(frontmatter as any)?.markmap,
142145
},
143146
},
@@ -169,7 +172,7 @@ class MarkmapEditor implements CustomTextEditorProvider {
169172
const md = document.getText();
170173
const { root, features, frontmatter } = transformerExport.transform(md);
171174
const jsonOptions = {
172-
...defaultOptions,
175+
...globalOptions,
173176
...(frontmatter as any)?.markmap,
174177
};
175178
const { embedAssets } = jsonOptions as { embedAssets?: boolean };
@@ -180,11 +183,11 @@ class MarkmapEditor implements CustomTextEditorProvider {
180183
styles: [
181184
...(customCSS
182185
? [
183-
{
184-
type: 'style',
185-
data: customCSS,
186-
} as CSSItem,
187-
]
186+
{
187+
type: 'style',
188+
data: customCSS,
189+
} as CSSItem,
190+
]
188191
: []),
189192
],
190193
scripts: [

0 commit comments

Comments
 (0)