@@ -11,6 +11,26 @@ export default class PortalsCanvasExtension extends CanvasExtension {
1111 isEnabled ( ) { return 'portalsFeatureEnabled' as const }
1212
1313 init ( ) {
14+ this . plugin . registerEvent ( this . plugin . app . vault . on ( 'modify' , ( file : TFile ) => {
15+ const canvases = this . plugin . app . workspace . getLeavesOfType ( 'canvas' ) . map ( leaf => ( leaf . view as CanvasView ) . canvas )
16+
17+ for ( const canvas of canvases ) {
18+ const hasPortalsToFile = canvas . getData ( ) . nodes . filter ( nodeData =>
19+ nodeData . type === 'file' &&
20+ nodeData . portalToFile === file . path
21+ ) . length > 0
22+
23+ // Update whole canvas data
24+ if ( hasPortalsToFile ) {
25+ canvas . setData ( canvas . getData ( ) )
26+
27+ // Maintain history
28+ canvas . history . current --
29+ canvas . history . data . pop ( )
30+ }
31+ }
32+ } ) )
33+
1434 this . plugin . registerEvent ( this . plugin . app . workspace . on (
1535 CanvasEvent . PopupMenuCreated ,
1636 ( canvas : Canvas ) => this . updatePopupMenu ( canvas )
@@ -57,20 +77,6 @@ export default class PortalsCanvasExtension extends CanvasExtension {
5777 } )
5878 }
5979 ) )
60-
61- this . plugin . registerEvent ( this . plugin . app . vault . on ( 'modify' , ( file : TFile ) => {
62- const canvases = this . plugin . app . workspace . getLeavesOfType ( 'canvas' ) . map ( leaf => ( leaf . view as CanvasView ) . canvas )
63-
64- for ( const canvas of canvases ) {
65- const hasPortalsToFile = canvas . getData ( ) . nodes . filter ( nodeData =>
66- nodeData . type === 'file' &&
67- nodeData . portalToFile === file . path
68- ) . length > 0
69-
70- // Update whole canvas data
71- if ( hasPortalsToFile ) canvas . setData ( canvas . getData ( ) )
72- }
73- } ) )
7480 }
7581
7682 private updatePopupMenu ( canvas : Canvas ) {
0 commit comments