Skip to content

Commit

Permalink
fix: InvalidLinkExtensions unsubscribes from metadata updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dtkav committed Oct 1, 2024
1 parent bcb3dd6 commit 1aa2e08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/LiveViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ export class LiveViewManager {
this.metadataListeners.set(tfile, cb);
}

offMeta(tfile: TFile) {
this.metadataListeners.delete(tfile);
}

openDiffView(state: Differ.ViewState) {
Differ.openDiffView(this.workspace, state);
}
Expand Down
10 changes: 7 additions & 3 deletions src/markdownView/InvalidLinkExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class InvalidLinkPluginValue {
connectionManager?: LiveViewManager;
decorationAnchors: number[];
decorations: DecorationSet;
cb: (data: string, cache: CachedMetadata) => void;
log: (message: string) => void = (message: string) => {};

constructor(editor: EditorView) {
Expand All @@ -56,7 +57,7 @@ export class InvalidLinkPluginValue {
this.decorations = Decoration.none;
this.decorationAnchors = [];
this.metadata = new Map();
const cb = (data: string, cache: CachedMetadata) => {
this.cb = (data: string, cache: CachedMetadata) => {
this.updateFromMetadata(cache);
this.editor.dispatch({
effects: metadataChangeEffect.of(null),
Expand Down Expand Up @@ -86,7 +87,7 @@ export class InvalidLinkPluginValue {
if (this.view.document) {
this.view.document.whenSynced().then(() => {
if (this.connectionManager && this.view?.document?.tfile) {
this.connectionManager.onMeta(this.view.document.tfile, cb);
this.connectionManager.onMeta(this.view.document.tfile, this.cb);
const fileCache = app.metadataCache.getFileCache(
this.view.document.tfile,
);
Expand Down Expand Up @@ -284,11 +285,14 @@ export class InvalidLinkPluginValue {
}

destroy() {
if (this.connectionManager && this.view?.document?.tfile) {
this.connectionManager.offMeta(this.view.document.tfile);
}
this.connectionManager = null as any;
this.view = undefined;
this.editor = null as any;
this.metadata.clear();
this.metadata = null as any;
this.editor = null as any;
}
}

Expand Down

0 comments on commit 1aa2e08

Please sign in to comment.