Skip to content

Commit b12712a

Browse files
BunsDevclaude
andauthored
Location row: shorten long paths from the left in code, not CSS (#7)
The direction:rtl trick rendered the leading "/" at the end of the path ("…/26f5e17b/"). tailPath() now keeps whole trailing segments under a length budget and prefixes "…"; e2e asserts the shown text is a real suffix of the full path with no stray separator. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 0ba066a commit b12712a

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎apps/desktop/e2e/app.spec.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ test("⇧⌘N creates a worktree thread and the header shows its branch and path
158158
const pathTitle = await page.locator(".location .location-path").getAttribute("title");
159159
expect(pathTitle).toContain(path.join(home, "worktrees"));
160160
expect(fs.existsSync(path.join(pathTitle!, "README.md"))).toBe(true);
161+
// Long paths are shortened from the left, keeping whole trailing segments and no stray separators.
162+
const shown = await page.locator(".location .location-path").innerText();
163+
expect(shown.startsWith("…") || shown === pathTitle).toBe(true);
164+
expect(pathTitle!.endsWith(shown.replace(/^…/, ""))).toBe(true);
165+
expect(shown.endsWith("/")).toBe(false);
161166
await expect(page.locator(".location .location-kind")).toHaveText("⑂");
162167
await page.locator(".location button", { hasText: "Copy path" }).click();
163168
expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(pathTitle);

‎apps/desktop/src/renderer/components/ThreadView.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ export function shortenHome(p: string): string {
2727
return p.replace(/^\/(?:Users|home)\/[^/]+(?=\/|$)/, "~").replace(/^[A-Za-z]:\\Users\\[^\\]+(?=\\|$)/, "~");
2828
}
2929

30+
/** Keeps the tail of a long path (the part that distinguishes worktrees), dropping whole leading segments. */
31+
export function tailPath(p: string, max = 60): string {
32+
if (p.length <= max) return p;
33+
const parts = p.split("/");
34+
let out = "";
35+
for (let i = parts.length - 1; i > 0; i--) {
36+
const next = "/" + parts[i] + out;
37+
if (next.length + 1 > max) break;
38+
out = next;
39+
}
40+
return "…" + (out || p.slice(-(max - 1)));
41+
}
42+
3043
export function ThreadView({ thread, project, items, onSend, onStop, onAnswer, onUpdate, showChanges, onToggleChanges, changedCount, models, modelsError, inputRef, onOpenPath, onOpenTerminal, platform }: Props) {
3144
const scroller = useRef<HTMLDivElement>(null);
3245
const busy = thread.status === "running" || thread.status === "waiting";
@@ -59,7 +72,7 @@ export function ThreadView({ thread, project, items, onSend, onStop, onAnswer, o
5972
{thread.worktree ? "⑂" : "▸"}
6073
</span>
6174
{thread.worktree && <code className="location-branch" title="Branch">{thread.worktree.branch}</code>}
62-
<code className="location-path" title={thread.cwd}>{shortenHome(thread.cwd)}</code>
75+
<code className="location-path" title={thread.cwd}>{tailPath(shortenHome(thread.cwd))}</code>
6376
<span className="spacer" />
6477
<button className="btn small ghost" onClick={() => onOpenPath(thread.cwd)} title={`Open ${thread.cwd} in ${platform === "darwin" ? "Finder" : "the file manager"}`}>
6578
{platform === "darwin" ? "Finder" : "Files"}

‎apps/desktop/src/renderer/styles.css‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,5 +255,5 @@ kbd { font: 11px var(--mono); background: rgba(255,255,255,.08); border: 1px sol
255255
.location { display: flex; align-items: center; gap: 8px; padding: 4px 16px; border-bottom: 1px solid var(--line); background: var(--bg-1); flex: none; font-size: 12px; color: var(--fg-2); min-width: 0; }
256256
.location-kind { width: 14px; text-align: center; color: var(--accent); }
257257
.location-branch { background: rgba(124, 156, 255, .12); border: 1px solid rgba(124, 156, 255, .35); color: var(--accent); border-radius: 999px; padding: 0 8px; font-size: 11.5px; white-space: nowrap; }
258-
.location-path { color: var(--fg-1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; direction: rtl; text-align: left; }
258+
.location-path { color: var(--fg-1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
259259
.location .btn.small { padding: 1px 8px; font-size: 12px; }

0 commit comments

Comments
 (0)