From 958ca2a45173bf6dee1c2621d36e21caa003a53f Mon Sep 17 00:00:00 2001 From: Javier Martinez Date: Thu, 19 Sep 2024 15:15:12 +0000 Subject: [PATCH] Dispose marker listeners and only fetch current model problems --- src/lib/editor/code/EditorCode.svelte | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib/editor/code/EditorCode.svelte b/src/lib/editor/code/EditorCode.svelte index 4d9811f..91c8a6b 100644 --- a/src/lib/editor/code/EditorCode.svelte +++ b/src/lib/editor/code/EditorCode.svelte @@ -22,9 +22,11 @@ export let hideConsoleBar = false; let editorEl: HTMLElement; + let modelUri: Monaco.Uri; let monacoEditor: Monaco.editor.IStandaloneCodeEditor; let model: Monaco.editor.ITextModel; let readOnlyEditHandler: Monaco.IDisposable; + let markerListener: Monaco.IDisposable; let lineNumber = 1; let column = 1; let drawerClosed = false; @@ -83,8 +85,7 @@ loader.config({ monaco: monacoEditorImport.default }); monaco = await loader.init(); - - let modelUri = monaco.Uri.parse(goblDocURL); + modelUri = monaco.Uri.parse(goblDocURL); model = monaco.editor.createModel("", "json", modelUri); setSchemaURI(jsonSchemaURL); @@ -208,8 +209,9 @@ validateSchema(value); }); - monaco.editor.onDidChangeMarkers(() => { - problems.set(monaco.editor.getModelMarkers({})); + markerListener = monaco.editor.onDidChangeMarkers(() => { + const markers = monaco.editor.getModelMarkers({ resource: modelUri }); + problems.set(markers); }); monacoEditor.onDidChangeCursorPosition((event) => { @@ -229,6 +231,10 @@ onDestroy(() => { $problems = []; // reset problems + if (markerListener) { + markerListener.dispose(); + } + if (unsubscribeEditor != null) { unsubscribeEditor(); }