Use the shared truncate and firstLine in App, Palette and useDetails

This commit is contained in:
Callum Alpass committed 2026-11-02 23:04:44 +11:00
1 parent f2ae9ae080
commit 346212ba5f
3 files changed
+4 -20

No files matched your search

+2 -11
View File
@@ -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;
}
+1 -4
View File
@@ -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;
}
+1 -5
View File
@@ -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;
}