feat: configurable filter tags for recent files
New 'Filter tags' setting in Recent Files tab. Enter tag names one per line to pin specific tags as filter pills. Leave empty to auto-detect from frontmatter 'type' property (existing behavior).
This commit is contained in:
@@ -241,14 +241,34 @@ export class WaypointView extends ItemView {
|
||||
}
|
||||
|
||||
// ── Type filter bar ──
|
||||
const typeCounts: Record<string, number> = {};
|
||||
for (const file of this.plugin.recentFiles) {
|
||||
const tfile = this.app.vault.getAbstractFileByPath(file.path);
|
||||
if (tfile instanceof TFile) {
|
||||
const cache = this.app.metadataCache.getFileCache(tfile);
|
||||
const type = cache?.frontmatter?.type;
|
||||
if (type && typeof type === 'string') {
|
||||
typeCounts[type] = (typeCounts[type] || 0) + 1;
|
||||
const configuredTags = this.plugin.settings.recentFiles.filterTags;
|
||||
let typeCounts: Record<string, number> = {};
|
||||
|
||||
if (configuredTags.length > 0) {
|
||||
// Use configured tags — count occurrences in recent files
|
||||
for (const tag of configuredTags) {
|
||||
typeCounts[tag] = 0;
|
||||
}
|
||||
for (const file of this.plugin.recentFiles) {
|
||||
const tfile = this.app.vault.getAbstractFileByPath(file.path);
|
||||
if (tfile instanceof TFile) {
|
||||
const cache = this.app.metadataCache.getFileCache(tfile);
|
||||
const type = cache?.frontmatter?.type;
|
||||
if (type && typeof type === 'string' && typeCounts.hasOwnProperty(type)) {
|
||||
typeCounts[type]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Auto-detect from frontmatter `type` property
|
||||
for (const file of this.plugin.recentFiles) {
|
||||
const tfile = this.app.vault.getAbstractFileByPath(file.path);
|
||||
if (tfile instanceof TFile) {
|
||||
const cache = this.app.metadataCache.getFileCache(tfile);
|
||||
const type = cache?.frontmatter?.type;
|
||||
if (type && typeof type === 'string') {
|
||||
typeCounts[type] = (typeCounts[type] || 0) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -262,7 +282,9 @@ export class WaypointView extends ItemView {
|
||||
this.redraw();
|
||||
});
|
||||
// Type pills
|
||||
const sortedTypes = Object.entries(typeCounts).sort(([,a], [,b]) => b - a);
|
||||
const sortedTypes = configuredTags.length > 0
|
||||
? Object.entries(typeCounts) // preserve configured order
|
||||
: Object.entries(typeCounts).sort(([,a], [,b]) => b - a); // sort by count
|
||||
for (const [type, count] of sortedTypes) {
|
||||
const pill = filterBar.createSpan({ cls: `waypoint-recent-pill${this.recentFilesFilter === type ? ' is-active' : ''}` });
|
||||
pill.setText(`${type} ${count}`);
|
||||
|
||||
Reference in New Issue
Block a user