diff --git a/src/ui/App.tsx b/src/ui/App.tsx index 8458320..e6645ab 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -46,6 +46,7 @@ import { ThreadView, type ConversationMouse, type ConversationTarget } from "./T import { Button, ResizeHandle } from "./Button.tsx"; import { HintBar } from "./HintBar.tsx"; import { bindingFor, commandsFor, fromCommand, hinted, hintsFor, keys, type Binding } from "../model/keymap.ts"; +import { firstLine, truncate } from "./text.ts"; import { useEvent } from "./useEvent.ts"; import { useQueue } from "./useQueue.ts"; import { useSecretRequest } from "./useSecretRequest.ts"; @@ -911,7 +912,7 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C ...(target.role === "user" ? turns.menuFor(target.messageId) : []), ]; if (target.kind === "message" && target.role === "user") turns.select(target.messageId); - openPicker({ placeholder: target.kind === "command" ? "Command" : target.role === "user" ? "Your message" : "Message", groups: [{ label: truncateLabel(target.kind === "command" ? target.command : target.text, 60), items }] }); + openPicker({ placeholder: target.kind === "command" ? "Command" : target.role === "user" ? "Your message" : "Message", groups: [{ label: truncate(firstLine(target.kind === "command" ? target.command : target.text), 60), items }] }); }; /** The right-click menu in the pull request view: its palette commands, as a picker. */ const openPullRequestMenu = () => @@ -1222,13 +1223,3 @@ function composerLineCount(composer: TextareaRenderable): number { function clampListWidth(columns: number, width: number): number { return Math.max(20, Math.min(columns, width - MIN_CONVERSATION_WIDTH)); } - -function truncateLabel(text: string, width: number): string { - const line = firstLine(text); - return line.length > width ? `${line.slice(0, width - 1)}…` : line; -} - -function firstLine(text: string): string { - const line = (text.trim().split("\n")[0] ?? "").replace(/\s+/g, " "); - return line.length > 100 ? `${line.slice(0, 99)}…` : line; -} diff --git a/src/ui/Palette.tsx b/src/ui/Palette.tsx index 80727a5..e2b2515 100644 --- a/src/ui/Palette.tsx +++ b/src/ui/Palette.tsx @@ -2,6 +2,7 @@ import type { PaletteEntry, PaletteGroup } from "../model/palette.ts"; import type { MouseEvent } from "@opentui/core"; import { ClickRow, wheelStep } from "./Button.tsx"; +import { truncate } from "./text.ts"; import { colors } from "./theme.ts"; /** @@ -75,7 +76,3 @@ export function entryKey(entry: PaletteEntry): string { return entry.kind === "command" ? `c:${entry.command.id}` : `t:${entry.threadId}`; } -function truncate(text: string, width: number): string { - const single = text.replace(/\s+/g, " "); - return single.length > width ? `${single.slice(0, Math.max(0, width - 1))}…` : single; -} diff --git a/src/ui/useDetails.ts b/src/ui/useDetails.ts index ae3e91f..8e104a9 100644 --- a/src/ui/useDetails.ts +++ b/src/ui/useDetails.ts @@ -8,6 +8,7 @@ import { keys, type Binding } from "../model/keymap.ts"; import type { Automations } from "./useAutomations.ts"; import type { Confirmation } from "./ConfirmBar.tsx"; import type { DiffState } from "./DiffView.tsx"; +import { firstLine } from "./text.ts"; /** The details column opens by itself on terminals at least this wide. */ const AUTO_WIDTH = 160; @@ -221,8 +222,3 @@ export function useDetails(deps: { } const messageOf = (error: unknown) => (error instanceof Error ? error.message : String(error)); - -function firstLine(text: string): string { - const line = (text.trim().split("\n")[0] ?? "").replace(/\s+/g, " "); - return line.length > 100 ? `${line.slice(0, 99)}…` : line; -}