@setoelkahfi / svara / commits / 92c9074

fix: new path is named correctly after renaming

Signed-off-by: mellobacon <mellodev@outlook.com>

mellobacon committed Nov 2, 2023 at 20:36 UTC 92c907449d1bc9e7059276b22d36dec9f75b3339
1 file changed +12 -13
src/lib/File.ts
+12 -13
@@ -66,8 +66,8 @@ async function updateTree(directory, updateType = "") {
66 let tree;
67 try {
68 tree = await fs.readDir(directory, {recursive: true});
69 - } catch (error) {
70 - error(error);
69 + } catch (e) {
70 + error(e);
71 }
72 if (!tree || tree === undefined) {
73 error(`Cannot load directory: ${tree}.`, {file: "File.ts", line: 73});
@@ -153,8 +153,8 @@ export async function moveFile(source: string, dest: string, file: string) {
153 if (tab === undefined) return;
154 tab.path = `${dest}${path.sep}${filename}`;
155 refreshTabs();
156 - } catch (error) {
157 - error(`Cannot move ${file} into ${dest}. Error: ${error}`, {file: "File.ts", line: 159});
156 + } catch (e) {
157 + error(`Cannot move ${file} into ${dest}. Error: ${e}`, {file: "File.ts", line: 159});
158 }
159 }
160
@@ -212,15 +212,15 @@ export async function moveToTrash(p: string) {
212 export async function createFolder(p) {
213 try {
214 await fs.createDir(p);
215 - } catch (error) {
216 - error(`Cannot create folder in path ${p}. Error: ${error}`, {file: "File.ts", line: 216});
215 + } catch (e) {
216 + error(`Cannot create folder in path ${p}. Error: ${e}`, {file: "File.ts", line: 216});
217 }
218 }
219 export async function createFile(p) {
220 try {
221 await invoke("write_file", {path: p, content: "", enc: "UTF-8", hasBom: false});
222 - } catch (error) {
223 - error(`Cannot create file in path ${p}. Error: ${error}`, {file: "File.ts", line: 223});
222 + } catch (e) {
223 + error(`Cannot create file in path ${p}. Error: ${e}`, {file: "File.ts", line: 223});
224 }
225 addEditorTab(p, p.split(path.sep).pop());
226 }
@@ -236,12 +236,11 @@ export async function renameFile(filename: string, oldpath: string) {
236 warn("Cannot rename from invalid file name", {file: "File.ts", line: 234});
237 return false;
238 }
239 - let newpath = oldpath.replace(oldpath.split(path.sep).pop(), filename);
240 -
239 + let newpath = oldpath.substring(0, oldpath.lastIndexOf(oldpath.split(path.sep).at(-1))) + filename;
240 try {
241 await fs.renameFile(oldpath, newpath);
243 - } catch (error) {
244 - error(`Cannot rename ${oldpath}. Error: ${error}`, {file: "File.ts", line: 242})
242 + } catch (e) {
243 + error(`Cannot rename ${oldpath}. Error: ${e}`, {file: "File.ts", line: 242})
244 return false;
245 }
246 if (isFile) {
@@ -276,4 +275,4 @@ export function checkValidFileName(input: string) {
275 if (input.endsWith(".")) return false;
276 if (input === "") return false;
277 return true;
279 -}
\ No newline at end of file
278 +}