fix: open tabs update path properly after parent folder is renamed
Signed-off-by: mellobacon <mellodev@outlook.com>
mellobacon committed
Nov 2, 2023 at 01:16 UTC
e1c2274810a3f52e523d5862ab0975eb180c354f
1 file changed
+14
-4
src/lib/File.ts
+14
-4
@@ -149,7 +149,7 @@ export async function moveFile(source: string, dest: string, file: string) {
149
150
try {
151
await fs.renameFile(file, `${dest}${path.sep}${filename}`);
152
- const tab = get(tabs).find(t => t.path === `${source}${path.sep}${filename}`);
152
+ const tab = get(tabs).find(t => t.path === `${source}${path.sep}${filename}`);
153
if (tab === undefined) return;
154
tab.path = `${dest}${path.sep}${filename}`;
155
refreshTabs();
@@ -226,11 +226,13 @@ export async function createFile(p) {
226
}
227
228
export async function renameFile(filename: string, oldpath: string) {
229
+ let isFile = false;
230
if (filename.length === 0) {
231
warn("Cannot rename file with length 0", {file: "File.ts", line: 230});
232
return false;
233
}
233
- if (await invoke("is_file", {path: oldpath}) && filename.includes(path.sep)) {
234
+ isFile = await invoke("is_file", {path: oldpath});
235
+ if (isFile && filename.includes(path.sep)) {
236
warn("Cannot rename from invalid file name", {file: "File.ts", line: 234});
237
return false;
238
}
@@ -242,8 +244,16 @@ export async function renameFile(filename: string, oldpath: string) {
244
error(`Cannot rename ${oldpath}. Error: ${error}`, {file: "File.ts", line: 242})
245
return false;
246
}
245
- let tab = get(tabs).find(t => t.active && t.isfile);
246
- renameTab(tab, filename, newpath);
247
+ if (isFile) {
248
+ let tab = get(tabs).find(t => t.active && t.isfile);
249
+ renameTab(tab, filename, newpath);
250
+ return true;
251
+ }
252
+ let openTabs = get(tabs).filter(t => t.path === `${oldpath}${path.sep}${t.label}`);
253
+ for (const tab of openTabs) {
254
+ tab.path = `${newpath}${path.sep}${tab.label}`;
255
+ }
256
+ refreshTabs();
257
return true;
258
}
259