@@ -116,6 +116,10 @@ export default class RantLangPlugin extends Plugin {
116
116
} ) ;
117
117
}
118
118
119
+ async onunload ( ) {
120
+ delete this . fileMap ;
121
+ }
122
+
119
123
async updateSettings ( settings : Partial < RantLangSettings > ) {
120
124
Object . assign ( this . settings , settings ) ;
121
125
await this . saveData ( this . settings ) ;
@@ -132,37 +136,15 @@ export default class RantLangPlugin extends Plugin {
132
136
processor . register ( ( ) => {
133
137
this . unregisterRantProcessor ( processor , file ) ;
134
138
} ) ;
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
- }
156
139
}
157
140
158
141
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 ) ) {
165
143
this . fileMap . get ( file ) . remove ( processor ) ;
144
+
145
+ if ( this . fileMap . get ( file ) . length == 0 ) {
146
+ this . fileMap . delete ( file ) ;
147
+ }
166
148
}
167
149
}
168
150
}
0 commit comments