Open Text File if File Does Not Exist (#963)

This will open new files as empty text files for editing.
This commit is contained in:
Sylvie Crowe 2024-10-06 13:38:03 -07:00 committed by GitHub
parent 28f189bccd
commit 76ccd83c5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 4 deletions

View File

@ -58,9 +58,14 @@ func viewRun(cmd *cobra.Command, args []string) {
WriteStderr("[error] getting absolute path: %v\n", err)
return
}
_, err = os.Stat(absFile)
absParent, err := filepath.Abs(filepath.Dir(fileArg))
if err != nil {
WriteStderr("[error] getting absolute path of parent dir: %v\n", err)
return
}
_, err = os.Stat(absParent)
if err == fs.ErrNotExist {
WriteStderr("[error] file does not exist: %q\n", absFile)
WriteStderr("[error] parent directory does not exist: %q\n", absParent)
return
}
if err != nil {

View File

@ -432,9 +432,14 @@ export class PreviewModel implements ViewModel {
const fileInfo = await getFn(this.statFile);
const fileName = await getFn(this.statFilePath);
const editMode = getFn(this.editMode);
const parentFileInfo = await this.getParentInfo(fileInfo);
console.log(parentFileInfo);
if (parentFileInfo?.notfound ?? false) {
return { errorStr: `Parent Directory Not Found: ${fileInfo.path}` };
}
if (fileInfo?.notfound) {
return { errorStr: `File Not Found: ${fileInfo.path}` };
return { specializedView: "codeedit" };
}
if (mimeType == null) {
return { errorStr: `Unable to determine mimetype for: ${fileInfo.path}` };
@ -492,6 +497,18 @@ export class PreviewModel implements ViewModel {
services.ObjectService.UpdateObjectMeta(blockOref, updateMeta);
}
async getParentInfo(fileInfo: FileInfo): Promise<FileInfo | undefined> {
const conn = globalStore.get(this.connection);
try {
const parentFileInfo = await RpcApi.RemoteFileJoinCommand(WindowRpcClient, [fileInfo.path, ".."], {
route: makeConnRoute(conn),
});
return parentFileInfo;
} catch {
return undefined;
}
}
async goParentDirectory() {
const fileInfo = await globalStore.get(this.statFile);
if (fileInfo == null) {
@ -500,7 +517,7 @@ export class PreviewModel implements ViewModel {
}
const conn = globalStore.get(this.connection);
try {
const newFileInfo = await RpcApi.RemoteFileJoinCommand(WindowRpcClient, [fileInfo.dir, ".."], {
const newFileInfo = await RpcApi.RemoteFileJoinCommand(WindowRpcClient, [fileInfo.path, ".."], {
route: makeConnRoute(conn),
});
console.log(newFileInfo.path);