fix: resolve custom type color and icon in all autocomplete contexts (#84)

* fix: resolve custom type color and icon in all autocomplete contexts

Custom types (e.g., Evergreen, Recipe) appeared grey in wikilink [[,
@-mention, Cmd+P, and search autocompletes because getTypeColor() was
called without the custom color key from the Type document.

Root causes:
- Editor.tsx: getTypeColor(group) missing typeEntryMap[group]?.color
- useNoteSearch.ts: getTypeColor(e.isA) missing custom color lookup
- SearchPanel.tsx: type badge had no color styling at all

Fixes:
- Extract buildTypeEntryMap to shared utility in typeColors.ts
- Pass custom color key in all autocomplete code paths
- Add type icon (Phosphor) to the left of each result in NoteSearchList
- Add TypeIcon to WikilinkSuggestionItem and NoteAutocomplete

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* docs: add design file for autocomplete type color fix

Shows the fixed state: type icon on the left, colored type badge on
the right, untyped notes neutral grey with no icon.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Luca Rossi
2026-02-26 04:05:22 +01:00
committed by GitHub
parent 807a4904a2
commit 5b6bc64cd6
13 changed files with 155 additions and 59 deletions

View File

@@ -171,4 +171,21 @@ describe('useNoteSearch', () => {
})
expect(preventDefaultSpy).not.toHaveBeenCalled()
})
it('resolves custom type color from Type entries', () => {
const withTypes: VaultEntry[] = [
makeEntry({ path: '/vault/t/recipe.md', title: 'Recipe', isA: 'Type', color: 'orange', icon: 'cooking-pot' }),
makeEntry({ path: '/vault/pasta.md', title: 'Pasta', isA: 'Recipe', modifiedAt: 1700000010 }),
makeEntry({ path: '/vault/proj.md', title: 'My Project', isA: 'Project', modifiedAt: 1700000009 }),
]
const { result } = renderHook(() => useNoteSearch(withTypes, ''))
const pasta = result.current.results.find(r => r.title === 'Pasta')
expect(pasta?.noteType).toBe('Recipe')
expect(pasta?.typeColor).toBe('var(--accent-orange)')
expect(pasta?.TypeIcon).toBeDefined()
// Built-in type still works
const project = result.current.results.find(r => r.title === 'My Project')
expect(project?.typeColor).toBe('var(--accent-red)')
expect(project?.TypeIcon).toBeDefined()
})
})