diff --git a/src/lib/components/chat/FileNav.svelte b/src/lib/components/chat/FileNav.svelte index a59dc588d2..8811411b7a 100644 --- a/src/lib/components/chat/FileNav.svelte +++ b/src/lib/components/chat/FileNav.svelte @@ -1572,6 +1572,40 @@ } as BrowserRow); }; + // The path bar cannot tell a file from a folder + const goToPath = async (path: string) => { + const machine = selectedMachine; + const generation = loadGeneration; + const selector = effectiveMachineId, + session = chatId; + const filePath = path.replace(/\/$/, ''); + const fileName = filePath.split('/').pop(); + const parentPath = parentDirectoryPath(filePath); + const listing = + machine && !onSelectDirectory && isInsideFileRoot(parentPath) + ? await listFiles(machine, parentPath) + : null; + if (generation !== loadGeneration || selector !== effectiveMachineId || session !== chatId) + return; + const entry = listing?.entries.find( + (item) => item.type === 'file' && cleanEntryName(item.name) === fileName + ); + if (entry) { + await openEntry({ + ...entry, + name: fileName, + fullPath: filePath, + parentPath, + depth: 0, + rowIndex: -1 + } as BrowserRow); + } else if (initialFile && onBrowseDirectory) { + onBrowseDirectory(path); + } else { + await loadDir(path); + } + }; + const openContentMatch = async (match: MachineFileMatch, contentMatch: MachineContentMatch) => { await openFileMatch(match); fileSearchTarget = { @@ -2540,6 +2574,7 @@ onGoBack={goBack} onGoForward={goForward} onNavigate={initialFile && onBrowseDirectory ? onBrowseDirectory : loadDir} + onGoToPath={goToPath} listFolders={async (path) => { const machine = selectedMachine; const entries = diff --git a/src/lib/components/chat/FileNav/FileNavToolbar.svelte b/src/lib/components/chat/FileNav/FileNavToolbar.svelte index 8769dc3e34..61f0942430 100644 --- a/src/lib/components/chat/FileNav/FileNavToolbar.svelte +++ b/src/lib/components/chat/FileNav/FileNavToolbar.svelte @@ -25,6 +25,7 @@ export let onViewModeChange: (mode: 'grid' | 'list') => void = () => {}; export let onNavigate: (path: string) => void = () => {}; + export let onGoToPath: ((path: string) => void) | null = null; export let listFolders: ((path: string) => Promise) | null = null; export let onRefresh: () => void = () => {}; export let showSearch = false; @@ -83,7 +84,7 @@ const goToPath = () => { typingPath = false; - if (pathInput.value.trim()) onNavigate(resolve(pathInput.value)); + if (pathInput.value.trim()) (onGoToPath ?? onNavigate)(resolve(pathInput.value)); }; // Tab / Shift+Tab cycle through the folders matching the last name typed