@@ -587,6 +587,32 @@ export default class CustomSortPlugin extends Plugin {
587587 return ctx
588588 }
589589
590+ resetIconInaccurateStateToEnabled ( ) {
591+ if ( this . ribbonIconStateInaccurate && this . ribbonIconEl ) {
592+ this . ribbonIconStateInaccurate = false
593+ setIcon ( this . ribbonIconEl , ICON_SORT_ENABLED_ACTIVE )
594+ }
595+ }
596+
597+ determineAndPrepareSortingDataForFolder ( folder : TFolder ) {
598+ let sortSpec : CustomSortSpec | null | undefined = this . determineSortSpecForFolder ( folder . path , folder . name )
599+
600+ // Performance optimization
601+ // Primary intention: when the implicit bookmarks integration is enabled, remain on std Obsidian, if no need to involve bookmarks
602+ let sortingAndGroupingStats : HasSortingOrGrouping = collectSortingAndGroupingTypes ( sortSpec )
603+ if ( hasOnlyByBookmarkOrStandardObsidian ( sortingAndGroupingStats ) ) {
604+ const bookmarksPlugin : BookmarksPluginInterface | undefined = getBookmarksPlugin ( this . app , this . settings . bookmarksGroupToConsumeAsOrderingReference , false , true )
605+ if ( ! bookmarksPlugin ?. bookmarksIncludeItemsInFolder ( folder . path ) ) {
606+ sortSpec = null
607+ }
608+ }
609+
610+ return {
611+ sortSpec : sortSpec ,
612+ sortingAndGroupingStats : sortingAndGroupingStats
613+ }
614+ }
615+
590616 // For the idea of monkey-patching credits go to https://github.com/nothingislost/obsidian-bartender
591617 patchFileExplorerFolder ( patchableFileExplorer ?: FileExplorerView ) : boolean {
592618 let plugin = this ;
@@ -604,26 +630,13 @@ export default class CustomSortPlugin extends Plugin {
604630 return old . call ( this , ...args ) ;
605631 }
606632
607- if ( plugin . ribbonIconStateInaccurate && plugin . ribbonIconEl ) {
608- plugin . ribbonIconStateInaccurate = false
609- setIcon ( plugin . ribbonIconEl , ICON_SORT_ENABLED_ACTIVE )
610- }
633+ plugin . resetIconInaccurateStateToEnabled ( )
611634
612635 const folder = args [ 0 ]
613- let sortSpec : CustomSortSpec | null | undefined = plugin . determineSortSpecForFolder ( folder . path , folder . name )
614-
615- // Performance optimization
616- // Primary intention: when the implicit bookmarks integration is enabled, remain on std Obsidian, if no need to involve bookmarks
617- let has : HasSortingOrGrouping = collectSortingAndGroupingTypes ( sortSpec )
618- if ( hasOnlyByBookmarkOrStandardObsidian ( has ) ) {
619- const bookmarksPlugin : BookmarksPluginInterface | undefined = getBookmarksPlugin ( plugin . app , plugin . settings . bookmarksGroupToConsumeAsOrderingReference , false , true )
620- if ( ! bookmarksPlugin ?. bookmarksIncludeItemsInFolder ( folder . path ) ) {
621- sortSpec = null
622- }
623- }
636+ const sortingData = plugin . determineAndPrepareSortingDataForFolder ( folder )
624637
625- if ( sortSpec ) {
626- return getSortedFolderItems_vFrom_1_6_0 . call ( this , folder , sortSpec , plugin . createProcessingContextForSorting ( has ) )
638+ if ( sortingData . sortSpec ) {
639+ return getSortedFolderItems_vFrom_1_6_0 . call ( this , folder , sortingData . sortSpec , plugin . createProcessingContextForSorting ( sortingData . sortingAndGroupingStats ) )
627640 } else {
628641 return old . call ( this , ...args ) ;
629642 }
@@ -645,26 +658,13 @@ export default class CustomSortPlugin extends Plugin {
645658 return old . call ( this , ...args ) ;
646659 }
647660
648- if ( plugin . ribbonIconStateInaccurate && plugin . ribbonIconEl ) {
649- plugin . ribbonIconStateInaccurate = false
650- setIcon ( plugin . ribbonIconEl , ICON_SORT_ENABLED_ACTIVE )
651- }
661+ plugin . resetIconInaccurateStateToEnabled ( )
652662
653663 const folder : TFolder = this . file
654- let sortSpec : CustomSortSpec | null | undefined = plugin . determineSortSpecForFolder ( folder . path , folder . name )
655-
656- // Performance optimization
657- // Primary intention: when the implicit bookmarks integration is enabled, remain on std Obsidian, if no need to involve bookmarks
658- let has : HasSortingOrGrouping = collectSortingAndGroupingTypes ( sortSpec )
659- if ( hasOnlyByBookmarkOrStandardObsidian ( has ) ) {
660- const bookmarksPlugin : BookmarksPluginInterface | undefined = getBookmarksPlugin ( plugin . app , plugin . settings . bookmarksGroupToConsumeAsOrderingReference , false , true )
661- if ( ! bookmarksPlugin ?. bookmarksIncludeItemsInFolder ( folder . path ) ) {
662- sortSpec = null
663- }
664- }
664+ const sortingData = plugin . determineAndPrepareSortingDataForFolder ( folder )
665665
666- if ( sortSpec ) {
667- return folderSort_vUpTo_1_6_0 . call ( this , sortSpec , plugin . createProcessingContextForSorting ( has ) ) ;
666+ if ( sortingData . sortSpec ) {
667+ return folderSort_vUpTo_1_6_0 . call ( this , sortingData . sortSpec , plugin . createProcessingContextForSorting ( sortingData . sortingAndGroupingStats ) ) ;
668668 } else {
669669 return old . call ( this , ...args ) ;
670670 }
0 commit comments