diff --git a/frontend/app/view/codeeditor/codeeditor.tsx b/frontend/app/view/codeeditor/codeeditor.tsx index 10fe3b4bbe..ea45410e98 100644 --- a/frontend/app/view/codeeditor/codeeditor.tsx +++ b/frontend/app/view/codeeditor/codeeditor.tsx @@ -144,7 +144,7 @@ export function CodeEditor({ blockId, text, language, filename, fileinfo, meta, const fileInfo = await RpcApi.RemoteFileJoinCommand(TabRpcClient, [filename], { route: makeConnRoute(meta.connection ?? ""), }); - setAbsPath(`${fileInfo.dir}/${fileInfo.name}`); + setAbsPath(fileInfo.path); } catch (e) { setAbsPath(filename); } diff --git a/frontend/app/view/preview/directorypreview.tsx b/frontend/app/view/preview/directorypreview.tsx index c72013eff0..4c8b57add2 100644 --- a/frontend/app/view/preview/directorypreview.tsx +++ b/frontend/app/view/preview/directorypreview.tsx @@ -455,13 +455,6 @@ function DirectoryTable({ ); } -function getNormFilePath(finfo: FileInfo): string { - if (finfo.isdir) { - return finfo.dir; - } - return finfo.dir + "/" + finfo.name; -} - interface TableBodyProps { bodyRef: React.RefObject; model: PreviewModel; @@ -525,7 +518,7 @@ function TableBody({ if (finfo == null) { return; } - const normPath = getNormFilePath(finfo); + const normPath = finfo.path; const fileName = finfo.path.split("/").pop(); let parentFileInfo: FileInfo; try { @@ -618,7 +611,7 @@ function TableBody({ { label: makeNativeLabel(PLATFORM, true, true), click: () => { - getApi().openNativePath(parentFileInfo.dir); + getApi().openNativePath(parentFileInfo.path); }, } ); diff --git a/frontend/app/view/preview/preview.tsx b/frontend/app/view/preview/preview.tsx index e3f008c170..fb9c14abc1 100644 --- a/frontend/app/view/preview/preview.tsx +++ b/frontend/app/view/preview/preview.tsx @@ -751,7 +751,7 @@ export class PreviewModel implements ViewModel { meta: { view: "term", controller: "shell", - "cmd:cwd": fileInfo.dir, + "cmd:cwd": fileInfo.path, connection: conn, }, }; @@ -764,7 +764,7 @@ export class PreviewModel implements ViewModel { label: makeNativeLabel(PLATFORM, true, true), click: async () => { const fileInfo = await globalStore.get(this.statFile); - getApi().openNativePath(fileInfo.dir); + getApi().openNativePath(fileInfo.path); }, }); } @@ -775,7 +775,7 @@ export class PreviewModel implements ViewModel { label: makeNativeLabel(PLATFORM, false, false), click: async () => { const fileInfo = await globalStore.get(this.statFile); - getApi().openNativePath(`${fileInfo.dir}/${fileInfo.name}`); + getApi().openNativePath(fileInfo.path); }, }); } @@ -1104,7 +1104,7 @@ const fetchSuggestions = async ( TabRpcClient, { suggestiontype: "file", - "file:cwd": fileInfo.dir, + "file:cwd": fileInfo.path, query: query, widgetid: reqContext.widgetid, reqnum: reqContext.reqnum, diff --git a/pkg/wavebase/wavebase.go b/pkg/wavebase/wavebase.go index 52b365124a..2d2c30064b 100644 --- a/pkg/wavebase/wavebase.go +++ b/pkg/wavebase/wavebase.go @@ -148,6 +148,17 @@ func ExpandHomeDirSafe(pathStr string) string { return path } +func ReplaceHomeDir(pathStr string) string { + homeDir := GetHomeDir() + if pathStr == homeDir { + return "~" + } + if strings.HasPrefix(pathStr, homeDir+"/") { + return "~" + pathStr[len(homeDir):] + } + return pathStr +} + func GetDomainSocketName() string { return filepath.Join(GetWaveDataDir(), DomainSocketBaseName) } diff --git a/pkg/wshrpc/wshremote/wshremote.go b/pkg/wshrpc/wshremote/wshremote.go index 1a6221b674..9d0e0a7188 100644 --- a/pkg/wshrpc/wshremote/wshremote.go +++ b/pkg/wshrpc/wshremote/wshremote.go @@ -586,7 +586,7 @@ func (impl *ServerImpl) RemoteListEntriesCommand(ctx context.Context, data wshrp func statToFileInfo(fullPath string, finfo fs.FileInfo, extended bool) *wshrpc.FileInfo { mimeType := fileutil.DetectMimeType(fullPath, finfo, extended) rtn := &wshrpc.FileInfo{ - Path: fullPath, + Path: wavebase.ReplaceHomeDir(fullPath), Dir: computeDirPart(fullPath), Name: finfo.Name(), Size: finfo.Size(), @@ -644,7 +644,7 @@ func (*ServerImpl) fileInfoInternal(path string, extended bool) (*wshrpc.FileInf finfo, err := os.Stat(cleanedPath) if os.IsNotExist(err) { return &wshrpc.FileInfo{ - Path: path, + Path: wavebase.ReplaceHomeDir(path), Dir: computeDirPart(path), NotFound: true, ReadOnly: checkIsReadOnly(cleanedPath, finfo, false),