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.
This commit is contained in:
Sylvie Crowe 2024-10-07 09:58:12 -07:00 committed by GitHub
parent 92fd371fc9
commit 0ca1dbfbcc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);