Skip to content

Commit e56a29f

Browse files
committed
fix: Properly unload rant processors
1 parent 294cfb2 commit e56a29f

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

src/main.ts

+9-27
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ export default class RantLangPlugin extends Plugin {
116116
});
117117
}
118118

119+
async onunload() {
120+
delete this.fileMap;
121+
}
122+
119123
async updateSettings(settings: Partial<RantLangSettings>) {
120124
Object.assign(this.settings, settings);
121125
await this.saveData(this.settings);
@@ -132,37 +136,15 @@ export default class RantLangPlugin extends Plugin {
132136
processor.register(() => {
133137
this.unregisterRantProcessor(processor, file);
134138
});
135-
136-
const view = this.app.workspace.getActiveViewOfType(MarkdownView);
137-
if (view && this.fileMap.has(file) && this.fileMap.get(file).length === 1) {
138-
const self = this;
139-
140-
const unregisterOnUnloadFile = around(view, {
141-
onUnloadFile: function (next) {
142-
return async function (unloaded: TFile) {
143-
if (unloaded == file) {
144-
self.fileMap.delete(file);
145-
unregisterOnUnloadFile();
146-
}
147-
148-
return await next.call(this, unloaded);
149-
};
150-
},
151-
});
152-
153-
view.register(unregisterOnUnloadFile);
154-
view.register(() => this.fileMap.delete(file));
155-
}
156139
}
157140

158141
unregisterRantProcessor(processor: BaseRantProcessor, file: TFile) {
159-
const view = this.app.workspace.getActiveViewOfType(MarkdownView);
160-
if (
161-
view &&
162-
this.fileMap.has(file) &&
163-
this.fileMap.get(file).contains(processor)
164-
) {
142+
if (this.fileMap.has(file) && this.fileMap.get(file).contains(processor)) {
165143
this.fileMap.get(file).remove(processor);
144+
145+
if (this.fileMap.get(file).length == 0) {
146+
this.fileMap.delete(file);
147+
}
166148
}
167149
}
168150
}

0 commit comments

Comments
 (0)