Files
tolaria/src/utils/wikilinkColors.ts
lucaronin ee94ecb731 fix: unify wikilink resolution and disambiguate duplicate titles
- Create resolveEntry() in wikilink.ts: single case-insensitive resolution
  function that handles title, alias, filename stem, path suffix, and
  pipe syntax matching
- Replace findEntryByTarget (case-sensitive) and entryMatchesTarget
  (hardcoded /Laputa/ path) with unified resolveEntry
- Fix attachClickHandlers to insert path|title pipe syntax when multiple
  candidates share the same title (disambiguation)
- Update ai-context.ts resolveTarget to use unified resolution
- Add comprehensive tests for resolveEntry and disambiguation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 19:12:05 +01:00

34 lines
1.5 KiB
TypeScript

/**
* Wikilink color resolution: maps wikilink targets to their note-type accent color.
* Used by the WikiLink inline content renderer in the editor.
*/
import type { VaultEntry } from '../types'
import { getTypeColor } from './typeColors'
import { resolveEntry } from './wikilink'
/** Broken-link color: muted text to signal the target note doesn't exist */
const BROKEN_LINK_COLOR = 'var(--text-muted)'
/** Find a vault entry matching a wikilink target string.
* Delegates to the unified resolveEntry for consistent case-insensitive matching. */
export function findEntryByTarget(entries: VaultEntry[], target: string): VaultEntry | undefined {
return resolveEntry(entries, target)
}
/** Resolve the accent color for a given entry based on its type */
export function lookupColorForEntry(entries: VaultEntry[], entry: VaultEntry): string {
if (!entry.isA) return getTypeColor(null)
const typeEntry = entries.find(e => e.isA === 'Type' && e.title === entry.isA)
return getTypeColor(entry.isA, typeEntry?.color)
}
export interface WikilinkColorResult { color: string; isBroken: boolean }
/** Resolve the display color for a wikilink target */
export function resolveWikilinkColor(entries: VaultEntry[], target: string): WikilinkColorResult {
if (!entries.length) return { color: getTypeColor(null), isBroken: false }
const entry = findEntryByTarget(entries, target)
if (!entry) return { color: BROKEN_LINK_COLOR, isBroken: true }
return { color: lookupColorForEntry(entries, entry), isBroken: false }
}