@@ -78,7 +78,7 @@ export default class CodeBlockCustomizerPlugin extends Plugin {
7878 tabStoreEditor : StateStore < string , number > = new StateStore ( false , String ) ;
7979 tabStoreReading : StateStore < string , number > = new StateStore ( false , String ) ;
8080 debounceTimer : number | null = null ;
81- foldCommandTrigger : FoldCommand = FoldCommand . Default ;
81+ foldCommandTrigger : { command : FoldCommand ; path : string } | null = null ;
8282 rerenderQueue : Map < number , { content : string ; count : number } > = new Map ( ) ;
8383 rerenderDebounceTimers : Map < number , NodeJS . Timeout > = new Map ( ) ;
8484 modifiedBlocks : Map < string , string > = new Map ( ) ;
@@ -152,7 +152,7 @@ export default class CodeBlockCustomizerPlugin extends Plugin {
152152 const markdownView = this . app . workspace . getActiveViewOfType ( MarkdownView ) ;
153153 if ( markdownView ) {
154154 const isGlobalCommandActive = ( markdownView . getMode ( ) === 'source' && markdownView . containerEl . classList . contains ( 'codeblock-customizer-header-collapse-command' ) ) ||
155- ( markdownView . getMode ( ) === 'preview' && this . foldCommandTrigger !== FoldCommand . Default ) ;
155+ ( markdownView . getMode ( ) === 'preview' && this . getFoldCommand ( filePath ) !== FoldCommand . Default ) ;
156156
157157 if ( isGlobalCommandActive ) {
158158 return ;
@@ -610,22 +610,30 @@ export default class CodeBlockCustomizerPlugin extends Plugin {
610610 renderReadingViews ( ) : void {
611611 this . app . workspace . iterateAllLeaves ( ( leaf : WorkspaceLeaf ) => {
612612 if ( leaf . view instanceof MarkdownView && leaf . view . getMode ( ) === "preview" ) {
613- const preview = leaf . view . previewMode ;
614- if ( ! preview || ! preview . getScroll || ! preview . applyScroll ) {
615- return ;
616- }
617-
618- const scrollState = preview . getScroll ( ) ;
619-
620- preview . rerender ( true ) ;
621-
622- window . setTimeout ( ( ) => {
623- preview . applyScroll ( scrollState ) ;
624- } , 100 ) ;
613+ this . renderReadingView ( leaf . view ) ;
625614 }
626615 } ) ;
627616 } // renderReadingViews
628617
618+ private renderReadingView ( view : MarkdownView ) : void {
619+ const preview = view . previewMode ;
620+ if ( ! preview || ! preview . getScroll || ! preview . applyScroll ) {
621+ return ;
622+ }
623+
624+ const scrollState = preview . getScroll ( ) ;
625+
626+ preview . rerender ( true ) ;
627+
628+ window . setTimeout ( ( ) => {
629+ preview . applyScroll ( scrollState ) ;
630+ } , 100 ) ;
631+ } // renderReadingView
632+
633+ getFoldCommand ( path : string ) : FoldCommand {
634+ return this . foldCommandTrigger ?. path === path ? this . foldCommandTrigger . command : FoldCommand . Default ;
635+ } // getFoldCommand
636+
629637 private executeFoldCommand ( func : ( view : EditorView ) => void , foldCommand : FoldCommand , action : 'add' | 'remove' ) : void {
630638 const markdownView = this . app . workspace . getActiveViewOfType ( MarkdownView ) ;
631639 if ( ! markdownView ) {
@@ -637,8 +645,9 @@ export default class CodeBlockCustomizerPlugin extends Plugin {
637645 if ( mode === 'source' ) {
638646 func ( ( markdownView . editor as Editor & { cm : EditorView } ) . cm ) ;
639647 } else if ( mode === 'preview' ) {
640- this . foldCommandTrigger = foldCommand ;
641- this . renderReadingViews ( ) ;
648+ const path = markdownView . file ?. path ;
649+ this . foldCommandTrigger = path ? { command : foldCommand , path } : null ;
650+ this . renderReadingView ( markdownView ) ;
642651 }
643652 } // executeFoldCommand
644653
@@ -778,9 +787,7 @@ export default class CodeBlockCustomizerPlugin extends Plugin {
778787 return ;
779788 }
780789 view . containerEl . classList . remove ( 'codeblock-customizer-header-collapse-command' ) ;
781- if ( this . foldCommandTrigger !== FoldCommand . Default ) {
782- this . foldCommandTrigger = FoldCommand . Default ;
783- }
790+ this . foldCommandTrigger = null ;
784791 } ) ) ;
785792 } // registerEvents
786793
0 commit comments