@@ -48,6 +48,8 @@ import { AlignBranch } from 'src/stores/view/subscriptions/effects/align-branch/
4848import { lang } from 'src/lang/lang' ;
4949import { logger } from 'src/helpers/logger' ;
5050import { DebouncedMinimapEffects } from 'src/stores/minimap/subscriptions/effects/debounced-minimap-effects' ;
51+ import { updateFrontmatter } from 'src/stores/view/subscriptions/actions/document/update-frontmatter' ;
52+ import { loadFullDocument } from 'src/stores/view/subscriptions/actions/document/load-full-document' ;
5153
5254export const LINEAGE_VIEW_TYPE = 'lineage' ;
5355
@@ -173,21 +175,6 @@ export class LineageView extends TextFileView {
173175
174176 async onOpen ( ) { }
175177
176- /*private destroyStore = () => {
177- const leavesOfType = this.plugin.app.workspace
178- .getLeavesOfType(FILE_VIEW_TYPE)
179- .filter(
180- (l) =>
181- l.view instanceof LineageView &&
182- l.view.file?.path === this.activeFilePath &&
183- l.view !== this,
184- );
185- if (leavesOfType.length === 0) {
186- this.store.dispatch({ type: 'RESET_STORE' });
187- if (this.file) delete stores[this.file.path];
188- }
189- };*/
190-
191178 async onClose ( ) {
192179 return this . onUnloadFile ( ) ;
193180 }
@@ -286,53 +273,43 @@ export class LineageView extends TextFileView {
286273 } ;
287274
288275 private loadDocumentToStore = ( isInitialLoad = false ) => {
289- const { data, frontmatter } = extractFrontmatter ( this . data ) ;
276+ const { body, frontmatter } = extractFrontmatter ( this . data ) ;
277+
278+ const documentState = this . documentStore . getValue ( ) ;
279+ const viewState = this . viewStore . getValue ( ) ;
280+ const documentFormat = getOrDetectDocumentFormat ( this , body ) ;
281+ const existingBody = isInitialLoad
282+ ? ''
283+ : stringifyDocument ( documentState . document , documentFormat ) ;
290284
291- const state = this . documentStore . getValue ( ) ;
292- const format = getOrDetectDocumentFormat ( this , data ) ;
293- const existingData = stringifyDocument ( state . document , format ) ;
294- const bodyHasChanged = existingData !== data ;
285+ const bodyHasChanged = existingBody !== body ;
295286 const frontmatterHasChanged =
296- ! bodyHasChanged && frontmatter !== state . file . frontmatter ;
297- if ( ! existingData || bodyHasChanged || frontmatterHasChanged ) {
298- const isEditing =
299- this . viewStore . getValue ( ) . document . editing . activeNodeId ;
300- if ( frontmatterHasChanged && ! isInitialLoad ) {
301- this . documentStore . dispatch ( {
302- type : 'FILE/UPDATE_FRONTMATTER' ,
303- payload : {
304- frontmatter,
305- } ,
306- } ) ;
307- } else if ( ! isEditing ) {
308- const activeNode =
309- this . viewStore . getValue ( ) . document . activeNode ;
310- const activeSection = activeNode
311- ? this . documentStore . getValue ( ) . sections . id_section [
312- activeNode
313- ]
314- : null ;
315- this . documentStore . dispatch ( {
316- payload : {
317- document : { data : data , frontmatter, position : null } ,
318- format,
319- activeSection,
320- } ,
321- type : 'DOCUMENT/LOAD_FILE' ,
322- } ) ;
323- if (
324- this . isActive &&
325- ! isInitialLoad &&
326- existingData &&
327- bodyHasChanged
328- ) {
329- new Notice ( 'Document changed externally' ) ;
330- }
331- if ( ! maybeGetDocumentFormat ( this ) ) {
332- invariant ( this . file ) ;
333- setDocumentFormat ( this . plugin , this . file . path , format ) ;
334- }
287+ frontmatter !== documentState . file . frontmatter ;
288+
289+ const isEditing = Boolean ( viewState . document . editing . activeNodeId ) ;
290+
291+ if ( isInitialLoad ) {
292+ loadFullDocument ( this , body , frontmatter , documentFormat , null ) ;
293+ if ( ! maybeGetDocumentFormat ( this ) ) {
294+ setDocumentFormat ( this . plugin , this . file ! . path , documentFormat ) ;
295+ }
296+ } else if ( bodyHasChanged && ! isEditing ) {
297+ const activeNode = viewState . document . activeNode ;
298+ const activeSection = activeNode
299+ ? documentState . sections . id_section [ activeNode ]
300+ : null ;
301+ loadFullDocument (
302+ this ,
303+ body ,
304+ frontmatter ,
305+ documentFormat ,
306+ activeSection ,
307+ ) ;
308+ if ( this . isActive && existingBody ) {
309+ new Notice ( 'Document changed externally' ) ;
335310 }
311+ } else if ( frontmatterHasChanged ) {
312+ updateFrontmatter ( this , frontmatter ) ;
336313 }
337314 } ;
338315
0 commit comments