From 637cd136c2271baf4787815bc8bc25241626a943 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 23 Mar 2026 22:28:17 -0500 Subject: [PATCH] refac --- src/lib/components/chat/FileNav.svelte | 20 +++++ .../chat/FileNav/FileEntryRow.svelte | 77 +++++++++++++++++-- 2 files changed, 91 insertions(+), 6 deletions(-) diff --git a/src/lib/components/chat/FileNav.svelte b/src/lib/components/chat/FileNav.svelte index adb8bdf6d..6c4fb1544 100644 --- a/src/lib/components/chat/FileNav.svelte +++ b/src/lib/components/chat/FileNav.svelte @@ -487,6 +487,25 @@ await loadDir(currentPath); }; + // ── Rename ────────────────────────────────────────────────────────── + const handleRename = async (oldPath: string, newName: string) => { + const terminal = selectedTerminal; + if (!terminal || !newName) return; + + const dir = oldPath.substring(0, oldPath.lastIndexOf('/') + 1) || currentPath; + const destination = `${dir}${newName}`; + + if (oldPath === destination) return; + + const result = await moveEntry(terminal.url, terminal.key, oldPath, destination); + if ('error' in result) { + toast.error(result.error); + } else { + toast.success($i18n.t('Renamed to {{name}}', { name: newName })); + } + await loadDir(currentPath); + }; + // ── Lifecycle ──────────────────────────────────────────────────────── onMount(async () => { const terminal = getTerminal(); @@ -1041,6 +1060,7 @@ onDownload={downloadFile} onDelete={requestDelete} onMove={handleMove} + onRename={handleRename} /> {/each} diff --git a/src/lib/components/chat/FileNav/FileEntryRow.svelte b/src/lib/components/chat/FileNav/FileEntryRow.svelte index c260c6000..8c0b3806d 100644 --- a/src/lib/components/chat/FileNav/FileEntryRow.svelte +++ b/src/lib/components/chat/FileNav/FileEntryRow.svelte @@ -1,5 +1,5 @@
  • @@ -83,7 +116,12 @@ ); } }} - on:click={() => onOpen(entry)} + on:click={() => { + if (!renaming) onOpen(entry); + }} + on:dblclick|preventDefault|stopPropagation={() => { + startRename(); + }} > {#if entry.type === 'directory'} @@ -103,10 +141,25 @@ /> {/if} - - {entry.name} - - {#if entry.type === 'file' && entry.size !== undefined} + {#if renaming} + + { + if (e.key === 'Enter') { e.preventDefault(); submitRename(); } + if (e.key === 'Escape') { e.preventDefault(); cancelRename(); } + }} + on:blur={submitRename} + on:click|stopPropagation + /> + {:else} + + {entry.name} + + {/if} + {#if entry.type === 'file' && entry.size !== undefined && !renaming} {formatFileSize(entry.size)} {/if} @@ -151,6 +204,18 @@ {/if} + +