Merge branch 'master' into 74-integration-with-bookmarks-core-plugin
# Conflicts: # src/custom-sort/custom-sort.ts
This commit is contained in:
commit
a3190cff62
|
@ -2276,7 +2276,7 @@ describe('CustomSortOrder.byMetadataFieldAlphabetical', () => {
|
||||||
expect(result1).toBe(SORT_FIRST_GOES_EARLIER)
|
expect(result1).toBe(SORT_FIRST_GOES_EARLIER)
|
||||||
expect(result2).toBe(SORT_FIRST_GOES_LATER)
|
expect(result2).toBe(SORT_FIRST_GOES_LATER)
|
||||||
})
|
})
|
||||||
it('should correctly fallback to alphabetical by name when metadata on both items is present and equal', () => {
|
it('should correctly compare when metadata on both items is present and equal', () => {
|
||||||
// given
|
// given
|
||||||
const itemA: Partial<FolderItemForSorting> = {
|
const itemA: Partial<FolderItemForSorting> = {
|
||||||
metadataFieldValue: 'Aaa',
|
metadataFieldValue: 'Aaa',
|
||||||
|
@ -2294,9 +2294,9 @@ describe('CustomSortOrder.byMetadataFieldAlphabetical', () => {
|
||||||
const result3: number = sorter(itemB as FolderItemForSorting, itemB as FolderItemForSorting)
|
const result3: number = sorter(itemB as FolderItemForSorting, itemB as FolderItemForSorting)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(result1).toBe(SORT_FIRST_GOES_LATER)
|
expect(result1).toBe(EQUAL_OR_UNCOMPARABLE)
|
||||||
expect(result2).toBe(SORT_FIRST_GOES_EARLIER)
|
expect(result2).toBe(EQUAL_OR_UNCOMPARABLE)
|
||||||
expect(result3).toBe(SORT_ITEMS_ARE_EQUAL)
|
expect(result3).toBe(EQUAL_OR_UNCOMPARABLE)
|
||||||
})
|
})
|
||||||
it('should put the item with metadata earlier if the second one has no metadata ', () => {
|
it('should put the item with metadata earlier if the second one has no metadata ', () => {
|
||||||
// given
|
// given
|
||||||
|
@ -2358,7 +2358,7 @@ describe('CustomSortOrder.byMetadataFieldAlphabeticalReverse', () => {
|
||||||
expect(result1).toBe(SORT_FIRST_GOES_LATER)
|
expect(result1).toBe(SORT_FIRST_GOES_LATER)
|
||||||
expect(result2).toBe(SORT_FIRST_GOES_EARLIER)
|
expect(result2).toBe(SORT_FIRST_GOES_EARLIER)
|
||||||
})
|
})
|
||||||
it('should correctly fallback to alphabetical reverse by name when metadata on both items is present and equal', () => {
|
it('should correctly compare when metadata on both items is present and equal', () => {
|
||||||
// given
|
// given
|
||||||
const itemA: Partial<FolderItemForSorting> = {
|
const itemA: Partial<FolderItemForSorting> = {
|
||||||
metadataFieldValue: 'Aaa',
|
metadataFieldValue: 'Aaa',
|
||||||
|
@ -2376,9 +2376,9 @@ describe('CustomSortOrder.byMetadataFieldAlphabeticalReverse', () => {
|
||||||
const result3: number = sorter(itemB as FolderItemForSorting, itemB as FolderItemForSorting)
|
const result3: number = sorter(itemB as FolderItemForSorting, itemB as FolderItemForSorting)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(result1).toBe(SORT_FIRST_GOES_EARLIER)
|
expect(result1).toBe(EQUAL_OR_UNCOMPARABLE)
|
||||||
expect(result2).toBe(SORT_FIRST_GOES_LATER)
|
expect(result2).toBe(EQUAL_OR_UNCOMPARABLE)
|
||||||
expect(result3).toBe(SORT_ITEMS_ARE_EQUAL)
|
expect(result3).toBe(EQUAL_OR_UNCOMPARABLE)
|
||||||
})
|
})
|
||||||
it('should put the item with metadata later if the second one has no metadata (reverse order)', () => {
|
it('should put the item with metadata later if the second one has no metadata (reverse order)', () => {
|
||||||
// given
|
// given
|
||||||
|
@ -2425,9 +2425,9 @@ describe('sorterByMetadataField', () => {
|
||||||
it.each([
|
it.each([
|
||||||
[true,'abc','def',-1, 'a', 'a'],
|
[true,'abc','def',-1, 'a', 'a'],
|
||||||
[true,'xyz','klm',1, 'b', 'b'],
|
[true,'xyz','klm',1, 'b', 'b'],
|
||||||
[true,'mmm','mmm',0, 'c', 'c'],
|
[true,'mmm','mmm',EQUAL_OR_UNCOMPARABLE, 'c', 'c'],
|
||||||
[true,'mmm','mmm',-1, 'd', 'e'],
|
[true,'mmm','mmm',EQUAL_OR_UNCOMPARABLE, 'd', 'e'],
|
||||||
[true,'mmm','mmm',1, 'e', 'd'],
|
[true,'mmm','mmm',EQUAL_OR_UNCOMPARABLE, 'e', 'd'],
|
||||||
[true,'abc',undefined,-1, 'a','a'],
|
[true,'abc',undefined,-1, 'a','a'],
|
||||||
[true,undefined,'klm',1, 'b','b'],
|
[true,undefined,'klm',1, 'b','b'],
|
||||||
[true,undefined,undefined,EQUAL_OR_UNCOMPARABLE, 'a','a'],
|
[true,undefined,undefined,EQUAL_OR_UNCOMPARABLE, 'a','a'],
|
||||||
|
@ -2435,9 +2435,9 @@ describe('sorterByMetadataField', () => {
|
||||||
[true,undefined,undefined,EQUAL_OR_UNCOMPARABLE, 'd','c'],
|
[true,undefined,undefined,EQUAL_OR_UNCOMPARABLE, 'd','c'],
|
||||||
[false,'abc','def',1, 'a', 'a'],
|
[false,'abc','def',1, 'a', 'a'],
|
||||||
[false,'xyz','klm',-1, 'b', 'b'],
|
[false,'xyz','klm',-1, 'b', 'b'],
|
||||||
[false,'mmm','mmm',0, 'c', 'c'],
|
[false,'mmm','mmm',EQUAL_OR_UNCOMPARABLE, 'c', 'c'],
|
||||||
[false,'mmm','mmm',1, 'd', 'e'],
|
[false,'mmm','mmm',EQUAL_OR_UNCOMPARABLE, 'd', 'e'],
|
||||||
[false,'mmm','mmm',-1, 'e', 'd'],
|
[false,'mmm','mmm',EQUAL_OR_UNCOMPARABLE, 'e', 'd'],
|
||||||
[false,'abc',undefined,1, 'a','a'],
|
[false,'abc',undefined,1, 'a','a'],
|
||||||
[false,undefined,'klm',-1, 'b','b'],
|
[false,undefined,'klm',-1, 'b','b'],
|
||||||
[false,undefined,undefined,EQUAL_OR_UNCOMPARABLE, 'a','a'],
|
[false,undefined,undefined,EQUAL_OR_UNCOMPARABLE, 'a','a'],
|
||||||
|
|
|
@ -5,7 +5,8 @@ import {
|
||||||
requireApiVersion,
|
requireApiVersion,
|
||||||
TAbstractFile,
|
TAbstractFile,
|
||||||
TFile,
|
TFile,
|
||||||
TFolder} from 'obsidian';
|
TFolder
|
||||||
|
} from 'obsidian';
|
||||||
import {
|
import {
|
||||||
determineStarredStatusOf,
|
determineStarredStatusOf,
|
||||||
Starred_PluginInstance
|
Starred_PluginInstance
|
||||||
|
@ -86,12 +87,7 @@ export const sorterByMetadataField:(reverseOrder?: boolean, trueAlphabetical?: b
|
||||||
}
|
}
|
||||||
if (a.metadataFieldValue && b.metadataFieldValue) {
|
if (a.metadataFieldValue && b.metadataFieldValue) {
|
||||||
const sortResult: number = collatorCompareFn(a.metadataFieldValue, b.metadataFieldValue)
|
const sortResult: number = collatorCompareFn(a.metadataFieldValue, b.metadataFieldValue)
|
||||||
if (sortResult === 0) {
|
return sortResult
|
||||||
// Fallback -> requested sort by metadata and both items have the same metadata value
|
|
||||||
return collatorCompareFn(a.sortString, b.sortString) // switch to alphabetical sort by note/folder titles
|
|
||||||
} else {
|
|
||||||
return sortResult
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Item with metadata goes before the w/o metadata
|
// Item with metadata goes before the w/o metadata
|
||||||
if (a.metadataFieldValue) return -1
|
if (a.metadataFieldValue) return -1
|
||||||
|
|
Loading…
Reference in New Issue