File tree Expand file tree Collapse file tree 3 files changed +31
-12
lines changed Expand file tree Collapse file tree 3 files changed +31
-12
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,15 @@ export class MDRCManager {
77 this . activeMDRCs = new Map < string , AbstractMDRC > ( ) ;
88 }
99
10+ unloadFile ( filePath : string ) : void {
11+ for ( const mdrc of this . activeMDRCs . values ( ) ) {
12+ if ( mdrc . filePath === filePath ) {
13+ console . debug ( `meta-bind | MDRCManager >> unregistered MDRC ${ mdrc . uuid } ` ) ;
14+ mdrc . unload ( ) ;
15+ }
16+ }
17+ }
18+
1019 unload ( ) : void {
1120 for ( const mdrc of this . activeMDRCs . values ( ) ) {
1221 console . debug ( `meta-bind | MDRCManager >> unregistered MDRC ${ mdrc . uuid } ` ) ;
Original file line number Diff line number Diff line change @@ -82,6 +82,20 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
8282 const metadataAdapter = new ObsidianMetadataAdapter ( this ) ;
8383 this . metadataManager = new MetadataManager ( metadataAdapter ) ;
8484
85+ this . registerEvent (
86+ this . app . vault . on ( 'rename' , ( _file , oldPath ) => {
87+ this . mdrcManager . unloadFile ( oldPath ) ;
88+ metadataAdapter . onFileRename ( oldPath ) ;
89+ } ) ,
90+ ) ;
91+
92+ this . registerEvent (
93+ this . app . vault . on ( 'delete' , file => {
94+ this . mdrcManager . unloadFile ( file . path ) ;
95+ metadataAdapter . onFileDelete ( file . path ) ;
96+ } ) ,
97+ ) ;
98+
8599 this . loadTemplates ( ) ;
86100
87101 // register all post processors for MDRCs
Original file line number Diff line number Diff line change @@ -71,23 +71,19 @@ export class ObsidianMetadataAdapter implements IMetadataAdapter {
7171 } ) ,
7272 ) ;
7373
74- this . plugin . registerEvent (
75- this . plugin . app . vault . on ( 'delete' , file => {
76- this . manager ?. deleteCacheInstantly ( file . path ) ;
77- } ) ,
78- ) ;
79-
80- this . plugin . registerEvent (
81- this . plugin . app . vault . on ( 'rename' , ( _ , oldPath ) => {
82- this . manager ?. deleteCacheInstantly ( oldPath ) ;
83- } ) ,
84- ) ;
85-
8674 if ( this . manager !== undefined ) {
8775 this . interval = window . setInterval ( ( ) => this . manager ?. cycle ( ) , this . plugin . settings . syncInterval ) ;
8876 }
8977 }
9078
79+ public onFileRename ( oldPath : string ) : void {
80+ this . manager ?. deleteCacheInstantly ( oldPath ) ;
81+ }
82+
83+ public onFileDelete ( path : string ) : void {
84+ this . manager ?. deleteCacheInstantly ( path ) ;
85+ }
86+
9187 public unload ( ) : void {
9288 if ( this . interval !== undefined ) {
9389 window . clearInterval ( this . interval ) ;
You can’t perform that action at this time.
0 commit comments