From 11d66231919db3f992ff6c98064f7f74252322ac Mon Sep 17 00:00:00 2001 From: SebastianMC <23032356+SebastianMC@users.noreply.github.com> Date: Thu, 25 Jan 2024 10:47:05 +0100 Subject: [PATCH] #123 - sorting by file basename by default (instead of fullname with ext) - new syntax `a-z.` and `true a-z.` introduced to allow explicitly sorting by filename with ext --- .../custom-sort-getComparator.spec.ts | 3 +- src/custom-sort/custom-sort-types.ts | 4 + src/custom-sort/custom-sort.spec.ts | 183 ++++++++++++------ src/custom-sort/custom-sort.ts | 14 +- .../sorting-spec-processor.spec.ts | 47 +++-- src/custom-sort/sorting-spec-processor.ts | 23 ++- 6 files changed, 198 insertions(+), 76 deletions(-) diff --git a/src/custom-sort/custom-sort-getComparator.spec.ts b/src/custom-sort/custom-sort-getComparator.spec.ts index d942af3..342acc7 100644 --- a/src/custom-sort/custom-sort-getComparator.spec.ts +++ b/src/custom-sort/custom-sort-getComparator.spec.ts @@ -97,7 +97,8 @@ const AB_EQUAL: number = 0 const BaseItemForSorting1: FolderItemForSorting = { groupIdx: 1, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'parent folder/References.md', diff --git a/src/custom-sort/custom-sort-types.ts b/src/custom-sort/custom-sort-types.ts index 9a18d89..45e09ee 100644 --- a/src/custom-sort/custom-sort-types.ts +++ b/src/custom-sort/custom-sort-types.ts @@ -13,9 +13,13 @@ export enum CustomSortGroupType { export enum CustomSortOrder { alphabetical = 1, // = 1 to allow: if (customSortOrder) { ... + alphabeticalWithFileExt, trueAlphabetical, + trueAlphabeticalWithFileExt, alphabeticalReverse, + alphabeticalReverseWithFileExt, trueAlphabeticalReverse, + trueAlphabeticalReverseWithFileExt, byModifiedTime, // New to old byModifiedTimeAdvanced, byModifiedTimeReverse, // Old to new diff --git a/src/custom-sort/custom-sort.spec.ts b/src/custom-sort/custom-sort.spec.ts index 999a749..d0b5154 100644 --- a/src/custom-sort/custom-sort.spec.ts +++ b/src/custom-sort/custom-sort.spec.ts @@ -109,7 +109,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -134,7 +135,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 1, // This indicates the last+1 idx (no match) isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 555, mtime: MOCK_TIMESTAMP + 666, path: 'Some parent folder/References.md' @@ -161,7 +163,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 1, // This indicates the last+1 idx (no match) isFolder: false, - sortString: "Part123:-icle.md", + sortString: "Part123:-icle", + sortStringWithExt: "Part123:-icle.md", ctime: MOCK_TIMESTAMP + 555, mtime: MOCK_TIMESTAMP + 666, path: 'Some parent folder/Part123:-icle.md' @@ -189,7 +192,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 1, // This indicates the last+1 idx isFolder: false, - sortString: "Part123:-icle.md", + sortString: "Part123:-icle", + sortStringWithExt: "Part123:-icle.md", ctime: MOCK_TIMESTAMP + 555, mtime: MOCK_TIMESTAMP + 666, path: 'Some parent folder/Part123:-icle.md' @@ -217,7 +221,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, // Matched! isFolder: false, - sortString: "Part123:-icle.md", + sortString: "Part123:-icle", + sortStringWithExt: "Part123:-icle.md", ctime: MOCK_TIMESTAMP + 555, mtime: MOCK_TIMESTAMP + 666, path: 'Some parent folder/Part123:-icle.md' @@ -245,7 +250,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, // Matched! isFolder: false, - sortString: "00000123////Part123:-icle.md", + sortString: "00000123////Part123:-icle", + sortStringWithExt: "00000123////Part123:-icle.md", ctime: MOCK_TIMESTAMP + 555, mtime: MOCK_TIMESTAMP + 666, path: 'Some parent folder/Part123:-icle.md' @@ -273,7 +279,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 1, // This indicates the last+1 idx isFolder: false, - sortString: "Part:123-icle.md", + sortString: "Part:123-icle", + sortStringWithExt: "Part:123-icle.md", ctime: MOCK_TIMESTAMP + 555, mtime: MOCK_TIMESTAMP + 666, path: 'Some parent folder/Part:123-icle.md' @@ -302,7 +309,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, // Matched! isFolder: false, - sortString: "Part:123-icle.md", + sortString: "Part:123-icle", + sortStringWithExt: "Part:123-icle.md", ctime: MOCK_TIMESTAMP + 555, mtime: MOCK_TIMESTAMP + 666, path: 'Some parent folder/Part:123-icle.md' @@ -332,7 +340,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, // Matched! isFolder: false, - sortString: "00000001|00000023////Part:1 1-23.456-icle.md", + sortString: "00000001|00000023////Part:1 1-23.456-icle", + sortStringWithExt: "00000001|00000023////Part:1 1-23.456-icle.md", ctime: MOCK_TIMESTAMP + 555, mtime: MOCK_TIMESTAMP + 666, path: 'Some parent folder/Part:1 1-23.456-icle.md' @@ -360,7 +369,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, // Matched! isFolder: false, - sortString: "00000123////Part:123-icle.md", + sortString: "00000123////Part:123-icle", + sortStringWithExt: "00000123////Part:123-icle.md", ctime: MOCK_TIMESTAMP + 555, mtime: MOCK_TIMESTAMP + 666, path: 'Some parent folder/Part:123-icle.md' @@ -391,7 +401,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, // Matched! isFolder: false, - sortString: "00000555|00000006//00000123////Part 555-6 123-icle.md", + sortString: "00000555|00000006//00000123////Part 555-6 123-icle", + sortStringWithExt: "00000555|00000006//00000123////Part 555-6 123-icle.md", ctime: MOCK_TIMESTAMP + 555, mtime: MOCK_TIMESTAMP + 666, path: 'Some parent folder/Part 555-6 123-icle.md' @@ -417,7 +428,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -443,7 +455,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "Ref2erences.md", + sortString: "Ref2erences", + sortStringWithExt: "Ref2erences.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/Ref2erences.md' @@ -470,7 +483,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: '00000001|00000030|00000006|00001900////Reference i.xxx.vi.mcm.md', + sortString: '00000001|00000030|00000006|00001900////Reference i.xxx.vi.mcm', + sortStringWithExt: '00000001|00000030|00000006|00001900////Reference i.xxx.vi.mcm.md', ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/Reference i.xxx.vi.mcm.md' @@ -493,7 +507,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 1, // This indicates the last+1 idx isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -519,7 +534,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -545,7 +561,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References 12.md", + sortString: "References 12", + sortStringWithExt: "References 12.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References 12.md' @@ -572,7 +589,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: '00000001|00000030|00000006|00001900////Reference i.xxx.vi.mcm.md', + sortString: '00000001|00000030|00000006|00001900////Reference i.xxx.vi.mcm', + sortStringWithExt: '00000001|00000030|00000006|00001900////Reference i.xxx.vi.mcm.md', ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/Reference i.xxx.vi.mcm.md' @@ -595,7 +613,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 1, // This indicates the last+1 idx isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -620,7 +639,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 1, // This indicates the last+1 idx isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -646,7 +666,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -672,7 +693,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References 12.md", + sortString: "References 12", + sortStringWithExt: "References 12.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References 12.md' @@ -699,7 +721,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: '00000001|00000030|00000006|00001900////Reference i.xxx.vi.mcm.md', + sortString: '00000001|00000030|00000006|00001900////Reference i.xxx.vi.mcm', + sortStringWithExt: '00000001|00000030|00000006|00001900////Reference i.xxx.vi.mcm.md', ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/Reference i.xxx.vi.mcm.md' @@ -722,7 +745,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 1, // This indicates the last+1 idx isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -747,7 +771,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 1, // This indicates the last+1 idx isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -774,7 +799,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, // This indicates match! isFolder: false, - sortString: "gs-123.md", + sortString: "gs-123", + sortStringWithExt: "gs-123.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/gs-123.md' @@ -815,7 +841,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 1, // The lastIdx+1, group not determined isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -854,7 +881,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 1, // lastIdx + 1, group not determined isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -893,7 +921,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -933,6 +962,7 @@ describe('determineSortingGroup', () => { groupIdx: 0, isFolder: true, sortString: "References", + sortStringWithExt: "References", ctime: DEFAULT_FOLDER_CTIME, mtime: DEFAULT_FOLDER_MTIME, path: 'References', @@ -965,7 +995,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 1, // The lastIdx+1, group not determined isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -996,7 +1027,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -1028,6 +1060,8 @@ describe('determineSortingGroup', () => { groupIdx: 1, // The lastIdx+1, group not determined isFolder: true, sortString: "TestEmptyFolder", + sortStringWithExt: "TestEmptyFolder", + ctime: 0, mtime: 0, path: 'TestEmptyFolder', @@ -1067,6 +1101,8 @@ describe('determineSortingGroup', () => { groupIdx: 1, // The lastIdx+1, group not determined isFolder: true, sortString: "TestEmptyFolder", + sortStringWithExt: "TestEmptyFolder", + ctime: 0, mtime: 0, path: 'TestEmptyFolder', @@ -1106,6 +1142,8 @@ describe('determineSortingGroup', () => { groupIdx: 0, isFolder: true, sortString: "TestEmptyFolder", + sortStringWithExt: "TestEmptyFolder", + ctime: 0, mtime: 0, path: 'TestEmptyFolder', @@ -1147,7 +1185,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 1, // The lastIdx+1, group not determined isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -1182,7 +1221,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 1, // The lastIdx+1, group not determined isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -1216,7 +1256,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -1251,7 +1292,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md' @@ -1283,6 +1325,8 @@ describe('determineSortingGroup', () => { groupIdx: 1, // The lastIdx+1, group not determined isFolder: true, sortString: "TestEmptyFolder", + sortStringWithExt: "TestEmptyFolder", + ctime: 0, mtime: 0, path: 'TestEmptyFolder', @@ -1325,6 +1369,8 @@ describe('determineSortingGroup', () => { groupIdx: 0, isFolder: true, sortString: "TestEmptyFolder", + sortStringWithExt: "TestEmptyFolder", + ctime: 0, mtime: 0, path: 'TestEmptyFolder', @@ -1370,6 +1416,8 @@ describe('determineSortingGroup', () => { groupIdx: 0, isFolder: true, sortString: "TestEmptyFolder", + sortStringWithExt: "TestEmptyFolder", + ctime: 0, mtime: 0, path: 'TestEmptyFolder', @@ -1413,6 +1461,8 @@ describe('determineSortingGroup', () => { groupIdx: 0, isFolder: true, sortString: "TestEmptyFolder", + sortStringWithExt: "TestEmptyFolder", + ctime: 0, mtime: 0, path: 'TestEmptyFolder', @@ -1459,6 +1509,8 @@ describe('determineSortingGroup', () => { groupIdx: 0, isFolder: true, sortString: "TestEmptyFolder", + sortStringWithExt: "TestEmptyFolder", + ctime: 0, mtime: 0, path: 'TestEmptyFolder', @@ -1502,6 +1554,7 @@ describe('determineSortingGroup', () => { groupIdx: 1, // lastIdx+1 - no match isFolder: true, sortString: "TestEmptyFolder", + sortStringWithExt: "TestEmptyFolder", ctime: 0, mtime: 0, path: 'TestEmptyFolder', @@ -1548,6 +1601,7 @@ describe('determineSortingGroup', () => { groupIdx: 1, // lastIdx+1 - no match isFolder: true, sortString: "TestEmptyFolder", + sortStringWithExt: "TestEmptyFolder", ctime: 0, mtime: 0, path: 'TestEmptyFolder', @@ -1598,7 +1652,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md', @@ -1639,7 +1694,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md', @@ -1680,7 +1736,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md', @@ -1721,7 +1778,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md', @@ -1763,6 +1821,7 @@ describe('determineSortingGroup', () => { groupIdx: 0, isFolder: true, sortString: "References", + sortStringWithExt: "References", ctime: DEFAULT_FOLDER_CTIME, mtime: DEFAULT_FOLDER_MTIME, path: 'References', @@ -1805,7 +1864,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md', @@ -1845,7 +1905,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md', @@ -1885,7 +1946,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md', @@ -1930,7 +1992,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md', @@ -1972,7 +2035,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md', @@ -2015,7 +2079,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md', @@ -2059,7 +2124,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md', @@ -2103,6 +2169,7 @@ describe('determineSortingGroup', () => { groupIdx: 0, isFolder: true, sortString: "References", + sortStringWithExt: "References", ctime: DEFAULT_FOLDER_CTIME, mtime: DEFAULT_FOLDER_MTIME, path: 'References', @@ -2147,7 +2214,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md', @@ -2188,7 +2256,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md', @@ -2229,7 +2298,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md', @@ -2282,7 +2352,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 0, isFolder: false, - sortString: "References.md", + sortString: "References", + sortStringWithExt: "References.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/References.md', @@ -2332,7 +2403,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 3, isFolder: false, - sortString: "Abcdef!.md", + sortString: "Abcdef!", + sortStringWithExt: "Abcdef!.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/Abcdef!.md' @@ -2381,7 +2453,8 @@ describe('determineSortingGroup', () => { expect(result1).toEqual({ groupIdx: 1, // Imposed by combined groups isFolder: false, - sortString: "Hello :-) ha.md", + sortString: "Hello :-) ha", + sortStringWithExt: "Hello :-) ha.md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/Hello :-) ha.md' @@ -2389,7 +2462,8 @@ describe('determineSortingGroup', () => { expect(result2).toEqual({ groupIdx: 1, // Imposed by combined groups isFolder: false, - sortString: "Hello World :-).md", + sortString: "Hello World :-)", + sortStringWithExt: "Hello World :-).md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/Hello World :-).md' @@ -2434,7 +2508,8 @@ describe('determineSortingGroup', () => { expect(result).toEqual({ groupIdx: 2, // Imposed by combined groups isFolder: false, - sortString: "Hello :-).md", + sortString: "Hello :-)", + sortStringWithExt: "Hello :-).md", ctime: MOCK_TIMESTAMP + 222, mtime: MOCK_TIMESTAMP + 333, path: 'Some parent folder/Hello :-).md' diff --git a/src/custom-sort/custom-sort.ts b/src/custom-sort/custom-sort.ts index e9c6f48..08de1b0 100644 --- a/src/custom-sort/custom-sort.ts +++ b/src/custom-sort/custom-sort.ts @@ -58,7 +58,8 @@ export const CollatorTrueAlphabeticalCompare = new Intl.Collator(undefined, { export interface FolderItemForSorting { path: string groupIdx?: number // the index itself represents order for groups - sortString: string // fragment (or full name) to be used for sorting + sortString: string // file basename / folder name to be used for sorting (optionally prefixed with regexp-matched group) + sortStringWithExt: string // same as above, yet full filename (with ext) metadataFieldValue?: string // relevant to metadata-based group sorting only metadataFieldValueSecondary?: string // relevant to secondary metadata-based sorting only metadataFieldValueForDerived?: string // relevant to metadata-based sorting-spec level sorting only @@ -170,9 +171,13 @@ export const sorterByFolderMDate:(reverseOrder?: boolean) => SorterFn = (reverse const Sorters: { [key in CustomSortOrder]: SorterFn } = { [CustomSortOrder.alphabetical]: (a: FolderItemForSorting, b: FolderItemForSorting) => CollatorCompare(a.sortString, b.sortString), + [CustomSortOrder.alphabeticalWithFileExt]: (a: FolderItemForSorting, b: FolderItemForSorting) => CollatorCompare(a.sortStringWithExt, b.sortStringWithExt), [CustomSortOrder.trueAlphabetical]: (a: FolderItemForSorting, b: FolderItemForSorting) => CollatorTrueAlphabeticalCompare(a.sortString, b.sortString), + [CustomSortOrder.trueAlphabeticalWithFileExt]: (a: FolderItemForSorting, b: FolderItemForSorting) => CollatorTrueAlphabeticalCompare(a.sortStringWithExt, b.sortStringWithExt), [CustomSortOrder.alphabeticalReverse]: (a: FolderItemForSorting, b: FolderItemForSorting) => CollatorCompare(b.sortString, a.sortString), + [CustomSortOrder.alphabeticalReverseWithFileExt]: (a: FolderItemForSorting, b: FolderItemForSorting) => CollatorCompare(b.sortStringWithExt, a.sortStringWithExt), [CustomSortOrder.trueAlphabeticalReverse]: (a: FolderItemForSorting, b: FolderItemForSorting) => CollatorTrueAlphabeticalCompare(b.sortString, a.sortString), + [CustomSortOrder.trueAlphabeticalReverseWithFileExt]: (a: FolderItemForSorting, b: FolderItemForSorting) => CollatorTrueAlphabeticalCompare(b.sortStringWithExt, a.sortStringWithExt), [CustomSortOrder.byModifiedTime]: (a: FolderItemForSorting, b: FolderItemForSorting) => (a.isFolder && b.isFolder) ? CollatorCompare(a.sortString, b.sortString) : (a.mtime - b.mtime), [CustomSortOrder.byModifiedTimeAdvanced]: sorterByFolderMDate(), [CustomSortOrder.byModifiedTimeReverse]: (a: FolderItemForSorting, b: FolderItemForSorting) => (a.isFolder && b.isFolder) ? CollatorCompare(a.sortString, b.sortString) : (b.mtime - a.mtime), @@ -351,6 +356,7 @@ export const determineSortingGroup = function (entry: TFile | TFolder, spec: Cus let groupIdx: number let determined: boolean = false let derivedText: string | null | undefined + let derivedTextWithExt: string | undefined let bookmarkedIdx: number | undefined const aFolder: boolean = isFolder(entry) @@ -485,7 +491,8 @@ export const determineSortingGroup = function (entry: TFile | TFolder, spec: Cus break } if (determined && derivedText) { - derivedText = derivedText + '//' + entry.name + derivedTextWithExt = derivedText + '//' + entry.name + derivedText = derivedText + '//' + basename } } @@ -541,7 +548,8 @@ export const determineSortingGroup = function (entry: TFile | TFolder, spec: Cus return { // idx of the matched group or idx of Outsiders group or the largest index (= groups count+1) groupIdx: determinedGroupIdx, - sortString: derivedText ?? entry.name, + sortString: derivedText ?? basename, + sortStringWithExt: derivedText ? derivedTextWithExt! : entry.name, metadataFieldValue: metadataValueToSortBy, metadataFieldValueSecondary: metadataValueSecondaryToSortBy, metadataFieldValueForDerived: metadataValueDerivedPrimaryToSortBy, diff --git a/src/custom-sort/sorting-spec-processor.spec.ts b/src/custom-sort/sorting-spec-processor.spec.ts index d9b0ac0..fde99c8 100644 --- a/src/custom-sort/sorting-spec-processor.spec.ts +++ b/src/custom-sort/sorting-spec-processor.spec.ts @@ -78,7 +78,7 @@ target-folder: Sandbox target-folder: Abcd efgh ijk > a-z Plain text spec bla bla bla (matches files and folders)... -/: files only matching +/:. files only matching > a-z / folders only matching < a-z @@ -143,7 +143,7 @@ target-folder: Sandbox target-folder: Abcd efgh ijk \> a-z Plain text spec bla bla bla (matches files and folders)... -/:files files only matching +/:files. files only matching > a-z /folders folders only matching \< a-z @@ -317,6 +317,7 @@ const expectedSortSpecsExampleA: { [key: string]: CustomSortSpec } = { exactText: "files only matching", filesOnly: true, order: CustomSortOrder.alphabeticalReverse, + matchFilenameWithExt: true, type: CustomSortGroupType.ExactName }, { exactText: "folders only matching", @@ -531,6 +532,10 @@ target-folder: True Alpha < true a-z target-folder: True Alpha Rev > true a-z +target-folder: True Alpha withExt +< true a-z. +target-folder: True Alpha Rev withExt +> true a-z. target-folder: by-meta True Alpha < true a-z by-metadata: target-folder: by-meta True Alpha Rev @@ -554,6 +559,22 @@ const expectedSortSpecForTrueAlphabeticalSorting: { [key: string]: CustomSortSpe outsidersGroupIdx: 0, targetFoldersPaths: ['True Alpha Rev'] }, + "True Alpha withExt": { + defaultOrder: CustomSortOrder.trueAlphabeticalWithFileExt, + groups: [{ + type: CustomSortGroupType.Outsiders + }], + outsidersGroupIdx: 0, + targetFoldersPaths: ['True Alpha withExt'] + }, + "True Alpha Rev withExt": { + defaultOrder: CustomSortOrder.trueAlphabeticalReverseWithFileExt, + groups: [{ + type: CustomSortGroupType.Outsiders + }], + outsidersGroupIdx: 0, + targetFoldersPaths: ['True Alpha Rev withExt'] + }, "by-meta True Alpha": { defaultOrder: CustomSortOrder.byMetadataFieldTrueAlphabetical, groups: [{ @@ -1453,7 +1474,7 @@ describe('multi-level sorting', () => { a pre order-asc: true a-z, order-asc: modified a pre 2 - order-asc: true a-z, < modified + order-asc: true a-z., < modified a post 1 order-asc: true a-z, modified order-asc a post 2 @@ -1477,7 +1498,7 @@ describe('multi-level sorting', () => { d post order-desc: true a-z, modified > d none - order-desc: true a-z, modified + order-desc: true a-z., modified d unspecified order-desc: true a-z, sorting: modified d dbl specified @@ -1493,7 +1514,7 @@ describe('multi-level sorting', () => { type: CustomSortGroupType.ExactName },{ exactText: "a pre 2", - order: CustomSortOrder.trueAlphabetical, + order: CustomSortOrder.trueAlphabeticalWithFileExt, secondaryOrder: CustomSortOrder.byModifiedTime, type: CustomSortGroupType.ExactName },{ @@ -1553,7 +1574,7 @@ describe('multi-level sorting', () => { type: CustomSortGroupType.ExactName },{ exactText: "d none", - order: CustomSortOrder.trueAlphabeticalReverse, + order: CustomSortOrder.trueAlphabeticalReverseWithFileExt, secondaryOrder: CustomSortOrder.byModifiedTime, type: CustomSortGroupType.ExactName },{ @@ -1582,7 +1603,7 @@ describe('multi-level sorting', () => { a c d < a-z, created desc a ac a - < a-z, advanced created asc + < a-z., advanced created asc a ac d < a-z, advanced created desc a m a @@ -1594,7 +1615,7 @@ describe('multi-level sorting', () => { a am d < a-z, advanced modified desc d c a - > a-z, created asc + > a-z., created asc d c d > a-z, created desc d ac a @@ -1625,7 +1646,7 @@ describe('multi-level sorting', () => { type: CustomSortGroupType.ExactName },{ exactText: "a ac a", - order: CustomSortOrder.alphabetical, + order: CustomSortOrder.alphabeticalWithFileExt, secondaryOrder: CustomSortOrder.byCreatedTimeAdvanced, type: CustomSortGroupType.ExactName },{ @@ -1655,7 +1676,7 @@ describe('multi-level sorting', () => { type: CustomSortGroupType.ExactName },{ exactText: "d c a", - order: CustomSortOrder.alphabeticalReverse, + order: CustomSortOrder.alphabeticalReverseWithFileExt, secondaryOrder: CustomSortOrder.byCreatedTime, type: CustomSortGroupType.ExactName }, { @@ -1777,14 +1798,14 @@ describe('the sorting: prefix', () => { }) it('secondary should not inherit direction from primary', () => { const inputTxtArr: Array = ` - /folders:files - sorting: a-z desc, sorting: advanced modified + /folders:files. + sorting: a-z. desc, sorting: advanced modified `.replace(/\t/gi, '').split('\n') const result = processor.parseSortSpecFromText(inputTxtArr, 'mock-folder', 'custom-name-note.md') expect(result?.sortSpecByPath).toEqual({ 'mock-folder': { groups: [{ - order: CustomSortOrder.alphabeticalReverse, + order: CustomSortOrder.alphabeticalReverseWithFileExt, secondaryOrder: CustomSortOrder.byModifiedTimeAdvanced, type: CustomSortGroupType.Outsiders }], diff --git a/src/custom-sort/sorting-spec-processor.ts b/src/custom-sort/sorting-spec-processor.ts index 187bbfa..2109e28 100644 --- a/src/custom-sort/sorting-spec-processor.ts +++ b/src/custom-sort/sorting-spec-processor.ts @@ -112,7 +112,9 @@ const MAX_SORT_LEVEL: number = 1 // remember about .toLowerCase() before comparison! const OrderLiterals: { [key: string]: CustomSortOrderAscDescPair } = { + 'a-z.': {asc: CustomSortOrder.alphabeticalWithFileExt, desc: CustomSortOrder.alphabeticalReverseWithFileExt}, 'a-z': {asc: CustomSortOrder.alphabetical, desc: CustomSortOrder.alphabeticalReverse}, + 'true a-z.': {asc: CustomSortOrder.trueAlphabeticalWithFileExt, desc: CustomSortOrder.trueAlphabeticalReverseWithFileExt}, 'true a-z': {asc: CustomSortOrder.trueAlphabetical, desc: CustomSortOrder.trueAlphabeticalReverse}, 'created': {asc: CustomSortOrder.byCreatedTime, desc: CustomSortOrder.byCreatedTimeReverse}, 'modified': {asc: CustomSortOrder.byModifiedTime, desc: CustomSortOrder.byModifiedTimeReverse}, @@ -215,7 +217,11 @@ const OrdersSupportedByMetadata: { [key in CustomSortOrder]?: CustomSortOrder} = [CustomSortOrder.alphabetical]: CustomSortOrder.byMetadataFieldAlphabetical, [CustomSortOrder.alphabeticalReverse]: CustomSortOrder.byMetadataFieldAlphabeticalReverse, [CustomSortOrder.trueAlphabetical]: CustomSortOrder.byMetadataFieldTrueAlphabetical, - [CustomSortOrder.trueAlphabeticalReverse]: CustomSortOrder.byMetadataFieldTrueAlphabeticalReverse + [CustomSortOrder.trueAlphabeticalReverse]: CustomSortOrder.byMetadataFieldTrueAlphabeticalReverse, + [CustomSortOrder.alphabeticalWithFileExt]: CustomSortOrder.byMetadataFieldAlphabetical, + [CustomSortOrder.alphabeticalReverseWithFileExt]: CustomSortOrder.byMetadataFieldAlphabeticalReverse, + [CustomSortOrder.trueAlphabeticalWithFileExt]: CustomSortOrder.byMetadataFieldTrueAlphabetical, + [CustomSortOrder.trueAlphabeticalReverseWithFileExt]: CustomSortOrder.byMetadataFieldTrueAlphabeticalReverse } const CURRENT_FOLDER_SYMBOL: string = '.' @@ -228,15 +234,20 @@ interface ParsedSortingAttribute { type AttrValueValidatorFn = (v: string, attr: Attribute, attrLexeme: string) => any|AttrError|null; +// Lexemes with name prefix _1_ have to be checked before others, because they are longer variants of shorter lexemes +// and thus plain parsing would detect the shorter contained variants first otherwise. + const FilesGroupVerboseLexeme: string = '/:files' const FilesGroupShortLexeme: string = '/:' -const FilesWithExtGroupVerboseLexeme: string = '/:files.' -const FilesWithExtGroupShortLexeme: string = '/:.' +const _1_FilesWithExtGroupVerboseLexeme: string = '/:files.' +const _1_FilesWithExtGroupShortLexeme: string = '/:.' const FoldersGroupVerboseLexeme: string = '/folders' const FoldersGroupShortLexeme: string = '/' const AnyTypeGroupLexemeShort: string = '%' // See % as a combination of / and : const AnyTypeGroupLexeme1: string = '/folders:files' +const _1_AnyTypeWithExtGroupLexeme1: string = '/folders:files.' const AnyTypeGroupLexeme2: string = '/%' // See % as a combination of / and : +const _1_AnyTypeWithExtGroupLexeme2: string = '/%.' // See % as a combination of / and :. const HideItemShortLexeme: string = '--%' // See % as a combination of / and : const HideItemVerboseLexeme: string = '/--hide:' @@ -289,10 +300,12 @@ interface SortingGroupType { } const SortingGroupPrefixes: { [key: string]: SortingGroupType } = { + [_1_AnyTypeWithExtGroupLexeme1]: {filenameWithExt: true}, + [_1_AnyTypeWithExtGroupLexeme2]: {filenameWithExt: true}, + [_1_FilesWithExtGroupShortLexeme]: {filesOnly: true, filenameWithExt: true}, + [_1_FilesWithExtGroupVerboseLexeme]: {filesOnly: true, filenameWithExt: true}, [FilesGroupShortLexeme]: {filesOnly: true}, [FilesGroupVerboseLexeme]: {filesOnly: true}, - [FilesWithExtGroupShortLexeme]: {filesOnly: true, filenameWithExt: true}, - [FilesWithExtGroupVerboseLexeme]: {filesOnly: true, filenameWithExt: true}, [FoldersGroupShortLexeme]: {foldersOnly: true}, [FoldersGroupVerboseLexeme]: {foldersOnly: true}, [AnyTypeGroupLexemeShort]: {},