From 0ca1dbfbcc932def56f029224a47ac75531110d7 Mon Sep 17 00:00:00 2001 From: Sylvie Crowe <107814465+oneirocosm@users.noreply.github.com> Date: Mon, 7 Oct 2024 09:58:12 -0700 Subject: [PATCH] Back Arrow goes back to existing parent (#979) This change makes the preview back arrow take you back to a parent directory that already exists if you are stuck in a bad state. this prevents it from opening a directory that doesn't exist as a file, which can happen if you use the typeahead to reach a file that doesn't exist inside a directory that doesn't exist. --- frontend/app/view/preview/preview.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/frontend/app/view/preview/preview.tsx b/frontend/app/view/preview/preview.tsx index 4829cdfc2..82d9ca90c 100644 --- a/frontend/app/view/preview/preview.tsx +++ b/frontend/app/view/preview/preview.tsx @@ -509,8 +509,12 @@ export class PreviewModel implements ViewModel { } } - async goParentDirectory() { - const fileInfo = await globalStore.get(this.statFile); + async goParentDirectory({ fileInfo = null }: { fileInfo?: FileInfo | null }) { + // optional parameter needed for recursive case + const defaultFileInfo = await globalStore.get(this.statFile); + if (fileInfo === null) { + fileInfo = defaultFileInfo; + } if (fileInfo == null) { this.updateOpenFileModalAndError(false); return true; @@ -520,6 +524,11 @@ export class PreviewModel implements ViewModel { const newFileInfo = await RpcApi.RemoteFileJoinCommand(WindowRpcClient, [fileInfo.path, ".."], { route: makeConnRoute(conn), }); + if (newFileInfo.path != "" && newFileInfo.notfound) { + console.log("does not exist, ", newFileInfo.path); + this.goParentDirectory({ fileInfo: newFileInfo }); + return; + } console.log(newFileInfo.path); this.updateOpenFileModalAndError(false); this.goHistory(newFileInfo.path); @@ -694,7 +703,7 @@ export class PreviewModel implements ViewModel { } if (keyutil.checkKeyPressed(e, "Cmd:ArrowUp")) { // handle up directory - this.goParentDirectory(); + this.goParentDirectory({}); return true; } const openModalOpen = globalStore.get(this.openFileModal);