Spaces:
Running
Running
Commit ·
6243bd8
1
Parent(s): 7323886
commit initial 09-12-2025 008
Browse files- src/App.js +46 -0
src/App.js
CHANGED
|
@@ -198,6 +198,51 @@ ${selectedCode}
|
|
| 198 |
setActiveFile(remaining[0] || "");
|
| 199 |
};
|
| 200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
const handleChangeLanguage = (langId) => {
|
| 202 |
setFiles((prev) => ({
|
| 203 |
...prev,
|
|
@@ -260,6 +305,7 @@ ${selectedCode}
|
|
| 260 |
{openMenu === "file" && (
|
| 261 |
<div className="ide-menu-dropdown">
|
| 262 |
<button onClick={handleNewFile}>New File</button>
|
|
|
|
| 263 |
<button onClick={handleSaveLocal}>Save (Local)</button>
|
| 264 |
<button onClick={handleDownloadFile}>Download File</button>
|
| 265 |
</div>
|
|
|
|
| 198 |
setActiveFile(remaining[0] || "");
|
| 199 |
};
|
| 200 |
|
| 201 |
+
// 🔁 NEW: Rename file
|
| 202 |
+
const handleRenameFile = () => {
|
| 203 |
+
if (!activeFile) return;
|
| 204 |
+
|
| 205 |
+
const newName = window.prompt(
|
| 206 |
+
"Enter new file name (with extension):",
|
| 207 |
+
activeFile
|
| 208 |
+
);
|
| 209 |
+
if (!newName || newName === activeFile) return;
|
| 210 |
+
|
| 211 |
+
// prevent overwriting other file
|
| 212 |
+
if (files[newName]) {
|
| 213 |
+
setOutput(`❌ A file named "${newName}" already exists.`);
|
| 214 |
+
setOpenMenu(null);
|
| 215 |
+
return;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
const oldFile = files[activeFile];
|
| 219 |
+
|
| 220 |
+
// infer language from new extension if possible
|
| 221 |
+
let newLangId = oldFile.language;
|
| 222 |
+
const dotIndex = newName.lastIndexOf(".");
|
| 223 |
+
if (dotIndex !== -1) {
|
| 224 |
+
const newExt = newName.slice(dotIndex);
|
| 225 |
+
const match = LANGUAGE_OPTIONS.find((l) => l.ext === newExt);
|
| 226 |
+
if (match) {
|
| 227 |
+
newLangId = match.id;
|
| 228 |
+
}
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
setFiles((prev) => {
|
| 232 |
+
const copy = { ...prev };
|
| 233 |
+
delete copy[activeFile];
|
| 234 |
+
copy[newName] = {
|
| 235 |
+
...oldFile,
|
| 236 |
+
language: newLangId,
|
| 237 |
+
};
|
| 238 |
+
return copy;
|
| 239 |
+
});
|
| 240 |
+
|
| 241 |
+
setActiveFile(newName);
|
| 242 |
+
setOpenMenu(null);
|
| 243 |
+
setOutput(`✅ Renamed "${activeFile}" to "${newName}".`);
|
| 244 |
+
};
|
| 245 |
+
|
| 246 |
const handleChangeLanguage = (langId) => {
|
| 247 |
setFiles((prev) => ({
|
| 248 |
...prev,
|
|
|
|
| 305 |
{openMenu === "file" && (
|
| 306 |
<div className="ide-menu-dropdown">
|
| 307 |
<button onClick={handleNewFile}>New File</button>
|
| 308 |
+
<button onClick={handleRenameFile}>Rename File</button>
|
| 309 |
<button onClick={handleSaveLocal}>Save (Local)</button>
|
| 310 |
<button onClick={handleDownloadFile}>Download File</button>
|
| 311 |
</div>
|