diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs
index 62c0a91..f71b265 100644
--- a/src-tauri/src/commands.rs
+++ b/src-tauri/src/commands.rs
@@ -535,6 +535,27 @@ pub async fn delete_directory(path: String) -> Result<(), String> {
Ok(())
}
+#[tauri::command]
+pub async fn rename_path(old_path: String, new_path: String) -> Result<(), String> {
+ use std::fs;
+ use std::path::Path;
+
+ let old = Path::new(&old_path);
+ let new = Path::new(&new_path);
+
+ if !old.exists() {
+ return Err("Path does not exist".to_string());
+ }
+
+ if new.exists() {
+ return Err("Destination already exists".to_string());
+ }
+
+ fs::rename(old, new).map_err(|e| format!("Failed to rename: {}", e))?;
+
+ Ok(())
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 0d0901e..6db2820 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -158,6 +158,7 @@ pub fn run() {
create_directory,
delete_file,
delete_directory,
+ rename_path,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
diff --git a/src/lib/components/editor/FileBrowser.svelte b/src/lib/components/editor/FileBrowser.svelte
index 5c72801..8a5880b 100644
--- a/src/lib/components/editor/FileBrowser.svelte
+++ b/src/lib/components/editor/FileBrowser.svelte
@@ -39,7 +39,7 @@
// Dialog state
let dialog = $state<{
- type: "newFile" | "newFolder" | "delete" | null;
+ type: "newFile" | "newFolder" | "delete" | "rename" | null;
parentPath: string;
targetEntry: FileEntry | null;
}>({
@@ -81,6 +81,10 @@
dialog = { type: "delete", parentPath: "", targetEntry: entry };
}
+ function openRenameDialog(entry: FileEntry) {
+ dialog = { type: "rename", parentPath: "", targetEntry: entry };
+ }
+
function closeDialog() {
dialog = { type: null, parentPath: "", targetEntry: null };
}
@@ -106,6 +110,12 @@
closeDialog();
}
+ async function handleRename(newName: string) {
+ if (!dialog.targetEntry) return;
+ await editorStore.renamePath(dialog.targetEntry.path, newName);
+ closeDialog();
+ }
+
function handleNewFile() {
openNewFileDialog($currentDirectory);
}
@@ -211,6 +221,7 @@
currentDirectory={$currentDirectory}
onNewFile={openNewFileDialog}
onNewFolder={openNewFolderDialog}
+ onRename={openRenameDialog}
onDelete={openDeleteDialog}
onClose={closeContextMenu}
/>
@@ -250,6 +261,17 @@
/>
{/if}
+{#if dialog.type === "rename" && dialog.targetEntry}
+
+{/if}
+