fix(webui): preserve file edit stats and left-truncate long paths (#6388)

* fix(webui): preserve file edit stats and truncate paths from start (NAN-332)

* fix(webui): remove redundant collapsed diff line totals

* fix(webui): include full paths in image edit hints
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-22 14:34:36 +08:00
1 parent b45048d415
commit f9257c3548
16 files changed
+160 -46

No files matched your search

+41 -14
View File
@@ -1,4 +1,4 @@
import { useEffect, useState, type KeyboardEvent, type MouseEvent } from "react";
import { useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent, type MouseEvent, type HTMLAttributes } from "react";
import { File, FileCode2, FileImage, FileJson2, FileText, FileVideo2, type LucideIcon } from "lucide-react";
import { useTranslation } from "react-i18next";
import { FileActions, useFilePreviewLoader } from "@/components/FileActions";
@@ -32,6 +32,7 @@ interface FileReferenceChipProps {
tooltipPath?: string;
display?: "name" | "path";
showIcon?: boolean;
truncateFromStart?: boolean;
active?: boolean;
className?: string;
textClassName?: string;
@@ -45,6 +46,7 @@ export function FileReferenceChip({
tooltipPath,
display = "name",
showIcon = true,
truncateFromStart = false,
active = false,
className,
textClassName,
@@ -68,18 +70,19 @@ export function FileReferenceChip({
setTooltipOpen(false);
onOpen(targetPath);
};
const Text = truncateFromStart ? StartTruncatedText : "span";
const onKeyDown = (event: KeyboardEvent) => {
if (event.key !== "Enter" && event.key !== " ") return;
openPreview(event);
};
return (
<FileActions path={targetPath}>
<FileActions path={targetPath} className={truncateFromStart ? "min-w-0" : undefined}>
<TooltipProvider>
<Tooltip open={tooltipOpen} onOpenChange={setTooltipOpen}>
<TooltipTrigger asChild>
<span
onContextMenuCapture={() => setTooltipOpen(false)}
className={cn("not-prose inline-flex max-w-full align-baseline leading-[inherit]", className)}
className={cn("not-prose inline-flex max-w-full align-baseline leading-[inherit]", truncateFromStart && "min-w-0", className)}
>
<span
data-testid={testId}
@@ -90,6 +93,7 @@ export function FileReferenceChip({
onKeyDown={interactive ? onKeyDown : undefined}
className={cn(
"inline-flex max-w-full items-baseline gap-[0.28em] font-medium leading-[inherit]",
truncateFromStart && "min-w-0",
interactive
? "text-sky-600 transition-colors hover:text-sky-700 dark:text-sky-300 dark:hover:text-sky-200"
: "text-muted-foreground",
@@ -100,11 +104,12 @@ export function FileReferenceChip({
)}
>
{showIcon ? <FileReferenceIcon kind={kind} className="translate-y-[0.12em]" /> : null}
<span
<Text
data-sheen-text={active ? displayText : undefined}
className={cn(
"min-w-0 max-w-full [overflow-wrap:anywhere] sm:truncate",
active && "streaming-text-sheen file-reference-sheen",
"min-w-0 max-w-full",
!truncateFromStart && "[overflow-wrap:anywhere] sm:truncate",
active && !truncateFromStart && "streaming-text-sheen file-reference-sheen",
textClassName,
)}
>
@@ -116,26 +121,28 @@ export function FileReferenceChip({
) : (
displayText
)}
</span>
</Text>
</span>
</span>
</TooltipTrigger>
<TooltipContent
aria-label={imageQuickLook ? t("filePreview.aria") : undefined}
aria-label={truncateFromStart ? fullPath : imageQuickLook ? t("filePreview.aria") : undefined}
side="top"
align="center"
align={truncateFromStart ? "start" : "center"}
sideOffset={8}
collisionPadding={12}
className={cn(
"rounded-control text-popover-foreground",
imageQuickLook && truncateFromStart && "space-y-2",
imageQuickLook
? "w-max max-w-[calc(100vw-2rem)] p-2"
: "max-w-[min(38rem,calc(100vw-2rem))] break-all px-2.5 py-1.5 font-mono text-[11px] leading-snug",
? cn("w-max p-2", truncateFromStart ? "max-w-[min(38rem,calc(100vw-2rem))]" : "max-w-[calc(100vw-2rem)]")
: cn("max-w-[min(38rem,calc(100vw-2rem))] px-2.5 py-1.5 font-mono text-[11px] leading-snug", truncateFromStart ? "text-left [overflow-wrap:anywhere]" : "break-all"),
)}
>
{imageQuickLook
? tooltipOpen ? <FileImageQuickLook key={targetPath} path={targetPath} /> : null
: fullPath}
{truncateFromStart ? <span className="block max-w-full select-text whitespace-pre-wrap text-left font-mono text-[11px] leading-snug [overflow-wrap:anywhere]">{fullPath.split(/([\\/])/).map((part, index) => (
<span key={index}>{part}{/^[\\/]$/.test(part) ? <wbr /> : null}</span>
))}</span> : !imageQuickLook ? fullPath : null}
{imageQuickLook && tooltipOpen ? <FileImageQuickLook key={targetPath} path={targetPath} /> : null}
</TooltipContent>
</Tooltip>
</TooltipProvider>
@@ -143,6 +150,26 @@ export function FileReferenceChip({
);
}
function StartTruncatedText({ children, className, ...props }: HTMLAttributes<HTMLSpanElement> & { "data-sheen-text"?: string }) {
const container = useRef<HTMLSpanElement>(null);
const content = useRef<HTMLSpanElement>(null);
const [clipped, setClipped] = useState(false);
useLayoutEffect(() => {
const update = () => setClipped(content.current!.getBoundingClientRect().width > container.current!.getBoundingClientRect().width);
const observer = new ResizeObserver(update);
observer.observe(container.current!);
observer.observe(content.current!);
update();
return () => observer.disconnect();
}, []);
return <span ref={container} className={cn("inline-flex items-baseline overflow-hidden whitespace-nowrap", className)}>
{clipped ? <span aria-hidden className="shrink-0">…</span> : null}
<span className="flex min-w-0 justify-end overflow-hidden">
<span ref={content} className={cn("shrink-0", props["data-sheen-text"] && "streaming-text-sheen file-reference-sheen")} {...props}>{children}</span>
</span>
</span>;
}
/** Only loads after the normal hover/focus delay, through the session's guarded preview API. */
function FileImageQuickLook({ path }: { path: string }) {
const { t } = useTranslation();
@@ -108,17 +108,21 @@ function FileEditRow({
? t("message.fileEditPreparing", { defaultValue: "Preparing file edit…" })
: (
<span className="flex min-w-0 items-center gap-1.5 overflow-hidden whitespace-nowrap">
<FileReferenceChip
path={edit.path}
previewPath={edit.absolute_path || edit.path}
onOpen={onOpenFilePreview}
display="path"
showIcon={false}
active={editing}
className="min-w-0"
textClassName="truncate text-[12px]"
testId="activity-file-reference"
/>
<span className="flex min-w-0 shrink overflow-hidden">
<FileReferenceChip
path={edit.path}
tooltipPath={edit.absolute_path || edit.path}
previewPath={edit.absolute_path || edit.path}
onOpen={onOpenFilePreview}
display="path"
showIcon={false}
active={editing}
className="min-w-0"
truncateFromStart
textClassName="text-[12px]"
testId="activity-file-reference"
/>
</span>
{hasCountedDiff ? <DiffPair added={edit.added} deleted={edit.deleted} /> : null}
</span>
)}
@@ -194,10 +198,6 @@ function FileUnifiedDiff({
: EMPTY_VISIBLE_DIFF,
[lineLimit, renderableDiff, shouldRenderBody, totalLineCount],
);
const lineCountLabel = t("message.fileEditDiffLineCount", {
count: diff.truncated ? `${totalLineCount}+` : totalLineCount,
defaultValue: "{{count}} lines",
});
const viewDiffLabel = shouldAutoCollapse
? tx("message.fileEditViewLargeDiff", "View large diff")
: tx("message.fileEditViewDiff", "View diff");
@@ -319,7 +319,6 @@ function FileUnifiedDiff({
aria-hidden
/>
<span className="min-w-0 flex-1">{viewDiffLabel}</span>
<span className="shrink-0 text-muted-foreground">{lineCountLabel}</span>
</button>
<DisclosureContent id={contentId} open={open} onExitComplete={releaseBody}>
{shouldRenderBody ? renderBody() : null}
-1
View File
@@ -2538,7 +2538,6 @@
"turnLatencyTitle": "Response time (end-to-end)",
"fileEditViewDiff": "View changes",
"fileEditViewLargeDiff": "Expand changes",
"fileEditDiffLineCount": "{{count}} lines",
"fileEditUnchangedLinesHidden": "{{count}} unchanged lines hidden",
"fileEditShowMoreLines": "Show {{count}} more lines",
"fileEditShowFewerLines": "Show fewer lines",
-1
View File
@@ -2160,7 +2160,6 @@
"turnLatencyTitle": "Tiempo de respuesta (extremo a extremo)",
"fileEditViewDiff": "Ver cambios",
"fileEditViewLargeDiff": "Expandir cambios",
"fileEditDiffLineCount": "{{count}} líneas",
"fileEditUnchangedLinesHidden": "{{count}} líneas sin cambios ocultas",
"fileEditShowMoreLines": "Mostrar {{count}} líneas más",
"fileEditShowFewerLines": "Mostrar menos líneas",
-1
View File
@@ -2159,7 +2159,6 @@
"turnLatencyTitle": "Temps de réponse (de bout en bout)",
"fileEditViewDiff": "Voir les modifications",
"fileEditViewLargeDiff": "Déplier les modifications",
"fileEditDiffLineCount": "{{count}} lignes",
"fileEditUnchangedLinesHidden": "{{count}} lignes inchangées masquées",
"fileEditShowMoreLines": "Afficher {{count}} lignes de plus",
"fileEditShowFewerLines": "Afficher moins de lignes",
-1
View File
@@ -2159,7 +2159,6 @@
"turnLatencyTitle": "Waktu respons (ujung ke ujung)",
"fileEditViewDiff": "Lihat perubahan",
"fileEditViewLargeDiff": "Perluas perubahan",
"fileEditDiffLineCount": "{{count}} baris",
"fileEditUnchangedLinesHidden": "{{count}} baris tidak berubah disembunyikan",
"fileEditShowMoreLines": "Tampilkan {{count}} baris lagi",
"fileEditShowFewerLines": "Tampilkan lebih sedikit baris",
-1
View File
@@ -2159,7 +2159,6 @@
"turnLatencyTitle": "応答時間(全行程)",
"fileEditViewDiff": "変更を表示",
"fileEditViewLargeDiff": "変更を展開",
"fileEditDiffLineCount": "{{count}} 行",
"fileEditUnchangedLinesHidden": "未変更の {{count}} 行を非表示",
"fileEditShowMoreLines": "さらに {{count}} 行を表示",
"fileEditShowFewerLines": "表示行数を減らす",
-1
View File
@@ -2159,7 +2159,6 @@
"turnLatencyTitle": "응답 시간(엔드투엔드)",
"fileEditViewDiff": "변경 보기",
"fileEditViewLargeDiff": "변경 펼치기",
"fileEditDiffLineCount": "{{count}}줄",
"fileEditUnchangedLinesHidden": "변경되지 않은 {{count}}줄 숨김",
"fileEditShowMoreLines": "{{count}}줄 더 보기",
"fileEditShowFewerLines": "간략히 보기",
-1
View File
@@ -2352,7 +2352,6 @@
"turnLatencyTitle": "Tempo de resposta (ponta a ponta)",
"fileEditViewDiff": "Ver alterações",
"fileEditViewLargeDiff": "Expandir alterações",
"fileEditDiffLineCount": "{{count}} linhas",
"fileEditUnchangedLinesHidden": "{{count}} linhas inalteradas ocultas",
"fileEditShowMoreLines": "Mostrar mais {{count}} linhas",
"fileEditShowFewerLines": "Mostrar menos linhas",
-1
View File
@@ -2159,7 +2159,6 @@
"turnLatencyTitle": "Thời gian phản hồi (end-to-end)",
"fileEditViewDiff": "Xem thay đổi",
"fileEditViewLargeDiff": "Mở rộng thay đổi",
"fileEditDiffLineCount": "{{count}} dòng",
"fileEditUnchangedLinesHidden": "Đã ẩn {{count}} dòng không đổi",
"fileEditShowMoreLines": "Hiển thị thêm {{count}} dòng",
"fileEditShowFewerLines": "Hiển thị ít dòng hơn",
-1
View File
@@ -2538,7 +2538,6 @@
"turnLatencyTitle": "回复耗时",
"fileEditViewDiff": "查看修改",
"fileEditViewLargeDiff": "展开修改",
"fileEditDiffLineCount": "{{count}} 行",
"fileEditUnchangedLinesHidden": "已隐藏 {{count}} 行未修改内容",
"fileEditShowMoreLines": "显示剩余 {{count}} 行",
"fileEditShowFewerLines": "收起部分行",
-1
View File
@@ -2158,7 +2158,6 @@
"turnLatencyTitle": "回覆耗時",
"fileEditViewDiff": "檢視修改",
"fileEditViewLargeDiff": "展開修改",
"fileEditDiffLineCount": "{{count}} 行",
"fileEditUnchangedLinesHidden": "已隱藏 {{count}} 行未修改內容",
"fileEditShowMoreLines": "顯示其餘 {{count}} 行",
"fileEditShowFewerLines": "收起部分行",
@@ -471,7 +471,7 @@ describe("AgentActivityCluster", () => {
expect(screen.queryByText("Edited files")).not.toBeInTheDocument();
const fileRef = screen.getByTestId("activity-file-reference");
expect(fileRef).toHaveTextContent("src/app.tsx");
expect(fileRef).toHaveAttribute("aria-label", "src/app.tsx");
expect(fileRef).toHaveAttribute("aria-label", "/Users/renxubin/project/src/app.tsx");
expect(screen.queryByTestId("activity-header-file-reference")).not.toBeInTheDocument();
expect(screen.queryByTestId("file-edit-diff")).not.toBeInTheDocument();
for (const diffPair of screen.getAllByTestId("activity-diff-pair")) {
@@ -794,8 +794,7 @@ describe("AgentActivityCluster", () => {
const toggle = screen.getByTestId("file-edit-diff-toggle");
expect(toggle).toHaveAttribute("aria-expanded", "false");
expect(toggle).toHaveTextContent("Expand changes");
expect(toggle).toHaveTextContent("165 lines");
expect(toggle).toHaveTextContent(/^Expand changes$/);
expect(screen.queryByTestId("file-edit-diff")).not.toBeInTheDocument();
expect(screen.queryByText("line-1")).not.toBeInTheDocument();
@@ -883,8 +882,7 @@ describe("AgentActivityCluster", () => {
const toggle = screen.getByTestId("file-edit-diff-toggle");
expect(toggle).toHaveAttribute("aria-expanded", "false");
expect(toggle).toHaveTextContent("View changes");
expect(toggle).toHaveTextContent("3 lines");
expect(toggle).toHaveTextContent(/^View changes$/);
expect(screen.queryByTestId("file-edit-diff")).not.toBeInTheDocument();
expect(screen.queryByText("return <New />;")).not.toBeInTheDocument();