@@ -81,6 +81,10 @@ type MonkeyAroundUninstaller = () => void
8181
8282type ContextMenuProvider = ( item : MenuItem ) => void
8383
84+ const cl = ( executionPointName : string , comment ?: string ) => {
85+ console . log ( `c-s ep: (${ executionPointName } ) ${ comment ? comment : '' } ` )
86+ }
87+
8488export default class CustomSortPlugin
8589 extends Plugin
8690 implements CustomSortPluginAPI
@@ -105,6 +109,7 @@ export default class CustomSortPlugin
105109 }
106110
107111 readAndParseSortingSpec ( ) {
112+ cl ( 'd pre-1' , 'entered readAndParseSortingSpec()' )
108113 const mCache : MetadataCache = this . app . metadataCache
109114 let failed : boolean = false
110115 let anySortingSpecFound : boolean = false
@@ -167,28 +172,35 @@ export default class CustomSortPlugin
167172
168173 if ( this . sortSpecCache ) {
169174 this . showNotice ( `Parsing custom sorting specification SUCCEEDED!` )
175+ cl ( 'd' , 'notify: Parsing custom sorting specification SUCCEEDED!' )
170176 } else {
171177 if ( anySortingSpecFound ) {
172178 errorMessage = errorMessage ? errorMessage : `No valid '${ SORTINGSPEC_YAML_KEY } :' key(s) in YAML front matter or multiline YAML indentation error or general YAML syntax error`
173179 } else {
174180 errorMessage = `No custom sorting specification found or only empty specification(s)`
175181 }
182+ cl ( 'd' , 'failed' )
176183 this . showNotice ( `Parsing custom sorting specification FAILED. Suspending the plugin.\n${ errorMessage } ` , ERROR_NOTICE_TIMEOUT )
177184 this . settings . suspended = true
178185 this . saveSettings ( )
179186 }
180187 }
181188
182189 checkFileExplorerIsAvailableAndPatchable ( logWarning : boolean = true ) : FileExplorerView | undefined {
190+ cl ( 'a pre-1' , 'entered checkFileExplorerIsAvailableAndPatchable()' )
183191 let fileExplorerView : FileExplorerView | undefined = this . getFileExplorer ( )
192+ cl ( 'a pre-2' , `this.getFileExplorer ${ fileExplorerView ? 'ok' : 'undefined' } ` )
184193 if ( fileExplorerView && typeof fileExplorerView . requestSort === 'function' ) {
194+ cl ( 'a pre-3' , 'has requestSort()' )
185195 // The plugin integration points changed with Obsidian 1.6.0 hence the patchability-check should also be Obsidian version aware
186196 if ( requireApiVersion && requireApiVersion ( "1.6.0" ) ) {
187197 if ( typeof fileExplorerView . getSortedFolderItems === 'function' ) {
198+ cl ( 'a' , '1.6.0+ and has getSortedFolderItems()' )
188199 return fileExplorerView
189200 }
190201 } else { // Obsidian versions prior to 1.6.0
191202 if ( typeof fileExplorerView . createFolderDom === 'function' ) {
203+ cl ( 'a' , '<1.6.0 and has createFolderDom()' )
192204 return fileExplorerView
193205 }
194206 }
@@ -197,6 +209,7 @@ export default class CustomSortPlugin
197209 if ( logWarning ) {
198210 this . logWarningFileExplorerNotAvailable ( )
199211 }
212+ cl ( 'a' , 'failed' )
200213 return undefined
201214 }
202215
@@ -321,6 +334,7 @@ export default class CustomSortPlugin
321334 this . registerEvent (
322335 // Keep in mind: this event is triggered once after app starts and then after each modification of _any_ metadata
323336 plugin . app . metadataCache . on ( "resolved" , ( ) => {
337+ cl ( 'c' , 'app metadataCache populated by Obsidian' )
324338 if ( ! this . settings . suspended ) {
325339 if ( ! this . initialAutoOrManualSortingTriggered ) {
326340 this . readAndParseSortingSpec ( )
@@ -634,6 +648,8 @@ export default class CustomSortPlugin
634648 }
635649 }
636650
651+ cl ( 'b pre-1' , 'entered patchFileExplorerFolder()' )
652+
637653 // patching file explorer might fail here because of various non-error reasons.
638654 // That's why not showing and not logging error message here
639655 patchableFileExplorer = patchableFileExplorer ?? this . checkFileExplorerIsAvailableAndPatchable ( false )
@@ -642,7 +658,9 @@ export default class CustomSortPlugin
642658 // Starting from Obsidian 1.6.0 the sorting mechanics has been significantly refactored internally in Obsidian
643659 const uninstallerOfFolderSortFunctionWrapper : MonkeyAroundUninstaller = around ( patchableFileExplorer . constructor . prototype , {
644660 getSortedFolderItems ( old : any ) {
661+ cl ( 'f pre-1' , 'patched getSortedFolderItems factory!' )
645662 return function ( ...args : any [ ] ) {
663+ cl ( 'f' , 'patched getSortedFolderItems invoked!' )
646664 // quick check for plugin status
647665 if ( plugin . settings . suspended ) {
648666 return old . call ( this , ...args ) ;
@@ -662,6 +680,7 @@ export default class CustomSortPlugin
662680 }
663681 } )
664682 this . register ( requestStandardObsidianSortAfter ( uninstallerOfFolderSortFunctionWrapper ) )
683+ cl ( 'b' , '1.6.0+ and patched getSortedFolderItems()' )
665684 return true
666685 } else {
667686 // Up to Obsidian 1.6.0
@@ -670,7 +689,9 @@ export default class CustomSortPlugin
670689 let Folder = patchableFileExplorer . createFolderDom ( tmpFolder ) . constructor ;
671690 const uninstallerOfFolderSortFunctionWrapper : MonkeyAroundUninstaller = around ( Folder . prototype , {
672691 sort ( old : any ) {
692+ cl ( 'f pre-1' , 'patched sort factory!' )
673693 return function ( ...args : any [ ] ) {
694+ cl ( 'f' , 'patched sort invoked!' )
674695 // quick check for plugin status
675696 if ( plugin . settings . suspended ) {
676697 return old . call ( this , ...args ) ;
@@ -690,9 +711,11 @@ export default class CustomSortPlugin
690711 }
691712 } )
692713 this . register ( requestStandardObsidianSortAfter ( uninstallerOfFolderSortFunctionWrapper ) )
714+ cl ( 'b' , '<1.6.0 and patched sort() on Folder thanks to createFolderDom()' )
693715 return true
694716 }
695717 } else {
718+ cl ( 'b' , 'failed' )
696719 return false
697720 }
698721 }
0 commit comments