fix: harden stale note rename and open flows

This commit is contained in:
lucaronin
2026-05-03 19:40:50 +02:00
parent 05a9aacd1e
commit c7b6832cb1
4 changed files with 82 additions and 6 deletions

View File

@@ -47,6 +47,16 @@ function isTitleKey(key: string): boolean {
return key.toLowerCase().replace(/\s+/g, '_') === 'title'
}
function safeString(value: unknown): string {
return typeof value === 'string' ? value : ''
}
function entryDisplayLabel(entry: VaultEntry): string {
return safeString(entry.title).trim()
|| safeString(entry.filename).trim()
|| 'Note'
}
interface TitleRenameDeps {
vaultPath: string
tabsRef: React.MutableRefObject<{ entry: VaultEntry; content: string }[]>
@@ -210,12 +220,12 @@ function buildTabManagementOptions(
void config.onMissingActiveVault?.(entry, error)
},
onMissingNotePath: (entry) => {
const label = entry.title.trim() || entry.filename
const label = entryDisplayLabel(entry)
config.setToastMessage(`"${label}" could not be opened because its file is missing or moved.`)
void config.reloadVault?.()
},
onUnreadableNoteContent: (entry) => {
const label = entry.title.trim() || entry.filename
const label = entryDisplayLabel(entry)
config.setToastMessage(`"${label}" could not be opened because it is not valid UTF-8 text.`)
},
}