From de122ad0454029e92a2b17f5eddde3fa192adb8b Mon Sep 17 00:00:00 2001 From: Test Date: Sat, 4 Apr 2026 13:55:42 +0200 Subject: [PATCH] feat: include Type definitions in command palette's dynamic commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit extractVaultTypes now also reads entries where isA === 'Type' and adds their title, so "New " commands appear as soon as a Type is defined — not only after an instance of that type exists. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/hooks/commands/typeCommands.ts | 7 ++++++- src/hooks/useCommandRegistry.test.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) 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', () => {