diff --git a/src/lib/components/chat/FileNav.svelte b/src/lib/components/chat/FileNav.svelte index 8994b9f2e..795da2f4d 100644 --- a/src/lib/components/chat/FileNav.svelte +++ b/src/lib/components/chat/FileNav.svelte @@ -19,6 +19,7 @@ type FileEntry } from '$lib/apis/terminal'; import Folder from '../icons/Folder.svelte'; + import Document from '../icons/Document.svelte'; import Spinner from '../common/Spinner.svelte'; import ConfirmDialog from '../common/ConfirmDialog.svelte'; @@ -50,6 +51,9 @@ let creatingFolder = false; let newFolderName = ''; let newFolderInput: HTMLInputElement; + let creatingFile = false; + let newFileName = ''; + let newFileInput: HTMLInputElement; // ── Delete confirmation ────────────────────────────────────────────── let deleteTarget: { path: string; name: string } | null = null; @@ -257,6 +261,31 @@ await loadDir(currentPath); }; + // ── File creation ──────────────────────────────────────────────────── + const startNewFile = async () => { + creatingFile = true; + newFileName = ''; + await tick(); + newFileInput?.focus(); + }; + + const submitNewFile = async () => { + const name = newFileName.trim(); + creatingFile = false; + newFileName = ''; + if (!name) return; + + const terminal = selectedTerminal; + if (!terminal) return; + + const emptyFile = new File([''], name, { type: 'application/octet-stream' }); + const result = await uploadToTerminal(terminal.url, terminal.key, currentPath, emptyFile); + toast[result ? 'success' : 'error']( + $i18n.t(result ? 'File created' : 'Failed to create file') + ); + await loadDir(currentPath); + }; + // ── Delete ─────────────────────────────────────────────────────────── const handleDelete = async (path: string, name: string) => { const terminal = selectedTerminal; @@ -397,6 +426,7 @@ onNavigate={loadDir} onRefresh={() => loadDir(currentPath)} onNewFolder={startNewFolder} + onNewFile={startNewFile} onUploadFiles={handleUploadFiles} /> @@ -422,7 +452,7 @@