@@ -3,7 +3,6 @@ import { JSItem, type CSSItem } from 'markmap-common';
33import { fillTemplate } from 'markmap-render' ;
44import { defaultOptions , type IMarkmapJSONOptions } from 'markmap-view' ;
55import {
6- CancellationToken ,
76 ColorThemeKind ,
87 CustomTextEditorProvider ,
98 ExtensionContext ,
@@ -61,11 +60,7 @@ class MarkmapEditor implements CustomTextEditorProvider {
6160 return data ;
6261 }
6362
64- public async resolveCustomTextEditor (
65- document : TextDocument ,
66- webviewPanel : WebviewPanel ,
67- token : CancellationToken ,
68- ) : Promise < void > {
63+ resolveCustomTextEditor ( document : TextDocument , webviewPanel : WebviewPanel ) {
6964 webviewPanel . webview . options = {
7065 enableScripts : true ,
7166 } ;
@@ -290,30 +285,38 @@ class MarkmapEditor implements CustomTextEditorProvider {
290285 logger . appendLine ( data ) ;
291286 } ,
292287 } ;
293- webviewPanel . webview . onDidReceiveMessage ( ( e ) => {
294- const handler = messageHandlers [ e . type ] ;
295- handler ?.( e . data ) ;
296- } ) ;
297- workspace . onDidChangeTextDocument ( ( e ) => {
298- if ( e . document !== document ) return ;
299- debouncedUpdate ( ) ;
300- } ) ;
301- vscodeWindow . onDidChangeTextEditorSelection ( ( e ) => {
302- if ( e . textEditor . document !== document ) return ;
303- debouncedUpdateCursor ( ) ;
304- } ) ;
305- vscodeWindow . onDidChangeActiveColorTheme ( updateTheme ) ;
288+
306289 updateOptions ( ) ;
307290 updateCSS ( ) ;
308291 updateTheme ( ) ;
309- workspace . onDidChangeConfiguration ( ( e ) => {
310- if ( e . affectsConfiguration ( 'markmap.defaultOptions' ) ) updateOptions ( ) ;
311- if ( e . affectsConfiguration ( 'markmap.customCSS' ) ) updateCSS ( ) ;
292+
293+ const disposables = [
294+ webviewPanel . webview . onDidReceiveMessage ( ( e ) => {
295+ const handler = messageHandlers [ e . type ] ;
296+ handler ?.( e . data ) ;
297+ } ) ,
298+ workspace . onDidChangeTextDocument ( ( e ) => {
299+ if ( e . document !== document ) return ;
300+ debouncedUpdate ( ) ;
301+ } ) ,
302+ vscodeWindow . onDidChangeTextEditorSelection ( ( e ) => {
303+ if ( e . textEditor . document !== document ) return ;
304+ debouncedUpdateCursor ( ) ;
305+ } ) ,
306+ vscodeWindow . onDidChangeActiveColorTheme ( updateTheme ) ,
307+ workspace . onDidChangeConfiguration ( ( e ) => {
308+ if ( e . affectsConfiguration ( 'markmap.defaultOptions' ) ) updateOptions ( ) ;
309+ if ( e . affectsConfiguration ( 'markmap.customCSS' ) ) updateCSS ( ) ;
310+ } ) ,
311+ ] ;
312+ webviewPanel . onDidDispose ( ( ) => {
313+ disposables . forEach ( ( disposable ) => disposable . dispose ( ) ) ;
312314 } ) ;
313315 }
314316}
315317
316318export function activate ( context : ExtensionContext ) {
319+ const markmapEditor = new MarkmapEditor ( context ) ;
317320 context . subscriptions . push (
318321 commands . registerCommand ( `${ PREFIX } .open` , ( uri ?: Uri ) => {
319322 uri ??= vscodeWindow . activeTextEditor ?. document . uri ;
@@ -325,7 +328,6 @@ export function activate(context: ExtensionContext) {
325328 ) ;
326329 } ) ,
327330 ) ;
328- const markmapEditor = new MarkmapEditor ( context ) ;
329331 context . subscriptions . push (
330332 vscodeWindow . registerCustomEditorProvider ( VIEW_TYPE , markmapEditor , {
331333 webviewOptions : { retainContextWhenHidden : true } ,
0 commit comments