Link picker: refresh Properties view after write (no more go-away-and-back)

processFrontMatter updates the file but the open editor's Properties panel
lags until metadataCache re-indexes, so a just-linked/unlinked value didn't
show until you left and returned. After a link write, re-set the active view's
state to force a clean properties re-render (best-effort; the write already
succeeded regardless). Captain-verified live.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Titus 2026-07-17 09:39:48 +02:00
parent 4a0ec0f395
commit 06697bddbb

View file

@ -168,10 +168,30 @@ export class NoteLinker {
target[choice.key] = links.length ? links[0] : null;
}
});
await this.refreshPropertiesView(file);
const label = selected.length ? selected.map((e) => e.name).join(', ') : '(none)';
new Notice(`${choice.label}: ${label}`);
}
/**
* Nudge the Properties panel to repaint after a frontmatter write.
* processFrontMatter updates the file, but the open editor's Properties view
* lags until metadataCache re-indexes so a just-linked/unlinked value doesn't
* show until you leave and return. If the file is open in the active view,
* re-set its view state, which forces a clean re-render of the properties.
*/
private async refreshPropertiesView(file: TFile): Promise<void> {
const view = this.app.workspace.getActiveViewOfType(MarkdownView);
if (!view || view.file?.path !== file.path) return;
try {
const leaf = view.leaf;
const state = leaf.getViewState();
await leaf.setViewState({ ...state, active: true });
} catch {
/* refresh is best-effort — the write already succeeded */
}
}
/** id+name of every element of `target` type in the world (excludes self). */
private async fetchElementsOfType(
worldName: string,