From 9b76521a907b520db4b6c8f2338c74343bdf0089 Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Wed, 11 Feb 2026 14:24:29 +0000 Subject: [PATCH] fix(ui): improve recent folders path display (#147) --- .../src/components/folder-selection-view.tsx | 63 +++++++++++++++++-- packages/ui/src/styles/utilities.css | 10 +++ 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/packages/ui/src/components/folder-selection-view.tsx b/packages/ui/src/components/folder-selection-view.tsx index a77e3547..281ea084 100644 --- a/packages/ui/src/components/folder-selection-view.tsx +++ b/packages/ui/src/components/folder-selection-view.tsx @@ -254,12 +254,63 @@ const FolderSelectionView: Component = (props) => { function getDisplayPath(path: string): string { + if (!path) return path + + // macOS: /Users//... if (path.startsWith("/Users/")) { return path.replace(/^\/Users\/[^/]+/, "~") } + + // Linux: /home//... + if (path.startsWith("/home/")) { + return path.replace(/^\/home\/[^/]+/, "~") + } + + // Windows: C:\Users\\... (and the forward-slash variant) + if (/^[A-Za-z]:\\Users\\/.test(path)) { + return path.replace(/^[A-Za-z]:\\Users\\[^\\]+/, "~") + } + if (/^[A-Za-z]:\/Users\//.test(path)) { + return path.replace(/^[A-Za-z]:\/Users\/[^/]+/, "~") + } + return path } + function looksLikeWindowsPath(value: string): boolean { + if (!value) return false + // Drive letter (C:\...) or UNC (\\server\share\...) + return /^[A-Za-z]:[\\/]/.test(value) || /^\\\\[^\\]+\\[^\\]+/.test(value) + } + + function splitFolderPath(rawPath: string): { baseName: string; dirName: string } { + if (!rawPath) return { baseName: "", dirName: "" } + + const isWindows = looksLikeWindowsPath(rawPath) + const trimmed = rawPath.replace(/[\\/]+$/, "") + + // Root edge-cases ("/", "C:\\", "\\\\server\\share\\") + if (!trimmed) { + return { baseName: rawPath, dirName: "" } + } + + if (isWindows && /^[A-Za-z]:$/.test(trimmed)) { + return { baseName: `${trimmed}\\`, dirName: "" } + } + + const lastSlash = trimmed.lastIndexOf("/") + const lastBackslash = isWindows ? trimmed.lastIndexOf("\\") : -1 + const lastSep = Math.max(lastSlash, lastBackslash) + + if (lastSep < 0) { + return { baseName: trimmed, dirName: "" } + } + + const baseName = trimmed.slice(lastSep + 1) || trimmed + const dirName = trimmed.slice(0, lastSep) + return { baseName, dirName } + } + return ( <>
= (props) => {
- {folder.path.split("/").pop()} + {splitFolderPath(folder.path).baseName}
-
- {getDisplayPath(folder.path)} -
-
- {formatRelativeTime(folder.lastAccessed)} +
+ + {getDisplayPath(folder.path)} + + {formatRelativeTime(folder.lastAccessed)}
diff --git a/packages/ui/src/styles/utilities.css b/packages/ui/src/styles/utilities.css index b7609c9a..230f9bd0 100644 --- a/packages/ui/src/styles/utilities.css +++ b/packages/ui/src/styles/utilities.css @@ -153,6 +153,16 @@ @apply opacity-50; } +/* Truncate from the start (keeps end visible; good for paths) */ +.truncate-start { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + direction: rtl; + text-align: left; + unicode-bidi: plaintext; +} + /* Prevent iOS Safari auto-zoom on text input focus */ @media (pointer: coarse) { input[type="text"],