Skip to content

Commit 1df39be

Browse files
edg-rclaude
andcommitted
feat(web): sidebar thread titles truncate in the middle
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d01b92c commit 1df39be

3 files changed

Lines changed: 32 additions & 7 deletions

File tree

‎apps/web/src/components/sidebar/SidebarThreadRow.tsx‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
10041004
isActive: props.isActive,
10051005
});
10061006

1007+
const titleDirection = textDirection(thread.title);
10071008
const title = isRenaming ? (
10081009
<ThreadRenameInput
10091010
title={renamingTitle}
@@ -1038,9 +1039,15 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
10381039
),
10391040
isRegeneratingTitle && "opacity-55",
10401041
)}
1041-
dir={textDirection(thread.title)}
1042+
dir={titleDirection}
10421043
>
1043-
{thread.title}
1044+
{/* The measured cut assumes left-to-right text, so RTL titles keep their end ellipsis. */}
1045+
<MiddleTruncate
1046+
value={thread.title}
1047+
{...(titleDirection === "rtl" ? { tail: 0 } : {})}
1048+
showTitle={false}
1049+
className="flex"
1050+
/>
10441051
</span>
10451052
);
10461053
const accessibleTitle = isRenaming ? null : <span className="sr-only">{thread.title}</span>;
@@ -1736,7 +1743,12 @@ export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props
17361743
thread.titleRegeneration != null && "opacity-55",
17371744
)}
17381745
>
1739-
{thread.title}
1746+
<MiddleTruncate
1747+
value={thread.title}
1748+
{...(textDirection(thread.title) === "rtl" ? { tail: 0 } : {})}
1749+
showTitle={false}
1750+
className="flex"
1751+
/>
17401752
</span>
17411753
<span id={`${props.resultId}-pr`} className="contents">
17421754
<ThreadSearchPullRequestNumber

‎apps/web/src/components/ui/middle-truncate.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ describe("splitForMiddleTruncate", () => {
2323
expect(splitForMiddleTruncate("t3/abcdefghijklmnopqrstuvwxyz")?.tail).toBe("qrstuvwxyz");
2424
});
2525

26+
it("starts a title's tail on a word", () => {
27+
expect(splitForMiddleTruncate("Debate Weaknesses in Bilateral Agreements")).toEqual({
28+
head: "Debate Weaknesses in Bilateral ",
29+
tail: "Agreements",
30+
});
31+
});
32+
33+
it("flattens line breaks so a value stays on one line", () => {
34+
expect(splitForMiddleTruncate("first\nsecond line of a label")?.head).not.toContain("\n");
35+
});
36+
2637
it("respects an explicit tail length", () => {
2738
expect(splitForMiddleTruncate("t3/clone-repo-to-other-machine", 6)?.tail).toBe("achine");
2839
});

‎apps/web/src/components/ui/middle-truncate.tsx‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ export function MiddleTruncate({
4242
{split ? (
4343
<>
4444
{/* The tail carries the ellipsis so it sits flush; a CSS ellipsis leaves a ragged gap. */}
45-
<span ref={headRef} className="peer min-w-0 overflow-hidden">
45+
<span ref={headRef} className="peer min-w-0 overflow-hidden whitespace-pre">
4646
{split.head}
4747
</span>
48-
<span className="shrink-0 peer-data-overflow:before:content-['…']">{split.tail}</span>
48+
<span className="shrink-0 whitespace-pre peer-data-overflow:before:content-['…']">
49+
{split.tail}
50+
</span>
4951
</>
5052
) : (
5153
// Keyed so React does not reuse the head node and its imperative clip.
@@ -92,14 +94,14 @@ function fitHead(head: HTMLElement) {
9294
const DEFAULT_TAIL = 10;
9395
const MAX_SEGMENT_TAIL = 16;
9496
const MIN_WORD_TAIL = 4;
95-
const WORD_BREAK = /[-_./]/;
97+
const WORD_BREAK = /[-_./\s]/;
9698

9799
export function splitForMiddleTruncate(
98100
value: string,
99101
tail?: number,
100102
): { head: string; tail: string } | null {
101103
// Split by code point to avoid cutting surrogate pairs into broken glyphs.
102-
const chars = Array.from(value);
104+
const chars = Array.from(value.replace(/[\r\n]+/g, " "));
103105
let keep = tail ?? DEFAULT_TAIL;
104106
if (tail === undefined) {
105107
const slash = chars.lastIndexOf("/");

0 commit comments

Comments
 (0)