diff --git a/src/hooks/commands/typeCommands.ts b/src/hooks/commands/typeCommands.ts index 033aad2e..5048e66d 100644 --- a/src/hooks/commands/typeCommands.ts +++ b/src/hooks/commands/typeCommands.ts @@ -18,7 +18,12 @@ export function pluralizeType(type: string): string { export function extractVaultTypes(entries: VaultEntry[]): string[] { const typeSet = new Set() for (const e of entries) { - if (e.isA && e.isA !== 'Type' && !e.trashed) typeSet.add(e.isA) + if (e.trashed) continue + if (e.isA === 'Type' && e.title) { + typeSet.add(e.title) + } else if (e.isA && e.isA !== 'Type') { + typeSet.add(e.isA) + } } if (typeSet.size === 0) return DEFAULT_TYPES return Array.from(typeSet).sort() diff --git a/src/hooks/useCommandRegistry.test.ts b/src/hooks/useCommandRegistry.test.ts index dd3e7c54..823acce6 100644 --- a/src/hooks/useCommandRegistry.test.ts +++ b/src/hooks/useCommandRegistry.test.ts @@ -192,6 +192,33 @@ describe('extractVaultTypes', () => { ] as never[] expect(extractVaultTypes(entries)).toEqual(['Event', 'Person', 'Project', 'Note']) }) + + it('includes types from Type definition entries', () => { + const entries = [ + { path: '/book.md', title: 'Book', isA: 'Type', trashed: false }, + ] as never[] + const types = extractVaultTypes(entries) + expect(types).toContain('Book') + }) + + it('includes types from both definitions and instances', () => { + const entries = [ + { path: '/book.md', title: 'Book', isA: 'Type', trashed: false }, + { path: '/hp.md', title: 'Harry Potter', isA: 'Book', trashed: false }, + { path: '/person.md', title: 'Person', isA: 'Type', trashed: false }, + ] as never[] + const types = extractVaultTypes(entries) + expect(types).toContain('Book') + expect(types).toContain('Person') + expect(types).toHaveLength(2) + }) + + it('excludes trashed Type definition entries', () => { + const entries = [ + { path: '/book.md', title: 'Book', isA: 'Type', trashed: true }, + ] as never[] + expect(extractVaultTypes(entries)).toEqual(['Event', 'Person', 'Project', 'Note']) + }) }) describe('groupSortKey', () => {