@@ -232,7 +232,6 @@ export default class CustomSortPlugin extends Plugin {
232232 if ( this . sortSpecCache ) {
233233 if ( fileExplorerView ) {
234234 this . showNotice ( 'Custom sort ON' ) ;
235- this . initialAutoOrManualSortingTriggered = true
236235 iconToSet = ICON_SORT_ENABLED_ACTIVE
237236 } else {
238237 this . showNotice ( 'Custom sort GENERAL PROBLEM. See console for detailed message.' ) ;
@@ -256,6 +255,7 @@ export default class CustomSortPlugin extends Plugin {
256255 if ( fileExplorerView ) {
257256 if ( this . fileExplorerFolderPatched ) {
258257 fileExplorerView . requestSort ( ) ;
258+ this . initialAutoOrManualSortingTriggered = true
259259 }
260260 } else {
261261 if ( iconToSet === ICON_SORT_ENABLED_ACTIVE ) {
@@ -326,14 +326,23 @@ export default class CustomSortPlugin extends Plugin {
326326 if ( ! this . settings . suspended ) {
327327 if ( ! this . initialAutoOrManualSortingTriggered ) {
328328 this . readAndParseSortingSpec ( )
329- this . initialAutoOrManualSortingTriggered = true
330329 if ( this . sortSpecCache ) { // successful read of sorting specifications?
331330 this . showNotice ( 'Custom sort ON' )
332- const fileExplorerView : FileExplorerView | undefined = this . checkFileExplorerIsAvailableAndPatchable ( false )
331+ let fileExplorerView : FileExplorerView | undefined = this . checkFileExplorerIsAvailableAndPatchable ( false )
332+ if ( fileExplorerView && ! this . fileExplorerFolderPatched ) {
333+ this . fileExplorerFolderPatched = this . patchFileExplorerFolder ( fileExplorerView ) ;
334+
335+ if ( ! this . fileExplorerFolderPatched ) {
336+ fileExplorerView = undefined
337+ }
338+ }
333339 if ( fileExplorerView ) {
334340 setIcon ( this . ribbonIconEl , ICON_SORT_ENABLED_ACTIVE )
335341 fileExplorerView . requestSort ( )
342+ this . initialAutoOrManualSortingTriggered = true
336343 } else {
344+ // Remark: in this case the File Explorer will render later on with standard Obsidian sort
345+ // and a different event will be responsible for patching it and applying the custom sort
337346 setIcon ( this . ribbonIconEl , ICON_SORT_ENABLED_NOT_APPLIED )
338347 plugin . ribbonIconStateInaccurate = true
339348 }
0 commit comments