#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:
parent
56348006ce
commit
cc73b4d3f1
|
@ -33,21 +33,6 @@ let CollatorTrueAlphabeticalCompare = new Intl.Collator(undefined, {
|
||||||
numeric: false,
|
numeric: false,
|
||||||
}).compare;
|
}).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 {
|
export interface FolderItemForSorting {
|
||||||
path: string
|
path: string
|
||||||
groupIdx?: number // the index itself represents order for groups
|
groupIdx?: number // the index itself represents order for groups
|
||||||
|
|
|
@ -1706,6 +1706,11 @@ const txtInputErrorPriorityEmptyPattern: string = `
|
||||||
`
|
`
|
||||||
|
|
||||||
const txtInputEmptySpec: string = ``
|
const txtInputEmptySpec: string = ``
|
||||||
|
const txtInputOnlyCommentsSpec: string = `
|
||||||
|
// Some comment
|
||||||
|
|
||||||
|
// Another comment below empty line
|
||||||
|
`
|
||||||
|
|
||||||
describe('SortingSpecProcessor error detection and reporting', () => {
|
describe('SortingSpecProcessor error detection and reporting', () => {
|
||||||
let processor: SortingSpecProcessor;
|
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)}`)
|
`${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'))
|
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> = `
|
const inputTxtArr: Array<string> = `
|
||||||
/folders /+ Hello
|
/folders /+ Hello
|
||||||
`.replace(/\t/gi, '').split('\n')
|
`.replace(/\t/gi, '').split('\n')
|
||||||
|
@ -1959,6 +1964,12 @@ describe('SortingSpecProcessor error detection and reporting', () => {
|
||||||
expect(result).toBeNull()
|
expect(result).toBeNull()
|
||||||
expect(errorsLogger).toHaveBeenCalledTimes(0)
|
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([
|
it.each([
|
||||||
'% \\.d+...',
|
'% \\.d+...',
|
||||||
'% ...\\d+',
|
'% ...\\d+',
|
||||||
|
|
18
src/main.ts
18
src/main.ts
|
@ -2,8 +2,8 @@ import {
|
||||||
App,
|
App,
|
||||||
FileExplorerView,
|
FileExplorerView,
|
||||||
MetadataCache,
|
MetadataCache,
|
||||||
Notice,
|
|
||||||
normalizePath,
|
normalizePath,
|
||||||
|
Notice,
|
||||||
Platform,
|
Platform,
|
||||||
Plugin,
|
Plugin,
|
||||||
PluginSettingTab,
|
PluginSettingTab,
|
||||||
|
@ -16,7 +16,7 @@ import {
|
||||||
Vault
|
Vault
|
||||||
} from 'obsidian';
|
} from 'obsidian';
|
||||||
import {around} from 'monkey-around';
|
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 {SortingSpecProcessor, SortSpecsCollection} from './custom-sort/sorting-spec-processor';
|
||||||
import {CustomSortOrder, CustomSortSpec} from './custom-sort/custom-sort-types';
|
import {CustomSortOrder, CustomSortSpec} from './custom-sort/custom-sort-types';
|
||||||
|
|
||||||
|
@ -82,6 +82,17 @@ export default class CustomSortPlugin extends Plugin {
|
||||||
this.sortSpecCache = null
|
this.sortSpecCache = null
|
||||||
const processor: SortingSpecProcessor = new SortingSpecProcessor()
|
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) => {
|
Vault.recurseChildren(this.app.vault.getRoot(), (file: TAbstractFile) => {
|
||||||
if (failed) return
|
if (failed) return
|
||||||
if (file instanceof TFile) {
|
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
|
sortSpec = null // A folder is explicitly excluded from custom sorting plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!sortSpec && plugin.settings.enableAutomaticBookmarksOrderIntegration) {
|
|
||||||
sortSpec = SORTSPEC_FOR_AUTOMATIC_BOOKMARKS_INTEGRATION
|
|
||||||
}
|
|
||||||
if (sortSpec) {
|
if (sortSpec) {
|
||||||
sortSpec.plugin = plugin
|
sortSpec.plugin = plugin
|
||||||
return folderSort.call(this, sortSpec, ...args);
|
return folderSort.call(this, sortSpec, ...args);
|
||||||
|
|
Loading…
Reference in New Issue