The best way to control Claude Code, Codex and more from any computer or phone
fix(web): truncate draft project names in the middle (#18858)
Co-authored-by: bentbrain <28818884+bentbrain@users.noreply.github.com>
Liam Cullen committed
Oct 19, 2026 at 06:09 UTC
c803a806332900fa43688a8c4a9b49fda29208b3
4 files changed
+126
-5
apps/web/src/components/chat/DraftHeroHeadline.tsx
+6
-5
@@ -40,6 +40,7 @@ import {
40
} from "../ui/combobox";
41
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
42
import { InlineButton } from "../ui/button";
43
+import { DraftProjectName } from "./DraftProjectName";
44
import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
45
46
const ADD_PROJECT_VALUE = "add-project";
@@ -258,9 +259,9 @@ export function DraftHeroHeadline({
259
/>
260
}
261
>
261
- <span className="min-w-0 truncate">
262
- {isScratchDraft ? "No project" : (activeProjectDisplayName ?? "Choose a project")}
263
- </span>
262
+ <DraftProjectName
263
+ value={isScratchDraft ? "No project" : (activeProjectDisplayName ?? "Choose a project")}
264
+ />
265
</TooltipTrigger>
266
{activeProjectDisplayName && !isScratchDraft ? (
267
<TooltipPopup side="top">{activeProjectDisplayName}</TooltipPopup>
@@ -285,8 +286,8 @@ export function DraftHeroHeadline({
286
<ProjectFavicon project={entry.group} className="size-4 shrink-0" />
287
) : null}
288
<Tooltip>
288
- <TooltipTrigger render={<span className="min-w-0 flex-1 truncate text-sm" />}>
289
- {item.label}
289
+ <TooltipTrigger render={<span className="min-w-0 flex-1 text-sm" />}>
290
+ <DraftProjectName value={item.label} />
291
</TooltipTrigger>
292
<TooltipPopup side="top">{item.label}</TooltipPopup>
293
</Tooltip>
apps/web/src/components/chat/DraftProjectName.logic.test.ts
new
+39
@@ -0,0 +1,39 @@
1
+import { describe, expect, it } from "vite-plus/test";
2
+
3
+import { truncateProjectName } from "./DraftProjectName.logic";
4
+
5
+const measure = (text: string) => Array.from(text).length;
6
+
7
+describe("truncateProjectName", () => {
8
+ it("keeps distinguishing suffixes in one string without adding whitespace", () => {
9
+ expect(truncateProjectName("ExampleCompany-CustomerPortal-App", 19, measure)).toBe(
10
+ "ExampleCo…ortal-App",
11
+ );
12
+ expect(truncateProjectName("ExampleCompany-CustomerPortal-Env", 19, measure)).toBe(
13
+ "ExampleCo…ortal-Env",
14
+ );
15
+ });
16
+
17
+ it("leaves names that fit unchanged", () => {
18
+ expect(truncateProjectName("ShortRepo", 9, measure)).toBe("ShortRepo");
19
+ });
20
+
21
+ it("fits proportional character widths", () => {
22
+ const proportional = (text: string) =>
23
+ Array.from(text).reduce((width, character) => width + (character === "W" ? 3 : 1), 0);
24
+ expect(truncateProjectName("WWWW-project-App", 12, proportional)).toBe("WW…App");
25
+ });
26
+
27
+ it("keeps combining marks and emoji sequences intact", () => {
28
+ const value = "e\u0301👩💻-customer-portal-App";
29
+ const result = truncateProjectName(value, 18, measure);
30
+ expect(result.startsWith("e\u0301👩💻")).toBe(true);
31
+ expect(result.endsWith("App")).toBe(true);
32
+ expect(measure(result)).toBeLessThanOrEqual(18);
33
+ });
34
+
35
+ it("handles space for only the ellipsis or no text", () => {
36
+ expect(truncateProjectName("ExampleCompany", 1, measure)).toBe("…");
37
+ expect(truncateProjectName("ExampleCompany", 0, measure)).toBe("");
38
+ });
39
+});
apps/web/src/components/chat/DraftProjectName.logic.ts
new
+27
@@ -0,0 +1,27 @@
1
+const graphemes = new Intl.Segmenter(undefined, { granularity: "grapheme" });
2
+
3
+export function truncateProjectName(
4
+ value: string,
5
+ availableWidth: number,
6
+ measure: (text: string) => number,
7
+): string {
8
+ if (measure(value) <= availableWidth) return value;
9
+ if (measure("…") > availableWidth) return "";
10
+
11
+ const characters = Array.from(graphemes.segment(value), (part) => part.segment);
12
+ const candidate = (count: number) => {
13
+ const head = characters.slice(0, Math.floor(count / 2)).join("");
14
+ const tailCount = Math.ceil(count / 2);
15
+ const tail = tailCount > 0 ? characters.slice(-tailCount).join("") : "";
16
+ return `${head}…${tail}`;
17
+ };
18
+
19
+ let low = 0;
20
+ let high = characters.length - 1;
21
+ while (low < high) {
22
+ const count = Math.ceil((low + high) / 2);
23
+ if (measure(candidate(count)) <= availableWidth) low = count;
24
+ else high = count - 1;
25
+ }
26
+ return candidate(low);
27
+}
apps/web/src/components/chat/DraftProjectName.tsx
new
+54
@@ -0,0 +1,54 @@
1
+import { useLayoutEffect, useRef, useState } from "react";
2
+
3
+import { observeResize } from "~/lib/observeResize";
4
+
5
+import { truncateProjectName } from "./DraftProjectName.logic";
6
+
7
+export function DraftProjectName({ value }: { value: string }) {
8
+ const containerRef = useRef<HTMLSpanElement>(null);
9
+ const [displayName, setDisplayName] = useState(value);
10
+
11
+ useLayoutEffect(() => {
12
+ const container = containerRef.current;
13
+ const context = document.createElement("canvas").getContext("2d");
14
+ if (!container || !context) return;
15
+
16
+ const update = () => {
17
+ const style = getComputedStyle(container);
18
+ context.font = style.font;
19
+ context.letterSpacing = style.letterSpacing === "normal" ? "0px" : style.letterSpacing;
20
+ setDisplayName(
21
+ truncateProjectName(
22
+ value,
23
+ container.getBoundingClientRect().width,
24
+ (text) => context.measureText(text).width,
25
+ ),
26
+ );
27
+ };
28
+ update();
29
+ const stopObserving = observeResize(container, update);
30
+ document.fonts.addEventListener("loadingdone", update);
31
+ return () => {
32
+ stopObserving();
33
+ document.fonts.removeEventListener("loadingdone", update);
34
+ };
35
+ }, [value]);
36
+
37
+ return (
38
+ <span
39
+ ref={containerRef}
40
+ className="inline-grid min-w-0 max-w-full overflow-hidden align-baseline whitespace-nowrap"
41
+ >
42
+ {/* Keep the full name's intrinsic width so fitting the visible text cannot shrink its budget. */}
43
+ <span
44
+ aria-hidden="true"
45
+ className="invisible col-start-1 row-start-1 min-w-0 overflow-hidden select-none"
46
+ >
47
+ {value}
48
+ </span>
49
+ <span aria-label={value} className="col-start-1 row-start-1 min-w-0 overflow-hidden">
50
+ {displayName}
51
+ </span>
52
+ </span>
53
+ );
54
+}