From 3bc307c121b0c302f0455379d9ff0b95e2f55f12 Mon Sep 17 00:00:00 2001 From: SebastianMC <23032356+SebastianMC@users.noreply.github.com> Date: Mon, 10 Jun 2024 22:35:28 +0200 Subject: [PATCH] Bugifx for #147 --- src/main.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index e57e7cf..61b4de7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -232,7 +232,6 @@ export default class CustomSortPlugin extends Plugin { if (this.sortSpecCache) { if (fileExplorerView) { this.showNotice('Custom sort ON'); - this.initialAutoOrManualSortingTriggered = true iconToSet = ICON_SORT_ENABLED_ACTIVE } else { this.showNotice('Custom sort GENERAL PROBLEM. See console for detailed message.'); @@ -256,6 +255,7 @@ export default class CustomSortPlugin extends Plugin { if (fileExplorerView) { if (this.fileExplorerFolderPatched) { fileExplorerView.requestSort(); + this.initialAutoOrManualSortingTriggered = true } } else { if (iconToSet === ICON_SORT_ENABLED_ACTIVE) { @@ -326,14 +326,23 @@ export default class CustomSortPlugin extends Plugin { if (!this.settings.suspended) { if (!this.initialAutoOrManualSortingTriggered) { this.readAndParseSortingSpec() - this.initialAutoOrManualSortingTriggered = true if (this.sortSpecCache) { // successful read of sorting specifications? this.showNotice('Custom sort ON') - const fileExplorerView: FileExplorerView | undefined = this.checkFileExplorerIsAvailableAndPatchable(false) + let fileExplorerView: FileExplorerView | undefined = this.checkFileExplorerIsAvailableAndPatchable(false) + if (fileExplorerView && !this.fileExplorerFolderPatched) { + this.fileExplorerFolderPatched = this.patchFileExplorerFolder(fileExplorerView); + + if (!this.fileExplorerFolderPatched) { + fileExplorerView = undefined + } + } if (fileExplorerView) { setIcon(this.ribbonIconEl, ICON_SORT_ENABLED_ACTIVE) fileExplorerView.requestSort() + this.initialAutoOrManualSortingTriggered = true } else { + // Remark: in this case the File Explorer will render later on with standard Obsidian sort + // and a different event will be responsible for patching it and applying the custom sort setIcon(this.ribbonIconEl, ICON_SORT_ENABLED_NOT_APPLIED) plugin.ribbonIconStateInaccurate = true }