diff --git a/src/custom-sort/custom-sort.ts b/src/custom-sort/custom-sort.ts index 378528d..7ce7a87 100644 --- a/src/custom-sort/custom-sort.ts +++ b/src/custom-sort/custom-sort.ts @@ -33,21 +33,6 @@ let CollatorTrueAlphabeticalCompare = new Intl.Collator(undefined, { numeric: false, }).compare; - -export const SORTSPEC_FOR_AUTOMATIC_BOOKMARKS_INTEGRATION: CustomSortSpec = { - defaultOrder: CustomSortOrder.byBookmarkOrder, - groups: [ - { - order: CustomSortOrder.byBookmarkOrder, - type: CustomSortGroupType.Outsiders - } - ], - outsidersGroupIdx: 0, - targetFoldersPaths: [ - "Spec applied automatically to folder not having explicit spec when automatic integration with bookmarks is enabled" - ] -} - export interface FolderItemForSorting { path: string groupIdx?: number // the index itself represents order for groups diff --git a/src/custom-sort/sorting-spec-processor.spec.ts b/src/custom-sort/sorting-spec-processor.spec.ts index cbfcc8b..7d27669 100644 --- a/src/custom-sort/sorting-spec-processor.spec.ts +++ b/src/custom-sort/sorting-spec-processor.spec.ts @@ -1706,6 +1706,11 @@ const txtInputErrorPriorityEmptyPattern: string = ` ` const txtInputEmptySpec: string = `` +const txtInputOnlyCommentsSpec: string = ` +// Some comment + +// Another comment below empty line +` describe('SortingSpecProcessor error detection and reporting', () => { let processor: SortingSpecProcessor; @@ -1942,7 +1947,7 @@ describe('SortingSpecProcessor error detection and reporting', () => { `${ERR_PREFIX} 22:PriorityPrefixAfterGroupTypePrefix Priority prefix must be used before sorting group type indicator ${ERR_SUFFIX_IN_LINE(2)}`) expect(errorsLogger).toHaveBeenNthCalledWith(2, ERR_LINE_TXT('/folders /+ /! Hello')) }) - it('should recognize error: combine prefix after sorting group type prefixe', () => { + it('should recognize error: combine prefix after sorting group type prefix', () => { const inputTxtArr: Array = ` /folders /+ Hello `.replace(/\t/gi, '').split('\n') @@ -1959,6 +1964,12 @@ describe('SortingSpecProcessor error detection and reporting', () => { expect(result).toBeNull() expect(errorsLogger).toHaveBeenCalledTimes(0) }) + it('should recognize empty spec', () => { + const inputTxtArr: Array = txtInputOnlyCommentsSpec.split('\n') + const result = processor.parseSortSpecFromText(inputTxtArr, 'mock-folder', 'custom-name-note.md') + expect(result).toBeNull() + expect(errorsLogger).toHaveBeenCalledTimes(0) + }) it.each([ '% \\.d+...', '% ...\\d+', diff --git a/src/main.ts b/src/main.ts index d370284..2118215 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,8 +2,8 @@ import { App, FileExplorerView, MetadataCache, - Notice, normalizePath, + Notice, Platform, Plugin, PluginSettingTab, @@ -16,7 +16,7 @@ import { Vault } from 'obsidian'; import {around} from 'monkey-around'; -import {folderSort, SORTSPEC_FOR_AUTOMATIC_BOOKMARKS_INTEGRATION} from './custom-sort/custom-sort'; +import {folderSort} from './custom-sort/custom-sort'; import {SortingSpecProcessor, SortSpecsCollection} from './custom-sort/sorting-spec-processor'; import {CustomSortOrder, CustomSortSpec} from './custom-sort/custom-sort-types'; @@ -82,6 +82,17 @@ export default class CustomSortPlugin extends Plugin { this.sortSpecCache = null const processor: SortingSpecProcessor = new SortingSpecProcessor() + if (this.settings.enableAutomaticBookmarksOrderIntegration) { + this.sortSpecCache = processor.parseSortSpecFromText( + 'target-folder: /*\n< by-bookmarks-order'.split('\n'), + 'System internal path', // Dummy unused value, there are no errors in the internal spec + 'System internal file', // Dummy unused value, there are no errors in the internal spec + this.sortSpecCache + ) + console.log('Auto injected sort spec') + console.log(this.sortSpecCache) + } + Vault.recurseChildren(this.app.vault.getRoot(), (file: TAbstractFile) => { if (failed) return if (file instanceof TFile) { @@ -349,9 +360,6 @@ export default class CustomSortPlugin extends Plugin { sortSpec = null // A folder is explicitly excluded from custom sorting plugin } } - if (!sortSpec && plugin.settings.enableAutomaticBookmarksOrderIntegration) { - sortSpec = SORTSPEC_FOR_AUTOMATIC_BOOKMARKS_INTEGRATION - } if (sortSpec) { sortSpec.plugin = plugin return folderSort.call(this, sortSpec, ...args);