@@ -211,7 +211,7 @@ export class LineageView extends TextFileView {
211211 } else {
212212 this . createStore ( ) ;
213213 }
214- this . loadDocumentToStore ( true ) ;
214+ this . loadDocumentToStore ( ) ;
215215 if ( ! this . inlineEditor ) {
216216 this . inlineEditor = new InlineEditor ( this ) ;
217217 await this . inlineEditor . onload ( ) ;
@@ -250,15 +250,14 @@ export class LineageView extends TextFileView {
250250 ] . documentStore ;
251251 } ;
252252
253- private loadDocumentToStore = ( isInitialLoad = false ) => {
253+ private loadDocumentToStore = ( ) => {
254254 const { body, frontmatter } = extractFrontmatter ( this . data ) ;
255255
256256 const documentState = this . documentStore . getValue ( ) ;
257257 const viewState = this . viewStore . getValue ( ) ;
258+ const isEmptyStore = documentState . history . items . length === 0 ;
258259 const format = getOrDetectDocumentFormat ( this , body ) ;
259- const existingBody = isInitialLoad
260- ? ''
261- : stringifyDocument ( documentState . document , format ) ;
260+ const existingBody = stringifyDocument ( documentState . document , format ) ;
262261
263262 const bodyHasChanged = existingBody !== body ;
264263 const frontmatterHasChanged =
@@ -270,19 +269,17 @@ export class LineageView extends TextFileView {
270269 const activeSection = activeNode
271270 ? documentState . sections . id_section [ activeNode ]
272271 : null ;
273- if ( isInitialLoad ) {
272+ if ( bodyHasChanged && ! isEditing ) {
274273 loadFullDocument ( this , body , frontmatter , format , activeSection ) ;
275- if ( ! maybeGetDocumentFormat ( this ) ) {
276- setDocumentFormat ( this . plugin , this . file ! . path , format ) ;
277- }
278- } else if ( bodyHasChanged && ! isEditing ) {
279- loadFullDocument ( this , body , frontmatter , format , activeSection ) ;
280- if ( this . isActive && existingBody ) {
274+ if ( this . isActive && existingBody && ! isEmptyStore ) {
281275 new Notice ( 'Document changed externally' ) ;
282276 }
283277 } else if ( frontmatterHasChanged ) {
284278 updateFrontmatter ( this , frontmatter ) ;
285279 }
280+ if ( isEmptyStore && ! maybeGetDocumentFormat ( this ) ) {
281+ setDocumentFormat ( this . plugin , this . file ! . path , format ) ;
282+ }
286283 } ;
287284
288285 private debouncedLoadDocumentToStore = debounce (
0 commit comments