feat(library): picker option to mark notes no_resolve

This commit is contained in:
afiqzudinhadi 2026-08-05 15:47:13 +08:00
parent 2686c3fa64
commit 16b8b242b8
4 changed files with 45 additions and 9 deletions

View file

@ -3,20 +3,22 @@ import { FuzzySuggestModal } from 'obsidian';
import type { ResolveCandidate } from 'packages/obsidian/src/library/types';
const SKIP_LABEL = 'Skip';
const NEVER_LABEL = 'Never resolve (mark no_resolve)';
interface PickerItem {
label: string;
index: number | null; // null = Skip
index: number | 'never' | null; // null = Skip, 'never' = mark no_resolve
}
/**
* Fuzzy picker for an ambiguous resolve() result. `pick()` resolves to the chosen candidate's
* index, or null when the user picks "Skip" / dismisses the modal (Esc, click-outside) without
* choosing -- both are treated identically by the caller (LibraryController.resolveType).
* index, 'never' when the user picks "Never resolve (mark no_resolve)", or null when the user
* picks "Skip" / dismisses the modal (Esc, click-outside) without choosing -- null is treated as
* a plain skip by the caller (LibraryController.resolveType).
*/
export class CandidatePickerModal extends FuzzySuggestModal<PickerItem> {
private settled = false;
private resolveFn?: (index: number | null) => void;
private resolveFn?: (index: number | 'never' | null) => void;
constructor(
app: App,
@ -29,7 +31,7 @@ export class CandidatePickerModal extends FuzzySuggestModal<PickerItem> {
}
getItems(): PickerItem[] {
return [...this.candidates.map((c, index) => ({ label: c.label, index })), { label: SKIP_LABEL, index: null }];
return [...this.candidates.map((c, index) => ({ label: c.label, index })), { label: SKIP_LABEL, index: null }, { label: NEVER_LABEL, index: 'never' as const }];
}
getItemText(item: PickerItem): string {
@ -45,13 +47,13 @@ export class CandidatePickerModal extends FuzzySuggestModal<PickerItem> {
this.contentEl.empty();
}
private settle(index: number | null): void {
private settle(index: number | 'never' | null): void {
if (this.settled) return;
this.settled = true;
this.resolveFn?.(index);
}
pick(): Promise<number | null> {
pick(): Promise<number | 'never' | null> {
return new Promise(resolve => {
this.resolveFn = resolve;
this.open();

View file

@ -208,7 +208,7 @@ export class LibraryController {
}
/** Opens the real candidate picker modal; tests override this method directly to avoid needing a real Obsidian modal. */
private async pickCandidate(filename: string, candidates: ResolveCandidate[]): Promise<number | null> {
private async pickCandidate(filename: string, candidates: ResolveCandidate[]): Promise<number | 'never' | null> {
const modal = new CandidatePickerModal(this.plugin.app, filename, candidates);
return await modal.pick();
}
@ -225,10 +225,17 @@ export class LibraryController {
let picked = 0;
let skipped = 0;
let marked = 0;
if (!dryRun) {
for (const entry of report.needsChoice) {
try {
const idx = await this.pickCandidate(entry.filename, entry.candidates);
if (idx === 'never') {
const content = await deps.readNote(entry.path);
await deps.writeNote(entry.path, patchFrontmatter(content, { no_resolve: 'true' }, { defaultType: spec.itemType }));
marked++;
continue;
}
const candidate = idx != null ? entry.candidates[idx] : undefined;
if (!candidate) {
skipped++;
@ -248,6 +255,7 @@ export class LibraryController {
const mode = dryRun ? 'DRY-RUN ' : '';
let msg = `Library ${mode}resolve (${spec.typeName}): ${report.resolved.length} resolved, ${report.ambiguous.length} ambiguous/no match`;
if (report.needsChoice.length) msg += `, ${picked} picked, ${skipped} skipped`;
if (marked) msg += `, ${marked} marked no-resolve`;
if (report.errors.length) msg += `, ${report.errors.length} errors (see console)`;
this.notify(msg, 0);
return report;