fix: clear stale editor state on vault switch

This commit is contained in:
lucaronin
2026-05-07 00:13:52 +02:00
parent 5c3a49d2ca
commit d211d89ab8
8 changed files with 469 additions and 84 deletions

View File

@@ -0,0 +1,20 @@
function normalizeVaultContainmentPath(path: string): string {
return path.replace(/\\/g, '/').replace(/\/+$/, '')
}
function compareVaultContainmentPath(path: string, vaultPath: string): [string, string] {
const normalizedPath = normalizeVaultContainmentPath(path)
const normalizedVaultPath = normalizeVaultContainmentPath(vaultPath)
const hasWindowsDrive = /^[a-z]:/i.test(normalizedPath) || /^[a-z]:/i.test(normalizedVaultPath)
return hasWindowsDrive
? [normalizedPath.toLowerCase(), normalizedVaultPath.toLowerCase()]
: [normalizedPath, normalizedVaultPath]
}
export function canWritePathToVault(path: string, vaultPath: string): boolean {
const trimmedVaultPath = vaultPath.trim()
if (!trimmedVaultPath) return true
const [targetPath, rootPath] = compareVaultContainmentPath(path, trimmedVaultPath)
if (!rootPath || !targetPath) return false
return targetPath === rootPath || targetPath.startsWith(`${rootPath}/`)
}