#74 - Integration with Bookmarks core plugin and support for indirect drag & drop arrangement

- added new plugin setting to enable auto-integration with bookmarks
- not reviewed
- not tested
- no unit tests coverage
This commit is contained in:
SebastianMC 2023-04-12 12:47:45 +02:00
parent 56348006ce
commit cc73b4d3f1
3 changed files with 25 additions and 21 deletions

View File

@ -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

View File

@ -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<string> = `
/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<string> = 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+',

View File

@ -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);