From 779f8738a2c70b6b3122c15e007deabb5c7a737a Mon Sep 17 00:00:00 2001 From: SebastianMC <23032356+SebastianMC@users.noreply.github.com> Date: Fri, 3 Jan 2025 13:07:31 +0100 Subject: [PATCH 1/2] 185 - drop backward compatibility - removed integration with Starred code plugin (which hasn't already been there for months) --- src/custom-sort/custom-sort-types.ts | 1 - src/custom-sort/custom-sort-utils.ts | 8 +- src/custom-sort/custom-sort.ts | 13 -- src/custom-sort/sorting-spec-processor.ts | 9 - src/main.ts | 2 - src/test/unit/custom-sort-utils.spec.ts | 1 - src/test/unit/custom-sort.spec.ts | 163 +++---------------- src/test/unit/sorting-spec-processor.spec.ts | 18 +- src/utils/StarredPluginSignature.ts | 43 ----- 9 files changed, 30 insertions(+), 228 deletions(-) delete mode 100644 src/utils/StarredPluginSignature.ts diff --git a/src/custom-sort/custom-sort-types.ts b/src/custom-sort/custom-sort-types.ts index 678b432..1908071 100644 --- a/src/custom-sort/custom-sort-types.ts +++ b/src/custom-sort/custom-sort-types.ts @@ -6,7 +6,6 @@ export enum CustomSortGroupType { ExactSuffix, ExactHeadAndTail, // Like W...n or Un...ed, which is shorter variant of typing the entire title HasMetadataField, // Notes (or folder's notes) containing a specific metadata field - StarredOnly, BookmarkedOnly, HasIcon } diff --git a/src/custom-sort/custom-sort-utils.ts b/src/custom-sort/custom-sort-utils.ts index e3f0ed0..e2ee872 100644 --- a/src/custom-sort/custom-sort-utils.ts +++ b/src/custom-sort/custom-sort-utils.ts @@ -16,7 +16,6 @@ export interface HasSortingTypes { export interface HasGroupingTypes { byBookmarks: number - byStarred: number byIcon: number total: number } @@ -31,10 +30,6 @@ export const checkByBookmark = (has: HasSortingOrGrouping, order?: CustomSortOrd (order === CustomSortOrder.byBookmarkOrder || order === CustomSortOrder.byBookmarkOrderReverse) && has.sorting.byBookmarks++; } -export const checkByStarred = (has: HasSortingOrGrouping, order?: CustomSortOrder, groupType?: CustomSortGroupType ) => { - groupType === CustomSortGroupType.StarredOnly && has.grouping.byStarred++; -} - export const checkByIcon = (has: HasSortingOrGrouping, order?: CustomSortOrder, groupType?: CustomSortGroupType ) => { groupType === CustomSortGroupType.HasIcon && has.grouping.byIcon++; } @@ -45,7 +40,6 @@ export const checkStandardObsidian = (has: HasSortingOrGrouping, order?: CustomS export const doCheck = (has: HasSortingOrGrouping, order?: CustomSortOrder, groupType?: CustomSortGroupType) => { checkByBookmark(has, order, groupType) - checkByStarred(has, order, groupType) checkByIcon(has, order, groupType) checkStandardObsidian(has, order, groupType) @@ -56,7 +50,7 @@ export const doCheck = (has: HasSortingOrGrouping, order?: CustomSortOrder, grou export const collectSortingAndGroupingTypes = (sortSpec?: CustomSortSpec|null): HasSortingOrGrouping => { const has: HasSortingOrGrouping = { grouping: { - byIcon: 0, byStarred: 0, byBookmarks: 0, total: 0 + byIcon: 0, byBookmarks: 0, total: 0 }, sorting: { byBookmarks: 0, standardObsidian: 0, total: 0 diff --git a/src/custom-sort/custom-sort.ts b/src/custom-sort/custom-sort.ts index e906929..6b041e9 100644 --- a/src/custom-sort/custom-sort.ts +++ b/src/custom-sort/custom-sort.ts @@ -8,10 +8,6 @@ import { TFolder, Vault } from 'obsidian'; -import { - determineStarredStatusOf, - Starred_PluginInstance -} from '../utils/StarredPluginSignature'; import { determineIconOf, ObsidianIconFolder_PluginInstance @@ -40,7 +36,6 @@ export interface ProcessingContext { // For internal transient use plugin?: CustomSortPluginAPI // to hand over the access to App instance to the sorting engine _mCache?: MetadataCache - starredPluginInstance?: Starred_PluginInstance bookmarksPluginInstance?: BookmarksPluginInterface, iconFolderPluginInstance?: ObsidianIconFolder_PluginInstance } @@ -495,14 +490,6 @@ export const determineSortingGroup = function (entry: TFile | TFolder, spec: Cus } } break - case CustomSortGroupType.StarredOnly: - if (ctx?.starredPluginInstance) { - const starred: boolean = determineStarredStatusOf(entry, aFile, ctx.starredPluginInstance) - if (starred) { - determined = true - } - } - break case CustomSortGroupType.BookmarkedOnly: if (ctx?.bookmarksPluginInstance) { const bookmarkOrder: number | undefined = ctx?.bookmarksPluginInstance.determineBookmarkOrder(entry.path) diff --git a/src/custom-sort/sorting-spec-processor.ts b/src/custom-sort/sorting-spec-processor.ts index f7a4cf7..698e591 100644 --- a/src/custom-sort/sorting-spec-processor.ts +++ b/src/custom-sort/sorting-spec-processor.ts @@ -269,8 +269,6 @@ const MetadataFieldIndicatorLexeme: string = 'with-metadata:' const BookmarkedItemIndicatorLexeme: string = 'bookmarked:' -const StarredItemsIndicatorLexeme: string = 'starred:' - const IconIndicatorLexeme: string = 'with-icon:' const CommentPrefix: string = '//' @@ -1710,13 +1708,6 @@ export class SortingSpecProcessor { foldersOnly: spec.foldersOnly, matchFilenameWithExt: spec.matchFilenameWithExt } - } else if (theOnly.startsWith(StarredItemsIndicatorLexeme)) { - return { - type: CustomSortGroupType.StarredOnly, - filesOnly: spec.filesOnly, - foldersOnly: spec.foldersOnly, - matchFilenameWithExt: spec.matchFilenameWithExt - } } else { // For non-three dots single text line assume exact match group return { diff --git a/src/main.ts b/src/main.ts index 715a2e9..b6bad58 100644 --- a/src/main.ts +++ b/src/main.ts @@ -44,7 +44,6 @@ import { ICON_SORT_SUSPENDED_GENERAL_ERROR, ICON_SORT_SUSPENDED_SYNTAX_ERROR } from "./custom-sort/icons"; -import {getStarredPlugin} from "./utils/StarredPluginSignature"; import { BookmarksPluginInterface, getBookmarksPlugin, @@ -583,7 +582,6 @@ export default class CustomSortPlugin createProcessingContextForSorting(has: HasSortingOrGrouping): ProcessingContext { const ctx: ProcessingContext = { _mCache: this.app.metadataCache, - starredPluginInstance: has.grouping.byStarred ? getStarredPlugin(this.app) : undefined, bookmarksPluginInstance: has.grouping.byBookmarks || has.sorting.byBookmarks ? getBookmarksPlugin(this.app, this.settings.bookmarksGroupToConsumeAsOrderingReference, false, true) : undefined, iconFolderPluginInstance: has.grouping.byIcon ? getIconFolderPlugin(this.app) : undefined, plugin: this diff --git a/src/test/unit/custom-sort-utils.spec.ts b/src/test/unit/custom-sort-utils.spec.ts index 43e3e47..c8bbe15 100644 --- a/src/test/unit/custom-sort-utils.spec.ts +++ b/src/test/unit/custom-sort-utils.spec.ts @@ -18,7 +18,6 @@ const getHas = (gTotal?: NM, gBkmrk?: NM, gStar?: NM, gIcon?: NM, sTot?: NM, sBk grouping: { total: gTotal ||0, byBookmarks: gBkmrk ||0, - byStarred: gStar ||0, byIcon: gIcon ||0 }, sorting: { diff --git a/src/test/unit/custom-sort.spec.ts b/src/test/unit/custom-sort.spec.ts index abdc780..af8aff5 100644 --- a/src/test/unit/custom-sort.spec.ts +++ b/src/test/unit/custom-sort.spec.ts @@ -1,7 +1,7 @@ import { CachedMetadata, MetadataCache, - Pos, + Pos, TAbstractFile, TFile, TFolder, Vault @@ -36,9 +36,8 @@ import { CompoundDotRomanNumberNormalizerFn } from "../../custom-sort/sorting-spec-processor"; import { - findStarredFile_pathParam, - Starred_PluginInstance -} from "../../utils/StarredPluginSignature"; + BookmarksPluginInterface +} from "../../utils/BookmarksCorePluginSignature"; import { ObsidianIconFolder_PluginInstance, ObsidianIconFolderPlugin_Data @@ -937,25 +936,25 @@ describe('determineSortingGroup', () => { } as FolderItemForSorting); }) }) - describe('CustomSortGroupType.StarredOnly', () => { - it('should not match not starred file', () => { + describe('CustomSortGroupType.BookmarkedOnly', () => { + it('should not match not bookmarked file', () => { // given const file: TFile = mockTFile('References', 'md', 111, MOCK_TIMESTAMP + 222, MOCK_TIMESTAMP + 333); const sortSpec: CustomSortSpec = { targetFoldersPaths: ['/'], groups: [{ - type: CustomSortGroupType.StarredOnly + type: CustomSortGroupType.BookmarkedOnly }] } - const starredPluginInstance: Partial = { - findStarredFile: jest.fn( function(filePath: findStarredFile_pathParam): TFile | null { - return null + const bookmarksPluginInstance: Partial = { + determineBookmarkOrder: jest.fn( function(path: string): number | undefined { + return undefined }) } // when const result = determineSortingGroup(file, sortSpec, { - starredPluginInstance: starredPluginInstance as Starred_PluginInstance + bookmarksPluginInstance: bookmarksPluginInstance as BookmarksPluginInterface } as ProcessingContext) // then @@ -968,30 +967,32 @@ describe('determineSortingGroup', () => { mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' }); - expect(starredPluginInstance.findStarredFile).toHaveBeenCalledTimes(1) + expect(bookmarksPluginInstance.determineBookmarkOrder).toHaveBeenCalledTimes(1) }) - it('should match starred file', () => { + it('should match bookmarked file', () => { // given const file: TFile = mockTFile('References', 'md', 111, MOCK_TIMESTAMP + 222, MOCK_TIMESTAMP + 333); const sortSpec: CustomSortSpec = { targetFoldersPaths: ['/'], groups: [{ - type: CustomSortGroupType.StarredOnly + type: CustomSortGroupType.BookmarkedOnly }] } - const starredPluginInstance: Partial = { - findStarredFile: jest.fn( function(filePath: findStarredFile_pathParam): TFile | null { - return filePath.path === 'Some parent folder/References.md' ? file : null + const BOOKMARK_ORDER = 123 + const bookmarksPluginInstance: Partial = { + determineBookmarkOrder: jest.fn( function(path: string): number | undefined { + return path === 'Some parent folder/References.md' ? BOOKMARK_ORDER : undefined }) } // when const result = determineSortingGroup(file, sortSpec, { - starredPluginInstance: starredPluginInstance as Starred_PluginInstance + bookmarksPluginInstance: bookmarksPluginInstance as BookmarksPluginInterface } as ProcessingContext) // then expect(result).toEqual({ + bookmarkedIdx: BOOKMARK_ORDER, groupIdx: 0, isFolder: false, sortString: "References", @@ -1000,131 +1001,7 @@ describe('determineSortingGroup', () => { mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' }); - expect(starredPluginInstance.findStarredFile).toHaveBeenCalledTimes(1) - }) - it('should not match empty folder', () => { - // given - const folder: TFolder = mockTFolder('TestEmptyFolder'); - const sortSpec: CustomSortSpec = { - targetFoldersPaths: ['/'], - groups: [{ - type: CustomSortGroupType.StarredOnly - }] - } - const starredPluginInstance: Partial = { - findStarredFile: jest.fn( function(filePath: findStarredFile_pathParam): TFile | null { - return filePath.path === 'Some parent folder/References.md' ? {} as TFile : null - }) - } - - // when - const result = determineSortingGroup(folder, sortSpec, { - starredPluginInstance: starredPluginInstance as Starred_PluginInstance - } as ProcessingContext) - - // then - expect(result).toEqual({ - groupIdx: 1, // The lastIdx+1, group not determined - isFolder: true, - sortString: "TestEmptyFolder", - sortStringWithExt: "TestEmptyFolder", - - ctime: 0, - mtime: 0, - path: 'TestEmptyFolder', - folder: { - children: [], - isRoot: expect.any(Function), - name: "TestEmptyFolder", - parent: {}, - path: "TestEmptyFolder", - vault: {} - } - }); - expect(starredPluginInstance.findStarredFile).not.toHaveBeenCalled() - }) - it('should not match folder w/o starred items', () => { - // given - const folder: TFolder = mockTFolderWithChildren('TestEmptyFolder'); - const sortSpec: CustomSortSpec = { - targetFoldersPaths: ['/'], - groups: [{ - type: CustomSortGroupType.StarredOnly - }] - } - const starredPluginInstance: Partial = { - findStarredFile: jest.fn( function(filePath: findStarredFile_pathParam): TFile | null { - return filePath.path === 'Some parent folder/References.md' ? {} as TFile : null - }) - } - - // when - const result = determineSortingGroup(folder, sortSpec, { - starredPluginInstance: starredPluginInstance as Starred_PluginInstance - } as ProcessingContext) - - // then - expect(result).toEqual({ - groupIdx: 1, // The lastIdx+1, group not determined - isFolder: true, - sortString: "TestEmptyFolder", - sortStringWithExt: "TestEmptyFolder", - - ctime: 0, - mtime: 0, - path: 'TestEmptyFolder', - folder: { - children: expect.any(Array), - isRoot: expect.any(Function), - name: "TestEmptyFolder", - parent: {}, - path: "TestEmptyFolder", - vault: {} - } - }); - expect(starredPluginInstance.findStarredFile).toHaveBeenCalledTimes(folder.children.filter(f => (f as any).isRoot === undefined).length) - }) - it('should match folder with one starred item', () => { - // given - const folder: TFolder = mockTFolderWithChildren('TestEmptyFolder'); - const sortSpec: CustomSortSpec = { - targetFoldersPaths: ['/'], - groups: [{ - type: CustomSortGroupType.StarredOnly - }] - } - const starredPluginInstance: Partial = { - findStarredFile: jest.fn(function (filePath: findStarredFile_pathParam): TFile | null { - return filePath.path === 'Some parent folder/Child file 2 created as newest, not modified at all.md' ? {} as TFile : null - }) - } - - // when - const result = determineSortingGroup(folder, sortSpec, { - starredPluginInstance: starredPluginInstance as Starred_PluginInstance - } as ProcessingContext) - - // then - expect(result).toEqual({ - groupIdx: 0, - isFolder: true, - sortString: "TestEmptyFolder", - sortStringWithExt: "TestEmptyFolder", - - ctime: 0, - mtime: 0, - path: 'TestEmptyFolder', - folder: { - children: expect.any(Array), - isRoot: expect.any(Function), - name: "TestEmptyFolder", - parent: {}, - path: "TestEmptyFolder", - vault: {} - } - }); - // assume optimized checking of starred items -> first match ends the check - expect(starredPluginInstance.findStarredFile).toHaveBeenCalledTimes(2) + expect(bookmarksPluginInstance.determineBookmarkOrder).toHaveBeenCalledTimes(1) }) }) describe('CustomSortGroupType.HasIcon', () => { diff --git a/src/test/unit/sorting-spec-processor.spec.ts b/src/test/unit/sorting-spec-processor.spec.ts index c3e66dc..7db5d1f 100644 --- a/src/test/unit/sorting-spec-processor.spec.ts +++ b/src/test/unit/sorting-spec-processor.spec.ts @@ -35,9 +35,9 @@ with-metadata: Pages > a-z by-metadata: /: with-icon: with-icon: RiClock24 -starred: -/:files starred: -/folders starred: +bookmarked: +/:files bookmarked: +/folders bookmarked: :::: folder of bookmarks < by-bookmarks-order @@ -100,9 +100,9 @@ target-folder: tricky folder 2 > a-z by-metadata: /:files with-icon: /folders:files with-icon: RiClock24 -/folders:files starred: -/:files starred: -/folders starred: +/folders:files bookmarked: +/:files bookmarked: +/folders bookmarked: target-folder: folder of bookmarks order-asc: by-bookmarks-order @@ -195,12 +195,12 @@ const expectedSortSpecsExampleA: { [key: string]: CustomSortSpec } = { type: CustomSortGroupType.HasIcon, iconName: 'RiClock24' }, { - type: CustomSortGroupType.StarredOnly + type: CustomSortGroupType.BookmarkedOnly }, { - type: CustomSortGroupType.StarredOnly, + type: CustomSortGroupType.BookmarkedOnly, filesOnly: true }, { - type: CustomSortGroupType.StarredOnly, + type: CustomSortGroupType.BookmarkedOnly, foldersOnly: true }, { type: CustomSortGroupType.Outsiders diff --git a/src/utils/StarredPluginSignature.ts b/src/utils/StarredPluginSignature.ts deleted file mode 100644 index 10aa46c..0000000 --- a/src/utils/StarredPluginSignature.ts +++ /dev/null @@ -1,43 +0,0 @@ -import {App, InstalledPlugin, PluginInstance, TAbstractFile, TFile, TFolder} from "obsidian"; - -export const StarredPlugin_findStarredFile_methodName = 'findStarredFile' - -export interface findStarredFile_pathParam { - path: string -} - -export interface Starred_PluginInstance extends PluginInstance { - [StarredPlugin_findStarredFile_methodName]: (filePath: findStarredFile_pathParam) => TFile | null -} - -export const StarredCorePluginId: string = 'starred' - -export const getStarredPlugin = (app: App): Starred_PluginInstance | undefined => { - const starredPlugin: InstalledPlugin | undefined = app?.internalPlugins?.getPluginById(StarredCorePluginId) - if (starredPlugin && starredPlugin.enabled && starredPlugin.instance) { - const starredPluginInstance: Starred_PluginInstance = starredPlugin.instance as Starred_PluginInstance - // defensive programming, in case Obsidian changes its internal APIs - if (typeof starredPluginInstance?.[StarredPlugin_findStarredFile_methodName] === 'function') { - return starredPluginInstance - } - } -} - -const isFolder = (entry: TAbstractFile) => { - // The plain obvious 'entry instanceof TFolder' doesn't work inside Jest unit tests, hence a workaround below - return !!((entry as any).isRoot); -} - -export const determineStarredStatusOfFolder = (folder: TFolder, starredPluginInstance: Starred_PluginInstance): boolean => { - return folder.children.some((folderItem) => { - return !isFolder(folderItem) && starredPluginInstance[StarredPlugin_findStarredFile_methodName]({path: folderItem.path}) - }) -} - -export const determineStarredStatusOf = (entry: TFile | TFolder, aFile: boolean, starredPluginInstance: Starred_PluginInstance) => { - if (aFile) { - return !!starredPluginInstance[StarredPlugin_findStarredFile_methodName]({path: entry.path}) - } else { // aFolder - return determineStarredStatusOfFolder(entry as TFolder, starredPluginInstance) - } -} From d07c61290af84f07400fbf17d10f1fa591617f0b Mon Sep 17 00:00:00 2001 From: SebastianMC <23032356+SebastianMC@users.noreply.github.com> Date: Fri, 3 Jan 2025 13:22:02 +0100 Subject: [PATCH 2/2] 185 - drop backward compatibility - removed legacy code to handle backward compatibility with <0.15.0, <1.2.0, <1.4.11 and <1.6.0 --- src/custom-sort/custom-sort.ts | 26 +----- src/main.ts | 164 ++++++++++++--------------------- src/types/types.d.ts | 1 - 3 files changed, 60 insertions(+), 131 deletions(-) diff --git a/src/custom-sort/custom-sort.ts b/src/custom-sort/custom-sort.ts index 6b041e9..c249af7 100644 --- a/src/custom-sort/custom-sort.ts +++ b/src/custom-sort/custom-sort.ts @@ -1,8 +1,6 @@ import { FrontMatterCache, MetadataCache, - Plugin, - requireApiVersion, TAbstractFile, TFile, TFolder, @@ -719,28 +717,8 @@ export const determineBookmarksOrderIfNeeded = (folderItems: Array { - if (!this.settings.customSortContextSubmenu) return; // Don't show the context menus at all + this.registerEvent( + // "files-menu" event was exposed in 1.4.11 + // @ts-ignore + this.app.workspace.on("files-menu", (menu: Menu, files: TAbstractFile[], source: string, leaf?: WorkspaceLeaf) => { + if (!this.settings.customSortContextSubmenu) return; // Don't show the context menus at all - const customSortMenuItem = (item?: MenuItem) => { - // if parameter is empty it means mobile invocation, where submenus are not supported. - // In that case flatten the menu. - let submenu: Menu|undefined - if (item) { - item.setTitle('Custom sort:'); - item.setIcon('hashtag'); - submenu = item.setSubmenu() - } - if (!submenu) menu.addSeparator(); - (submenu ?? menu).addItem(applyCustomSortMenuItem) - if (submenu) submenu.addSeparator(); - - if (this.settings.bookmarksContextMenus) { - const bookmarksPlugin = getBookmarksPlugin(plugin.app, plugin.settings.bookmarksGroupToConsumeAsOrderingReference) - if (bookmarksPlugin) { - (submenu ?? menu).addItem(getBookmarkSelectedMenuItemForFiles(files)); - (submenu ?? menu).addItem(getUnbookmarkSelectedMenuItemForFiles(files)); - } - } - (submenu ?? menu).addItem(suspendCustomSortMenuItem); - }; - - if (m) { - customSortMenuItem(undefined) - } else { - menu.addItem(customSortMenuItem) + const customSortMenuItem = (item?: MenuItem) => { + // if parameter is empty it means mobile invocation, where submenus are not supported. + // In that case flatten the menu. + let submenu: Menu|undefined + if (item) { + item.setTitle('Custom sort:'); + item.setIcon('hashtag'); + submenu = item.setSubmenu() } - }) - ) - } + if (!submenu) menu.addSeparator(); + (submenu ?? menu).addItem(applyCustomSortMenuItem) + if (submenu) submenu.addSeparator(); + + if (this.settings.bookmarksContextMenus) { + const bookmarksPlugin = getBookmarksPlugin(plugin.app, plugin.settings.bookmarksGroupToConsumeAsOrderingReference) + if (bookmarksPlugin) { + (submenu ?? menu).addItem(getBookmarkSelectedMenuItemForFiles(files)); + (submenu ?? menu).addItem(getUnbookmarkSelectedMenuItemForFiles(files)); + } + } + (submenu ?? menu).addItem(suspendCustomSortMenuItem); + }; + + if (m) { + customSortMenuItem(undefined) + } else { + menu.addItem(customSortMenuItem) + } + }) + ) this.registerEvent( this.app.vault.on("rename", (file: TAbstractFile, oldPath: string) => { @@ -633,60 +616,29 @@ export default class CustomSortPlugin // That's why not showing and not logging error message here patchableFileExplorer = patchableFileExplorer ?? this.checkFileExplorerIsAvailableAndPatchable(false) if (patchableFileExplorer) { - if (requireApiVersion && requireApiVersion("1.6.0")) { - // Starting from Obsidian 1.6.0 the sorting mechanics has been significantly refactored internally in Obsidian - const uninstallerOfFolderSortFunctionWrapper: MonkeyAroundUninstaller = around(patchableFileExplorer.constructor.prototype, { - getSortedFolderItems(old: any) { - return function (...args: any[]) { - // quick check for plugin status - if (plugin.settings.suspended) { - return old.call(this, ...args); - } + const uninstallerOfFolderSortFunctionWrapper: MonkeyAroundUninstaller = around(patchableFileExplorer.constructor.prototype, { + getSortedFolderItems(old: any) { + return function (...args: any[]) { + // quick check for plugin status + if (plugin.settings.suspended) { + return old.call(this, ...args); + } - plugin.resetIconInaccurateStateToEnabled() + plugin.resetIconInaccurateStateToEnabled() - const folder = args[0] - const sortingData = plugin.determineAndPrepareSortingDataForFolder(folder) + const folder = args[0] + const sortingData = plugin.determineAndPrepareSortingDataForFolder(folder) - if (sortingData.sortSpec) { - return getSortedFolderItems_vFrom_1_6_0.call(this, folder, sortingData.sortSpec, plugin.createProcessingContextForSorting(sortingData.sortingAndGroupingStats)) - } else { - return old.call(this, ...args); - } - }; - } - }) - this.register(requestStandardObsidianSortAfter(uninstallerOfFolderSortFunctionWrapper)) - return true - } else { - // Up to Obsidian 1.6.0 - // @ts-ignore - let tmpFolder = new TFolder(Vault, ""); - let Folder = patchableFileExplorer.createFolderDom(tmpFolder).constructor; - const uninstallerOfFolderSortFunctionWrapper: MonkeyAroundUninstaller = around(Folder.prototype, { - sort(old: any) { - return function (...args: any[]) { - // quick check for plugin status - if (plugin.settings.suspended) { - return old.call(this, ...args); - } - - plugin.resetIconInaccurateStateToEnabled() - - const folder: TFolder = this.file - const sortingData = plugin.determineAndPrepareSortingDataForFolder(folder) - - if (sortingData.sortSpec) { - return folderSort_vUpTo_1_6_0.call(this, sortingData.sortSpec, plugin.createProcessingContextForSorting(sortingData.sortingAndGroupingStats)); - } else { - return old.call(this, ...args); - } - }; - } - }) - this.register(requestStandardObsidianSortAfter(uninstallerOfFolderSortFunctionWrapper)) - return true - } + if (sortingData.sortSpec) { + return getSortedFolderItems.call(this, folder, sortingData.sortSpec, plugin.createProcessingContextForSorting(sortingData.sortingAndGroupingStats)) + } else { + return old.call(this, ...args); + } + }; + } + }) + this.register(requestStandardObsidianSortAfter(uninstallerOfFolderSortFunctionWrapper)) + return true } else { return false } @@ -730,7 +682,7 @@ export default class CustomSortPlugin const data: any = await this.loadData() || {} const isFreshInstall: boolean = Object.keys(data).length === 0 this.settings = Object.assign({}, DEFAULT_SETTINGS, data); - if (requireApiVersion('1.2.0') && isFreshInstall) { + if (isFreshInstall) { this.settings = Object.assign(this.settings, DEFAULT_SETTING_FOR_1_2_0_UP) } } diff --git a/src/types/types.d.ts b/src/types/types.d.ts index d6a52b0..6e9a2ee 100644 --- a/src/types/types.d.ts +++ b/src/types/types.d.ts @@ -50,7 +50,6 @@ declare module 'obsidian' { } export interface FileExplorerView extends View { - createFolderDom(folder: TFolder): FileExplorerFolder; getSortedFolderItems(sortedFolder: TFolder): any[]; requestSort(): void;