Skip to content

Commit

Permalink
Merge pull request #186 from SebastianMC/185-drop-backward-compatibil…
Browse files Browse the repository at this point in the history
…ity-and-require-1-7-2

#185 drop backward compatibility and require Obsidian 1.7.2 or newer
  • Loading branch information
SebastianMC authored Jan 3, 2025
2 parents d3e21b2 + 5c4202f commit b0d2140
Show file tree
Hide file tree
Showing 13 changed files with 942 additions and 789 deletions.
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-custom-sort",
"version": "2.1.15",
"version": "3.0.0",
"description": "Custom Sort plugin for Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {
Expand All @@ -24,12 +24,11 @@
"builtin-modules": "3.3.0",
"esbuild": "0.17.3",
"eslint": "^8.29.0",
"jest": "^28.1.1",
"monkey-around": "^2.3.0",
"obsidian": "^0.15.4",
"obsidian-1.4.11": "npm:[email protected]",
"ts-jest": "^28.0.5",
"tslib": "2.4.0",
"typescript": "4.7.4"
"jest": "^29.7.0",
"monkey-around": "^3.0.0",
"obsidian": "^1.7.2",
"ts-jest": "^29.2.5",
"tslib": "2.8.1",
"typescript": "5.7.2"
}
}
1 change: 0 additions & 1 deletion src/custom-sort/custom-sort-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export enum CustomSortGroupType {
ExactSuffix,
ExactHeadAndTail, // Like W...n or Un...ed, which is shorter variant of typing the entire title
HasMetadataField, // Notes (or folder's notes) containing a specific metadata field
StarredOnly,
BookmarkedOnly,
HasIcon
}
Expand Down
8 changes: 1 addition & 7 deletions src/custom-sort/custom-sort-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export interface HasSortingTypes {

export interface HasGroupingTypes {
byBookmarks: number
byStarred: number
byIcon: number
total: number
}
Expand All @@ -31,10 +30,6 @@ export const checkByBookmark = (has: HasSortingOrGrouping, order?: CustomSortOrd
(order === CustomSortOrder.byBookmarkOrder || order === CustomSortOrder.byBookmarkOrderReverse) && has.sorting.byBookmarks++;
}

export const checkByStarred = (has: HasSortingOrGrouping, order?: CustomSortOrder, groupType?: CustomSortGroupType ) => {
groupType === CustomSortGroupType.StarredOnly && has.grouping.byStarred++;
}

export const checkByIcon = (has: HasSortingOrGrouping, order?: CustomSortOrder, groupType?: CustomSortGroupType ) => {
groupType === CustomSortGroupType.HasIcon && has.grouping.byIcon++;
}
Expand All @@ -45,7 +40,6 @@ export const checkStandardObsidian = (has: HasSortingOrGrouping, order?: CustomS

export const doCheck = (has: HasSortingOrGrouping, order?: CustomSortOrder, groupType?: CustomSortGroupType) => {
checkByBookmark(has, order, groupType)
checkByStarred(has, order, groupType)
checkByIcon(has, order, groupType)
checkStandardObsidian(has, order, groupType)

Expand All @@ -56,7 +50,7 @@ export const doCheck = (has: HasSortingOrGrouping, order?: CustomSortOrder, grou
export const collectSortingAndGroupingTypes = (sortSpec?: CustomSortSpec|null): HasSortingOrGrouping => {
const has: HasSortingOrGrouping = {
grouping: {
byIcon: 0, byStarred: 0, byBookmarks: 0, total: 0
byIcon: 0, byBookmarks: 0, total: 0
},
sorting: {
byBookmarks: 0, standardObsidian: 0, total: 0
Expand Down
39 changes: 2 additions & 37 deletions src/custom-sort/custom-sort.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import {
FrontMatterCache,
MetadataCache,
Plugin,
requireApiVersion,
TAbstractFile,
TFile,
TFolder,
Vault
} from 'obsidian';
import {
determineStarredStatusOf,
Starred_PluginInstance
} from '../utils/StarredPluginSignature';
import {
determineIconOf,
ObsidianIconFolder_PluginInstance
Expand Down Expand Up @@ -40,7 +34,6 @@ export interface ProcessingContext {
// For internal transient use
plugin?: CustomSortPluginAPI // to hand over the access to App instance to the sorting engine
_mCache?: MetadataCache
starredPluginInstance?: Starred_PluginInstance
bookmarksPluginInstance?: BookmarksPluginInterface,
iconFolderPluginInstance?: ObsidianIconFolder_PluginInstance
}
Expand Down Expand Up @@ -495,14 +488,6 @@ export const determineSortingGroup = function (entry: TFile | TFolder, spec: Cus
}
}
break
case CustomSortGroupType.StarredOnly:
if (ctx?.starredPluginInstance) {
const starred: boolean = determineStarredStatusOf(entry, aFile, ctx.starredPluginInstance)
if (starred) {
determined = true
}
}
break
case CustomSortGroupType.BookmarkedOnly:
if (ctx?.bookmarksPluginInstance) {
const bookmarkOrder: number | undefined = ctx?.bookmarksPluginInstance.determineBookmarkOrder(entry.path)
Expand Down Expand Up @@ -732,28 +717,8 @@ export const determineBookmarksOrderIfNeeded = (folderItems: Array<FolderItemFor
})
}

// This function is a replacement for the Obsidian File Explorer function sort(...) up to Obsidian 1.6.0
// when a major refactoring of sorting mechanics happened
export const folderSort_vUpTo_1_6_0 = function (sortingSpec: CustomSortSpec, ctx: ProcessingContext) {

const fileExplorerView = this.fileExplorer ?? this.view // this.view replaces the former since 1.5.4 insider build
const folderUnderSort = this.file as TFolder
const sortOrder = this.sortOrder
const allFileItemsCollection = fileExplorerView.fileItems

const items = folderSortCore(folderUnderSort, sortOrder, sortingSpec, allFileItemsCollection, ctx)

if (requireApiVersion && requireApiVersion("0.15.0")) {
this.vChildren.setChildren(items);
} else {
this.children = items;
}
}

// This function is a replacement for the Obsidian File Explorer function getSortedFolderItems(...)
// which first appeared in Obsidian 1.6.0 and simplified a bit the plugin integration point
export const getSortedFolderItems_vFrom_1_6_0 = function (sortedFolder: TFolder, sortingSpec: CustomSortSpec, ctx: ProcessingContext) {
const sortOrder = this.sortOrder
export const getSortedFolderItems = function (sortedFolder: TFolder, sortingSpec: CustomSortSpec, ctx: ProcessingContext) {
const sortOrder = this.sortOrder // this is bound to FileExplorer Obsidian component
const allFileItemsCollection = this.fileItems
return folderSortCore(sortedFolder, sortOrder, sortingSpec, allFileItemsCollection, ctx)
}
Expand Down
9 changes: 0 additions & 9 deletions src/custom-sort/sorting-spec-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,6 @@ const MetadataFieldIndicatorLexeme: string = 'with-metadata:'

const BookmarkedItemIndicatorLexeme: string = 'bookmarked:'

const StarredItemsIndicatorLexeme: string = 'starred:'

const IconIndicatorLexeme: string = 'with-icon:'

const CommentPrefix: string = '//'
Expand Down Expand Up @@ -1710,13 +1708,6 @@ export class SortingSpecProcessor {
foldersOnly: spec.foldersOnly,
matchFilenameWithExt: spec.matchFilenameWithExt
}
} else if (theOnly.startsWith(StarredItemsIndicatorLexeme)) {
return {
type: CustomSortGroupType.StarredOnly,
filesOnly: spec.filesOnly,
foldersOnly: spec.foldersOnly,
matchFilenameWithExt: spec.matchFilenameWithExt
}
} else {
// For non-three dots single text line assume exact match group
return {
Expand Down
Loading

0 comments on commit b0d2140

Please sign in to comment.