Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { expect, it } from "vite-plus/test";

import { compactMenuBranchLabel } from "./ThreadGitControls.logic";

it("keeps emoji whole at both cuts of a long branch name", () => {
expect(compactMenuBranchLabel("feature/abc😀-long-branch-name-😀-for-menus")).toBe(
"feature/abc…-for-menus",
);
});
17 changes: 17 additions & 0 deletions apps/mobile/src/features/threads/ThreadGitControls.logic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations";

function truncateMiddle(value: string, maxLength: number): string {
if (value.length <= maxLength) {
return value;
}

const headLength = Math.ceil((maxLength - 1) / 2);
const tailStart = value.length - Math.floor((maxLength - 1) / 2);
const headEnd = splitsSurrogatePair(value, headLength) ? headLength - 1 : headLength;
const tailFrom = splitsSurrogatePair(value, tailStart) ? tailStart + 1 : tailStart;
return `${value.slice(0, headEnd)}…${value.slice(tailFrom)}`;
}

export function compactMenuBranchLabel(branch: string): string {
return truncateMiddle(branch, 24);
}
15 changes: 1 addition & 14 deletions apps/mobile/src/features/threads/ThreadGitControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,7 @@ import {
type TerminalMenuSession,
} from "../terminal/terminalMenu";
import { projectScriptMenuLabel } from "@t3tools/shared/projectScriptsCopy";

function truncateMiddle(value: string, maxLength: number): string {
if (value.length <= maxLength) {
return value;
}

const headLength = Math.ceil((maxLength - 1) / 2);
const tailLength = Math.floor((maxLength - 1) / 2);
return `${value.slice(0, headLength)}…${value.slice(value.length - tailLength)}`;
}

function compactMenuBranchLabel(branch: string): string {
return truncateMiddle(branch, 24);
}
import { compactMenuBranchLabel } from "./ThreadGitControls.logic";

function compactMenuStatus(gitStatus: VcsStatusResult | null, resolve: MessageResolver): string {
if (!gitStatus) {
Expand Down
28 changes: 28 additions & 0 deletions scripts/scenarios/git-menu-branch-keeps-whole-characters.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect } from "e2e";

import { run } from "./shell.ts";
import { runPromise } from "./t3.ts";
import { IOS, test } from "./t3-mobile.ts";

// The Git menu shows 12 units, "…" and the last 11; each emoji straddles one cut.
const BRANCH = "feature/abc😀-long-branch-name-😀-for-menus";

test(
"The Git menu's branch title keeps whole characters at both cuts",
IOS,
async ({ t3, app, screen }) => {
const project = await t3.project("demo");
await runPromise(run("git", ["checkout", "--quiet", "-b", BRANCH], { cwd: project }));
await t3.thread({ project, title: "Branch work", messages: ["first"] });
// A local simulator keeps the last run's pairing.
await app.clearState().catch(() => {});
await t3.open();

await screen.getByText("Branch work", { exact: false }).first().tap({ timeout: 120_000 });
await screen.getByRole("button", "Git controls").tap({ timeout: 60_000 });
const title = screen.getByText("feature/abc", { exact: false }).first();
await title.waitFor({ timeout: 30_000 });
await app.screenshot("git-menu");
await expect(title).toHaveText("feature/abc…-for-menus, Clean");
},
);
Loading