From 3a4b862e818c69fff6f3a3c67b50c51aa00c03e9 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 23 Mar 2026 22:35:26 -0500 Subject: [PATCH] refac --- src/lib/components/chat/FileNav.svelte | 57 ++++++++++++++++++- .../chat/FileNav/FileNavToolbar.svelte | 38 +++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) diff --git a/src/lib/components/chat/FileNav.svelte b/src/lib/components/chat/FileNav.svelte index 6c4fb1544..3ae9bd812 100644 --- a/src/lib/components/chat/FileNav.svelte +++ b/src/lib/components/chat/FileNav.svelte @@ -89,6 +89,54 @@ let loading = false; let error: string | null = null; + // ── Navigation history ────────────────────────────────────────────── + type NavEntry = { path: string; file: string | null }; + let navHistory: NavEntry[] = []; + let navIndex = -1; + let navigatingHistory = false; + + $: canGoBack = navIndex > 0; + $: canGoForward = navIndex < navHistory.length - 1; + + const pushNavHistory = (path: string, file: string | null = null) => { + if (navigatingHistory) return; + // Skip if this is the same as the current entry + const current = navHistory[navIndex]; + if (current && current.path === path && current.file === file) return; + // Truncate forward history when navigating to a new location + if (navIndex < navHistory.length - 1) { + navHistory = navHistory.slice(0, navIndex + 1); + } + navHistory = [...navHistory, { path, file }]; + navIndex = navHistory.length - 1; + }; + + const goBack = async () => { + if (!canGoBack) return; + navigatingHistory = true; + navIndex -= 1; + const entry = navHistory[navIndex]; + await loadDir(entry.path); + if (entry.file) { + const fileName = entry.file.split('/').pop() ?? ''; + await openEntry({ name: fileName, type: 'file', size: 0 }); + } + navigatingHistory = false; + }; + + const goForward = async () => { + if (!canGoForward) return; + navigatingHistory = true; + navIndex += 1; + const entry = navHistory[navIndex]; + await loadDir(entry.path); + if (entry.file) { + const fileName = entry.file.split('/').pop() ?? ''; + await openEntry({ name: fileName, type: 'file', size: 0 }); + } + navigatingHistory = false; + }; + // ── File preview state ─────────────────────────────────────────────── let selectedFile: string | null = null; let previewPort: number | null = null; @@ -259,6 +307,7 @@ clearFilePreview(); currentPath = path; savedPath = path; + pushNavHistory(path); const result = await listFiles(terminal.url, terminal.key, path); loading = false; @@ -284,10 +333,12 @@ return; } + const filePath = `${currentPath}${entry.name}`; + pushNavHistory(currentPath, filePath); + const terminal = selectedTerminal; if (!terminal) return; - const filePath = `${currentPath}${entry.name}`; selectedFile = filePath; fileLoading = true; clearFilePreview(); @@ -659,6 +710,10 @@ breadcrumbs={buildBreadcrumbs(currentPath)} {selectedFile} {loading} + {canGoBack} + {canGoForward} + onGoBack={goBack} + onGoForward={goForward} onNavigate={loadDir} onRefresh={() => { if (selectedFile) { diff --git a/src/lib/components/chat/FileNav/FileNavToolbar.svelte b/src/lib/components/chat/FileNav/FileNavToolbar.svelte index fcf61c0ef..3a8906f19 100644 --- a/src/lib/components/chat/FileNav/FileNavToolbar.svelte +++ b/src/lib/components/chat/FileNav/FileNavToolbar.svelte @@ -20,6 +20,12 @@ export let onUploadFiles: (files: File[]) => void = () => {}; export let onMove: (source: string, destFolder: string) => void = () => {}; + // Back / forward navigation + export let canGoBack = false; + export let canGoForward = false; + export let onGoBack: () => void = () => {}; + export let onGoForward: () => void = () => {}; + let dragOverCrumb: number | null = null; let uploadInput: HTMLInputElement; @@ -32,6 +38,38 @@
+ + + + + + + + + +