diff --git a/web/app.js b/web/app.js index 2a75b1d..b8df43f 100644 --- a/web/app.js +++ b/web/app.js @@ -1405,17 +1405,12 @@ async function _resolveRefExistsBatch(ids) { } function _findRefLabelFromThread(refId) { - // Scan posts for [[ref:id]] tokens we've already resolved into chips — - // fall back to ref_id when unknown. - const t = state.currentThread; - if (!t) return refId; - for (const p of t.posts || []) { - const re = new RegExp(`\\[\\[ref:${refId}\\]\\]`); - if (re.test(p.content || '')) { - // No reliable per-chip label here without re-resolving; reuse refId. - break; - } - } + // Prefer the ref index (window._forgeRefs) — it carries the real filename + // (label). Falls back to ref_id only when the index hasn't loaded yet or + // the ref is unknown. + const idx = window._forgeRefs; + const hit = idx && idx.byId && idx.byId.get(refId); + if (hit && hit.label) return hit.label; return refId; } @@ -1428,6 +1423,9 @@ async function renderPinnedArea(t) { root.hidden = true; return; } + // Ensure the ref index is loaded so we can show real filenames (labels) + // instead of opaque ref ids. Cheap if already cached. + try { await loadRefIndex(); } catch (_) { /* offline; fall back to ids */ } root.hidden = false; root.innerHTML = `