Skip to content

Commit c300894

Browse files
committed
#185 - drop backward compatibility
- removed integration with Starred code plugin (which hasn't already been there for months)
1 parent 5013b47 commit c300894

File tree

9 files changed

+30
-228
lines changed

9 files changed

+30
-228
lines changed

src/custom-sort/custom-sort-types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export enum CustomSortGroupType {
66
ExactSuffix,
77
ExactHeadAndTail, // Like W...n or Un...ed, which is shorter variant of typing the entire title
88
HasMetadataField, // Notes (or folder's notes) containing a specific metadata field
9-
StarredOnly,
109
BookmarkedOnly,
1110
HasIcon
1211
}

src/custom-sort/custom-sort-utils.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export interface HasSortingTypes {
1616

1717
export interface HasGroupingTypes {
1818
byBookmarks: number
19-
byStarred: number
2019
byIcon: number
2120
total: number
2221
}
@@ -31,10 +30,6 @@ export const checkByBookmark = (has: HasSortingOrGrouping, order?: CustomSortOrd
3130
(order === CustomSortOrder.byBookmarkOrder || order === CustomSortOrder.byBookmarkOrderReverse) && has.sorting.byBookmarks++;
3231
}
3332

34-
export const checkByStarred = (has: HasSortingOrGrouping, order?: CustomSortOrder, groupType?: CustomSortGroupType ) => {
35-
groupType === CustomSortGroupType.StarredOnly && has.grouping.byStarred++;
36-
}
37-
3833
export const checkByIcon = (has: HasSortingOrGrouping, order?: CustomSortOrder, groupType?: CustomSortGroupType ) => {
3934
groupType === CustomSortGroupType.HasIcon && has.grouping.byIcon++;
4035
}
@@ -45,7 +40,6 @@ export const checkStandardObsidian = (has: HasSortingOrGrouping, order?: CustomS
4540

4641
export const doCheck = (has: HasSortingOrGrouping, order?: CustomSortOrder, groupType?: CustomSortGroupType) => {
4742
checkByBookmark(has, order, groupType)
48-
checkByStarred(has, order, groupType)
4943
checkByIcon(has, order, groupType)
5044
checkStandardObsidian(has, order, groupType)
5145

@@ -56,7 +50,7 @@ export const doCheck = (has: HasSortingOrGrouping, order?: CustomSortOrder, grou
5650
export const collectSortingAndGroupingTypes = (sortSpec?: CustomSortSpec|null): HasSortingOrGrouping => {
5751
const has: HasSortingOrGrouping = {
5852
grouping: {
59-
byIcon: 0, byStarred: 0, byBookmarks: 0, total: 0
53+
byIcon: 0, byBookmarks: 0, total: 0
6054
},
6155
sorting: {
6256
byBookmarks: 0, standardObsidian: 0, total: 0

src/custom-sort/custom-sort.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import {
88
TFolder,
99
Vault
1010
} from 'obsidian';
11-
import {
12-
determineStarredStatusOf,
13-
Starred_PluginInstance
14-
} from '../utils/StarredPluginSignature';
1511
import {
1612
determineIconOf,
1713
ObsidianIconFolder_PluginInstance
@@ -40,7 +36,6 @@ export interface ProcessingContext {
4036
// For internal transient use
4137
plugin?: CustomSortPluginAPI // to hand over the access to App instance to the sorting engine
4238
_mCache?: MetadataCache
43-
starredPluginInstance?: Starred_PluginInstance
4439
bookmarksPluginInstance?: BookmarksPluginInterface,
4540
iconFolderPluginInstance?: ObsidianIconFolder_PluginInstance
4641
}
@@ -495,14 +490,6 @@ export const determineSortingGroup = function (entry: TFile | TFolder, spec: Cus
495490
}
496491
}
497492
break
498-
case CustomSortGroupType.StarredOnly:
499-
if (ctx?.starredPluginInstance) {
500-
const starred: boolean = determineStarredStatusOf(entry, aFile, ctx.starredPluginInstance)
501-
if (starred) {
502-
determined = true
503-
}
504-
}
505-
break
506493
case CustomSortGroupType.BookmarkedOnly:
507494
if (ctx?.bookmarksPluginInstance) {
508495
const bookmarkOrder: number | undefined = ctx?.bookmarksPluginInstance.determineBookmarkOrder(entry.path)

src/custom-sort/sorting-spec-processor.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,6 @@ const MetadataFieldIndicatorLexeme: string = 'with-metadata:'
269269

270270
const BookmarkedItemIndicatorLexeme: string = 'bookmarked:'
271271

272-
const StarredItemsIndicatorLexeme: string = 'starred:'
273-
274272
const IconIndicatorLexeme: string = 'with-icon:'
275273

276274
const CommentPrefix: string = '//'
@@ -1710,13 +1708,6 @@ export class SortingSpecProcessor {
17101708
foldersOnly: spec.foldersOnly,
17111709
matchFilenameWithExt: spec.matchFilenameWithExt
17121710
}
1713-
} else if (theOnly.startsWith(StarredItemsIndicatorLexeme)) {
1714-
return {
1715-
type: CustomSortGroupType.StarredOnly,
1716-
filesOnly: spec.filesOnly,
1717-
foldersOnly: spec.foldersOnly,
1718-
matchFilenameWithExt: spec.matchFilenameWithExt
1719-
}
17201711
} else {
17211712
// For non-three dots single text line assume exact match group
17221713
return {

src/main.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import {
4444
ICON_SORT_SUSPENDED_GENERAL_ERROR,
4545
ICON_SORT_SUSPENDED_SYNTAX_ERROR
4646
} from "./custom-sort/icons";
47-
import {getStarredPlugin} from "./utils/StarredPluginSignature";
4847
import {
4948
BookmarksPluginInterface,
5049
getBookmarksPlugin,
@@ -583,7 +582,6 @@ export default class CustomSortPlugin
583582
createProcessingContextForSorting(has: HasSortingOrGrouping): ProcessingContext {
584583
const ctx: ProcessingContext = {
585584
_mCache: this.app.metadataCache,
586-
starredPluginInstance: has.grouping.byStarred ? getStarredPlugin(this.app) : undefined,
587585
bookmarksPluginInstance: has.grouping.byBookmarks || has.sorting.byBookmarks ? getBookmarksPlugin(this.app, this.settings.bookmarksGroupToConsumeAsOrderingReference, false, true) : undefined,
588586
iconFolderPluginInstance: has.grouping.byIcon ? getIconFolderPlugin(this.app) : undefined,
589587
plugin: this

src/test/unit/custom-sort-utils.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const getHas = (gTotal?: NM, gBkmrk?: NM, gStar?: NM, gIcon?: NM, sTot?: NM, sBk
1818
grouping: {
1919
total: gTotal ||0,
2020
byBookmarks: gBkmrk ||0,
21-
byStarred: gStar ||0,
2221
byIcon: gIcon ||0
2322
},
2423
sorting: {

src/test/unit/custom-sort.spec.ts

Lines changed: 20 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
CachedMetadata,
33
MetadataCache,
4-
Pos,
4+
Pos, TAbstractFile,
55
TFile,
66
TFolder,
77
Vault
@@ -36,9 +36,8 @@ import {
3636
CompoundDotRomanNumberNormalizerFn
3737
} from "../../custom-sort/sorting-spec-processor";
3838
import {
39-
findStarredFile_pathParam,
40-
Starred_PluginInstance
41-
} from "../../utils/StarredPluginSignature";
39+
BookmarksPluginInterface
40+
} from "../../utils/BookmarksCorePluginSignature";
4241
import {
4342
ObsidianIconFolder_PluginInstance,
4443
ObsidianIconFolderPlugin_Data
@@ -937,25 +936,25 @@ describe('determineSortingGroup', () => {
937936
} as FolderItemForSorting);
938937
})
939938
})
940-
describe('CustomSortGroupType.StarredOnly', () => {
941-
it('should not match not starred file', () => {
939+
describe('CustomSortGroupType.BookmarkedOnly', () => {
940+
it('should not match not bookmarked file', () => {
942941
// given
943942
const file: TFile = mockTFile('References', 'md', 111, MOCK_TIMESTAMP + 222, MOCK_TIMESTAMP + 333);
944943
const sortSpec: CustomSortSpec = {
945944
targetFoldersPaths: ['/'],
946945
groups: [{
947-
type: CustomSortGroupType.StarredOnly
946+
type: CustomSortGroupType.BookmarkedOnly
948947
}]
949948
}
950-
const starredPluginInstance: Partial<Starred_PluginInstance> = {
951-
findStarredFile: jest.fn( function(filePath: findStarredFile_pathParam): TFile | null {
952-
return null
949+
const bookmarksPluginInstance: Partial<BookmarksPluginInterface> = {
950+
determineBookmarkOrder: jest.fn( function(path: string): number | undefined {
951+
return undefined
953952
})
954953
}
955954

956955
// when
957956
const result = determineSortingGroup(file, sortSpec, {
958-
starredPluginInstance: starredPluginInstance as Starred_PluginInstance
957+
bookmarksPluginInstance: bookmarksPluginInstance as BookmarksPluginInterface
959958
} as ProcessingContext)
960959

961960
// then
@@ -968,30 +967,32 @@ describe('determineSortingGroup', () => {
968967
mtime: MOCK_TIMESTAMP + 333,
969968
path: 'Some parent folder/References.md'
970969
});
971-
expect(starredPluginInstance.findStarredFile).toHaveBeenCalledTimes(1)
970+
expect(bookmarksPluginInstance.determineBookmarkOrder).toHaveBeenCalledTimes(1)
972971
})
973-
it('should match starred file', () => {
972+
it('should match bookmarked file', () => {
974973
// given
975974
const file: TFile = mockTFile('References', 'md', 111, MOCK_TIMESTAMP + 222, MOCK_TIMESTAMP + 333);
976975
const sortSpec: CustomSortSpec = {
977976
targetFoldersPaths: ['/'],
978977
groups: [{
979-
type: CustomSortGroupType.StarredOnly
978+
type: CustomSortGroupType.BookmarkedOnly
980979
}]
981980
}
982-
const starredPluginInstance: Partial<Starred_PluginInstance> = {
983-
findStarredFile: jest.fn( function(filePath: findStarredFile_pathParam): TFile | null {
984-
return filePath.path === 'Some parent folder/References.md' ? file : null
981+
const BOOKMARK_ORDER = 123
982+
const bookmarksPluginInstance: Partial<BookmarksPluginInterface> = {
983+
determineBookmarkOrder: jest.fn( function(path: string): number | undefined {
984+
return path === 'Some parent folder/References.md' ? BOOKMARK_ORDER : undefined
985985
})
986986
}
987987

988988
// when
989989
const result = determineSortingGroup(file, sortSpec, {
990-
starredPluginInstance: starredPluginInstance as Starred_PluginInstance
990+
bookmarksPluginInstance: bookmarksPluginInstance as BookmarksPluginInterface
991991
} as ProcessingContext)
992992

993993
// then
994994
expect(result).toEqual({
995+
bookmarkedIdx: BOOKMARK_ORDER,
995996
groupIdx: 0,
996997
isFolder: false,
997998
sortString: "References",
@@ -1000,131 +1001,7 @@ describe('determineSortingGroup', () => {
10001001
mtime: MOCK_TIMESTAMP + 333,
10011002
path: 'Some parent folder/References.md'
10021003
});
1003-
expect(starredPluginInstance.findStarredFile).toHaveBeenCalledTimes(1)
1004-
})
1005-
it('should not match empty folder', () => {
1006-
// given
1007-
const folder: TFolder = mockTFolder('TestEmptyFolder');
1008-
const sortSpec: CustomSortSpec = {
1009-
targetFoldersPaths: ['/'],
1010-
groups: [{
1011-
type: CustomSortGroupType.StarredOnly
1012-
}]
1013-
}
1014-
const starredPluginInstance: Partial<Starred_PluginInstance> = {
1015-
findStarredFile: jest.fn( function(filePath: findStarredFile_pathParam): TFile | null {
1016-
return filePath.path === 'Some parent folder/References.md' ? {} as TFile : null
1017-
})
1018-
}
1019-
1020-
// when
1021-
const result = determineSortingGroup(folder, sortSpec, {
1022-
starredPluginInstance: starredPluginInstance as Starred_PluginInstance
1023-
} as ProcessingContext)
1024-
1025-
// then
1026-
expect(result).toEqual({
1027-
groupIdx: 1, // The lastIdx+1, group not determined
1028-
isFolder: true,
1029-
sortString: "TestEmptyFolder",
1030-
sortStringWithExt: "TestEmptyFolder",
1031-
1032-
ctime: 0,
1033-
mtime: 0,
1034-
path: 'TestEmptyFolder',
1035-
folder: {
1036-
children: [],
1037-
isRoot: expect.any(Function),
1038-
name: "TestEmptyFolder",
1039-
parent: {},
1040-
path: "TestEmptyFolder",
1041-
vault: {}
1042-
}
1043-
});
1044-
expect(starredPluginInstance.findStarredFile).not.toHaveBeenCalled()
1045-
})
1046-
it('should not match folder w/o starred items', () => {
1047-
// given
1048-
const folder: TFolder = mockTFolderWithChildren('TestEmptyFolder');
1049-
const sortSpec: CustomSortSpec = {
1050-
targetFoldersPaths: ['/'],
1051-
groups: [{
1052-
type: CustomSortGroupType.StarredOnly
1053-
}]
1054-
}
1055-
const starredPluginInstance: Partial<Starred_PluginInstance> = {
1056-
findStarredFile: jest.fn( function(filePath: findStarredFile_pathParam): TFile | null {
1057-
return filePath.path === 'Some parent folder/References.md' ? {} as TFile : null
1058-
})
1059-
}
1060-
1061-
// when
1062-
const result = determineSortingGroup(folder, sortSpec, {
1063-
starredPluginInstance: starredPluginInstance as Starred_PluginInstance
1064-
} as ProcessingContext)
1065-
1066-
// then
1067-
expect(result).toEqual({
1068-
groupIdx: 1, // The lastIdx+1, group not determined
1069-
isFolder: true,
1070-
sortString: "TestEmptyFolder",
1071-
sortStringWithExt: "TestEmptyFolder",
1072-
1073-
ctime: 0,
1074-
mtime: 0,
1075-
path: 'TestEmptyFolder',
1076-
folder: {
1077-
children: expect.any(Array),
1078-
isRoot: expect.any(Function),
1079-
name: "TestEmptyFolder",
1080-
parent: {},
1081-
path: "TestEmptyFolder",
1082-
vault: {}
1083-
}
1084-
});
1085-
expect(starredPluginInstance.findStarredFile).toHaveBeenCalledTimes(folder.children.filter(f => (f as any).isRoot === undefined).length)
1086-
})
1087-
it('should match folder with one starred item', () => {
1088-
// given
1089-
const folder: TFolder = mockTFolderWithChildren('TestEmptyFolder');
1090-
const sortSpec: CustomSortSpec = {
1091-
targetFoldersPaths: ['/'],
1092-
groups: [{
1093-
type: CustomSortGroupType.StarredOnly
1094-
}]
1095-
}
1096-
const starredPluginInstance: Partial<Starred_PluginInstance> = {
1097-
findStarredFile: jest.fn(function (filePath: findStarredFile_pathParam): TFile | null {
1098-
return filePath.path === 'Some parent folder/Child file 2 created as newest, not modified at all.md' ? {} as TFile : null
1099-
})
1100-
}
1101-
1102-
// when
1103-
const result = determineSortingGroup(folder, sortSpec, {
1104-
starredPluginInstance: starredPluginInstance as Starred_PluginInstance
1105-
} as ProcessingContext)
1106-
1107-
// then
1108-
expect(result).toEqual({
1109-
groupIdx: 0,
1110-
isFolder: true,
1111-
sortString: "TestEmptyFolder",
1112-
sortStringWithExt: "TestEmptyFolder",
1113-
1114-
ctime: 0,
1115-
mtime: 0,
1116-
path: 'TestEmptyFolder',
1117-
folder: {
1118-
children: expect.any(Array),
1119-
isRoot: expect.any(Function),
1120-
name: "TestEmptyFolder",
1121-
parent: {},
1122-
path: "TestEmptyFolder",
1123-
vault: {}
1124-
}
1125-
});
1126-
// assume optimized checking of starred items -> first match ends the check
1127-
expect(starredPluginInstance.findStarredFile).toHaveBeenCalledTimes(2)
1004+
expect(bookmarksPluginInstance.determineBookmarkOrder).toHaveBeenCalledTimes(1)
11281005
})
11291006
})
11301007
describe('CustomSortGroupType.HasIcon', () => {

src/test/unit/sorting-spec-processor.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ with-metadata: Pages
3535
> a-z by-metadata:
3636
/: with-icon:
3737
with-icon: RiClock24
38-
starred:
39-
/:files starred:
40-
/folders starred:
38+
bookmarked:
39+
/:files bookmarked:
40+
/folders bookmarked:
4141
4242
:::: folder of bookmarks
4343
< by-bookmarks-order
@@ -100,9 +100,9 @@ target-folder: tricky folder 2
100100
> a-z by-metadata:
101101
/:files with-icon:
102102
/folders:files with-icon: RiClock24
103-
/folders:files starred:
104-
/:files starred:
105-
/folders starred:
103+
/folders:files bookmarked:
104+
/:files bookmarked:
105+
/folders bookmarked:
106106
107107
target-folder: folder of bookmarks
108108
order-asc: by-bookmarks-order
@@ -195,12 +195,12 @@ const expectedSortSpecsExampleA: { [key: string]: CustomSortSpec } = {
195195
type: CustomSortGroupType.HasIcon,
196196
iconName: 'RiClock24'
197197
}, {
198-
type: CustomSortGroupType.StarredOnly
198+
type: CustomSortGroupType.BookmarkedOnly
199199
}, {
200-
type: CustomSortGroupType.StarredOnly,
200+
type: CustomSortGroupType.BookmarkedOnly,
201201
filesOnly: true
202202
}, {
203-
type: CustomSortGroupType.StarredOnly,
203+
type: CustomSortGroupType.BookmarkedOnly,
204204
foldersOnly: true
205205
}, {
206206
type: CustomSortGroupType.Outsiders

0 commit comments

Comments
 (0)