Skip to content

Commit 0ca1dbf

Browse files
authored
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.
1 parent 92fd371 commit 0ca1dbf

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

frontend/app/view/preview/preview.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,12 @@ export class PreviewModel implements ViewModel {
509509
}
510510
}
511511

512-
async goParentDirectory() {
513-
const fileInfo = await globalStore.get(this.statFile);
512+
async goParentDirectory({ fileInfo = null }: { fileInfo?: FileInfo | null }) {
513+
// optional parameter needed for recursive case
514+
const defaultFileInfo = await globalStore.get(this.statFile);
515+
if (fileInfo === null) {
516+
fileInfo = defaultFileInfo;
517+
}
514518
if (fileInfo == null) {
515519
this.updateOpenFileModalAndError(false);
516520
return true;
@@ -520,6 +524,11 @@ export class PreviewModel implements ViewModel {
520524
const newFileInfo = await RpcApi.RemoteFileJoinCommand(WindowRpcClient, [fileInfo.path, ".."], {
521525
route: makeConnRoute(conn),
522526
});
527+
if (newFileInfo.path != "" && newFileInfo.notfound) {
528+
console.log("does not exist, ", newFileInfo.path);
529+
this.goParentDirectory({ fileInfo: newFileInfo });
530+
return;
531+
}
523532
console.log(newFileInfo.path);
524533
this.updateOpenFileModalAndError(false);
525534
this.goHistory(newFileInfo.path);
@@ -694,7 +703,7 @@ export class PreviewModel implements ViewModel {
694703
}
695704
if (keyutil.checkKeyPressed(e, "Cmd:ArrowUp")) {
696705
// handle up directory
697-
this.goParentDirectory();
706+
this.goParentDirectory({});
698707
return true;
699708
}
700709
const openModalOpen = globalStore.get(this.openFileModal);

0 commit comments

Comments
 (0)