Skip to content

Commit b0d2140

Browse files
authored
Merge pull request #186 from SebastianMC/185-drop-backward-compatibility-and-require-1-7-2
#185 drop backward compatibility and require Obsidian 1.7.2 or newer
2 parents d3e21b2 + 5c4202f commit b0d2140

13 files changed

+942
-789
lines changed

package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-custom-sort",
3-
"version": "2.1.15",
3+
"version": "3.0.0",
44
"description": "Custom Sort plugin for Obsidian (https://obsidian.md)",
55
"main": "main.js",
66
"scripts": {
@@ -24,12 +24,11 @@
2424
"builtin-modules": "3.3.0",
2525
"esbuild": "0.17.3",
2626
"eslint": "^8.29.0",
27-
"jest": "^28.1.1",
28-
"monkey-around": "^2.3.0",
29-
"obsidian": "^0.15.4",
30-
"obsidian-1.4.11": "npm:[email protected]",
31-
"ts-jest": "^28.0.5",
32-
"tslib": "2.4.0",
33-
"typescript": "4.7.4"
27+
"jest": "^29.7.0",
28+
"monkey-around": "^3.0.0",
29+
"obsidian": "^1.7.2",
30+
"ts-jest": "^29.2.5",
31+
"tslib": "2.8.1",
32+
"typescript": "5.7.2"
3433
}
3534
}

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: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
import {
22
FrontMatterCache,
33
MetadataCache,
4-
Plugin,
5-
requireApiVersion,
64
TAbstractFile,
75
TFile,
86
TFolder,
97
Vault
108
} from 'obsidian';
11-
import {
12-
determineStarredStatusOf,
13-
Starred_PluginInstance
14-
} from '../utils/StarredPluginSignature';
159
import {
1610
determineIconOf,
1711
ObsidianIconFolder_PluginInstance
@@ -40,7 +34,6 @@ export interface ProcessingContext {
4034
// For internal transient use
4135
plugin?: CustomSortPluginAPI // to hand over the access to App instance to the sorting engine
4236
_mCache?: MetadataCache
43-
starredPluginInstance?: Starred_PluginInstance
4437
bookmarksPluginInstance?: BookmarksPluginInterface,
4538
iconFolderPluginInstance?: ObsidianIconFolder_PluginInstance
4639
}
@@ -495,14 +488,6 @@ export const determineSortingGroup = function (entry: TFile | TFolder, spec: Cus
495488
}
496489
}
497490
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
506491
case CustomSortGroupType.BookmarkedOnly:
507492
if (ctx?.bookmarksPluginInstance) {
508493
const bookmarkOrder: number | undefined = ctx?.bookmarksPluginInstance.determineBookmarkOrder(entry.path)
@@ -732,28 +717,8 @@ export const determineBookmarksOrderIfNeeded = (folderItems: Array<FolderItemFor
732717
})
733718
}
734719

735-
// This function is a replacement for the Obsidian File Explorer function sort(...) up to Obsidian 1.6.0
736-
// when a major refactoring of sorting mechanics happened
737-
export const folderSort_vUpTo_1_6_0 = function (sortingSpec: CustomSortSpec, ctx: ProcessingContext) {
738-
739-
const fileExplorerView = this.fileExplorer ?? this.view // this.view replaces the former since 1.5.4 insider build
740-
const folderUnderSort = this.file as TFolder
741-
const sortOrder = this.sortOrder
742-
const allFileItemsCollection = fileExplorerView.fileItems
743-
744-
const items = folderSortCore(folderUnderSort, sortOrder, sortingSpec, allFileItemsCollection, ctx)
745-
746-
if (requireApiVersion && requireApiVersion("0.15.0")) {
747-
this.vChildren.setChildren(items);
748-
} else {
749-
this.children = items;
750-
}
751-
}
752-
753-
// This function is a replacement for the Obsidian File Explorer function getSortedFolderItems(...)
754-
// which first appeared in Obsidian 1.6.0 and simplified a bit the plugin integration point
755-
export const getSortedFolderItems_vFrom_1_6_0 = function (sortedFolder: TFolder, sortingSpec: CustomSortSpec, ctx: ProcessingContext) {
756-
const sortOrder = this.sortOrder
720+
export const getSortedFolderItems = function (sortedFolder: TFolder, sortingSpec: CustomSortSpec, ctx: ProcessingContext) {
721+
const sortOrder = this.sortOrder // this is bound to FileExplorer Obsidian component
757722
const allFileItemsCollection = this.fileItems
758723
return folderSortCore(sortedFolder, sortOrder, sortingSpec, allFileItemsCollection, ctx)
759724
}

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 {

0 commit comments

Comments
 (0)