From f9257c35483a4e80ed27b731bc2fa38c45df1a35 Mon Sep 17 00:00:00 2001
From: chengyongru <61816729+chengyongru@users.noreply.github.com>
Date: Thu, 22 Oct 2026 14:34:36 +0800
Subject: [PATCH] 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
---
webui/browser/file-edit-path-fixture.tsx | 28 ++++++++
webui/browser/file-edit-path.spec.ts | 69 +++++++++++++++++++
webui/browser/fixture.tsx | 5 +-
webui/src/components/FileReferenceChip.tsx | 55 +++++++++++----
.../thread/activity/FileEditRow.tsx | 31 ++++-----
webui/src/i18n/locales/en/common.json | 1 -
webui/src/i18n/locales/es/common.json | 1 -
webui/src/i18n/locales/fr/common.json | 1 -
webui/src/i18n/locales/id/common.json | 1 -
webui/src/i18n/locales/ja/common.json | 1 -
webui/src/i18n/locales/ko/common.json | 1 -
webui/src/i18n/locales/pt-BR/common.json | 1 -
webui/src/i18n/locales/vi/common.json | 1 -
webui/src/i18n/locales/zh-CN/common.json | 1 -
webui/src/i18n/locales/zh-TW/common.json | 1 -
.../src/tests/agent-activity-cluster.test.tsx | 8 +--
16 files changed, 160 insertions(+), 46 deletions(-)
create mode 100644 webui/browser/file-edit-path-fixture.tsx
create mode 100644 webui/browser/file-edit-path.spec.ts
diff --git a/webui/browser/file-edit-path-fixture.tsx b/webui/browser/file-edit-path-fixture.tsx
new file mode 100644
index 000000000..0f71bf4dc
--- /dev/null
+++ b/webui/browser/file-edit-path-fixture.tsx
@@ -0,0 +1,28 @@
+import { useState } from "react";
+import { FileActionsProvider } from "@/components/FileActions";
+import { FileEditGroup, type FileEditSummary } from "@/components/thread/activity/FileEditRow";
+
+export const longEditPath = "C:/Users/HR/.nanobot-ncode/workspace/artifacts/nan284-local-file-attachments/review-fixes-20261022-133833/serve_fixture.py";
+const paths = [longEditPath, "src/verify.py", `C:/项目/带空格的目录/${"very_long_file_name_".repeat(12)}verify.py`, longEditPath.replace("serve_fixture.py", "screenshot.png")];
+export function FileEditPathFixture() {
+ const [opened, setOpened] = useState("");
+ return ({ path, relative_path: null }),
+ loadPreview: async (path) => ({
+ path, display_path: path, project_path: path, size: 68, kind: "image", mime_type: "image/png",
+ data_url: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/l9sAAAAASUVORK5CYII=",
+ }),
+ }}>
+
+ {paths.map((path, index) => {
+ const edit: FileEditSummary = {
+ key: path, path, added: index === 1 ? 33 : 12345, deleted: index === 1 ? 0 : 6789,
+ approximate: false, binary: false, status: "done", pending: false,
+ diff: { format: "unified", text: "--- a/file\n+++ b/file\n@@ -1 +1 @@\n-old\n+new\n" },
+ };
+ return ;
+ })}
+
+
+ ;
+}
diff --git a/webui/browser/file-edit-path.spec.ts b/webui/browser/file-edit-path.spec.ts
new file mode 100644
index 000000000..e0d6d3142
--- /dev/null
+++ b/webui/browser/file-edit-path.spec.ts
@@ -0,0 +1,69 @@
+import { expect, test } from "@playwright/test";
+const longEditPath = "C:/Users/HR/.nanobot-ncode/workspace/artifacts/nan284-local-file-attachments/review-fixes-20261022-133833/serve_fixture.py";
+
+for (const width of [360, 1024]) {
+ test(`file edit paths preserve statistics and reveal full paths at ${width}px`, async ({ page }, testInfo) => {
+ await page.setViewportSize({ width, height: 800 });
+ await page.goto("/browser/fixture.html?case=file-edit-path");
+ const references = page.getByTestId("activity-file-reference");
+ await expect(references).toHaveCount(4);
+ for (let index = 0; index < 4; index++) {
+ const row = page.getByTestId("activity-step").nth(index);
+ const stats = row.getByTestId("activity-diff-pair");
+ await expect(stats).toHaveText(index === 1 ? "+33-0" : "+12345-6789");
+ const geometry = await row.evaluate((element) => {
+ const path = element.querySelector('[data-testid="activity-file-reference"]')!.getBoundingClientRect();
+ const stats = element.querySelector('[data-testid="activity-diff-pair"]')!.getBoundingClientRect();
+ return { pathRight: path.right, statsLeft: stats.left, statsRight: stats.right, rowRight: element.getBoundingClientRect().right };
+ });
+ expect(geometry.pathRight).toBeLessThanOrEqual(geometry.statsLeft);
+ expect(geometry.statsRight).toBeLessThanOrEqual(geometry.rowRight);
+ }
+ const longPath = references.first();
+ await expect(longPath).toContainText("…");
+ await expect(references.nth(1)).not.toContainText("…");
+ // The last filename stays inside the clipping viewport, without reversing text direction.
+ const filename = longPath.locator(".font-semibold");
+ const tail = await filename.evaluate((element) => {
+ const clip = element.parentElement!.parentElement!.getBoundingClientRect();
+ const name = element.getBoundingClientRect();
+ return { left: name.left, right: name.right, clipLeft: clip.left, clipRight: clip.right };
+ });
+ expect(tail.left).toBeGreaterThanOrEqual(tail.clipLeft - 1);
+ expect(tail.right).toBeLessThanOrEqual(tail.clipRight + 1);
+ await page.screenshot({ path: testInfo.outputPath("summary.png") });
+ await longPath.hover();
+ const hint = page.getByRole("tooltip");
+ await expect(hint).toHaveText(longEditPath);
+ const surface = page.locator('[data-radix-popper-content-wrapper] > [data-state="delayed-open"], [data-radix-popper-content-wrapper] > [data-state="instant-open"]');
+ const hintBounds = await surface.boundingBox();
+ expect(hintBounds!.x).toBeGreaterThanOrEqual(0);
+ expect(hintBounds!.x + hintBounds!.width).toBeLessThanOrEqual(width);
+ expect(await surface.evaluate((element) => element.scrollWidth <= element.clientWidth)).toBe(true);
+ await page.screenshot({ path: testInfo.outputPath("full-path-hint.png") });
+ await page.mouse.move(0, 0);
+ await longPath.focus();
+ await expect(hint).toHaveText(longEditPath);
+ await longPath.press("Enter");
+ await expect(page.getByLabel("Opened file")).toHaveText(longEditPath);
+ await expect(hint).toBeHidden();
+ await page.getByRole("button", { name: /View changes/ }).first().click();
+ await expect(page.getByTestId("file-edit-diff")).toBeVisible();
+ const imagePath = references.nth(3);
+ await expect(imagePath).toContainText("…");
+ await imagePath.hover();
+ await expect(hint).toContainText(longEditPath.replace("serve_fixture.py", "screenshot.png"));
+ await expect(surface.locator(".select-text")).toHaveText(longEditPath.replace("serve_fixture.py", "screenshot.png"));
+ await expect(page.getByTestId("file-image-quick-look")).toHaveCount(1);
+ await expect(surface.locator('[data-testid="file-image-quick-look"] img:visible')).toHaveCount(1);
+ expect(await surface.evaluate((element) => element.scrollWidth <= element.clientWidth)).toBe(true);
+ await page.screenshot({ path: testInfo.outputPath("image-path-hint.png") });
+ await page.mouse.move(0, 0);
+ await imagePath.focus();
+ await expect(hint).toContainText(longEditPath.replace("serve_fixture.py", "screenshot.png"));
+ await page.setViewportSize({ width: 1600, height: 800 });
+ await page.getByLabel("File edits").evaluate((element) => { (element as HTMLElement).style.maxWidth = "none"; });
+ await expect(longPath).not.toContainText("…");
+ expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);
+ });
+}
diff --git a/webui/browser/fixture.tsx b/webui/browser/fixture.tsx
index 6384955ae..b65cbd2f8 100644
--- a/webui/browser/fixture.tsx
+++ b/webui/browser/fixture.tsx
@@ -31,6 +31,7 @@ import { AnswerOrderFixture } from "./answer-order-fixture";
import { SidebarActivityFixture } from "./sidebar-activity-fixture";
import { HistoryHydrationFixture } from "./history-hydration-fixture";
import { IdleCompactionFixture, installIdleCompactionApi } from "./idle-compaction-fixture";
+import { FileEditPathFixture } from "./file-edit-path-fixture";
const history: UIMessage[] = [
{ id: "question", role: "user", content: "Earlier question", createdAt: 1_700_000_000_000 },
@@ -172,7 +173,9 @@ if (parameters.get("case") === "skeleton-additions") installSkeletonPreviewApi()
if (parameters.get("case") === "idle-compaction") installIdleCompactionApi();
await initializeI18n();
createRoot(document.getElementById("root")!).render(
- {parameters.get("case") === "answer-order"
+ {parameters.get("case") === "file-edit-path"
+ ?
+ : parameters.get("case") === "answer-order"
?
: parameters.get("case") === "sidebar-activity"
?
diff --git a/webui/src/components/FileReferenceChip.tsx b/webui/src/components/FileReferenceChip.tsx
index cbf1a8e20..cb0866f42 100644
--- a/webui/src/components/FileReferenceChip.tsx
+++ b/webui/src/components/FileReferenceChip.tsx
@@ -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 (
-
+
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)}
>
{showIcon ? : null}
-
@@ -116,26 +121,28 @@ export function FileReferenceChip({
) : (
displayText
)}
-
+
- {imageQuickLook
- ? tooltipOpen ? : null
- : fullPath}
+ {truncateFromStart ? {fullPath.split(/([\\/])/).map((part, index) => (
+ {part}{/^[\\/]$/.test(part) ? : null}
+ ))} : !imageQuickLook ? fullPath : null}
+ {imageQuickLook && tooltipOpen ? : null}
@@ -143,6 +150,26 @@ export function FileReferenceChip({
);
}
+function StartTruncatedText({ children, className, ...props }: HTMLAttributes & { "data-sheen-text"?: string }) {
+ const container = useRef(null);
+ const content = useRef(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
+ {clipped ? … : null}
+
+ {children}
+
+ ;
+}
+
/** Only loads after the normal hover/focus delay, through the session's guarded preview API. */
function FileImageQuickLook({ path }: { path: string }) {
const { t } = useTranslation();
diff --git a/webui/src/components/thread/activity/FileEditRow.tsx b/webui/src/components/thread/activity/FileEditRow.tsx
index 49e19325d..7abd6ccc8 100644
--- a/webui/src/components/thread/activity/FileEditRow.tsx
+++ b/webui/src/components/thread/activity/FileEditRow.tsx
@@ -108,17 +108,21 @@ function FileEditRow({
? t("message.fileEditPreparing", { defaultValue: "Preparing file edit…" })
: (
-
+
+
+
{hasCountedDiff ? : null}
)}
@@ -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
/>
{viewDiffLabel}
- {lineCountLabel}
{shouldRenderBody ? renderBody() : null}
diff --git a/webui/src/i18n/locales/en/common.json b/webui/src/i18n/locales/en/common.json
index f6d2342e0..e2ccad147 100644
--- a/webui/src/i18n/locales/en/common.json
+++ b/webui/src/i18n/locales/en/common.json
@@ -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",
diff --git a/webui/src/i18n/locales/es/common.json b/webui/src/i18n/locales/es/common.json
index 807fb597e..e1ec9d10e 100644
--- a/webui/src/i18n/locales/es/common.json
+++ b/webui/src/i18n/locales/es/common.json
@@ -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",
diff --git a/webui/src/i18n/locales/fr/common.json b/webui/src/i18n/locales/fr/common.json
index bbbb7554a..8c908605e 100644
--- a/webui/src/i18n/locales/fr/common.json
+++ b/webui/src/i18n/locales/fr/common.json
@@ -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",
diff --git a/webui/src/i18n/locales/id/common.json b/webui/src/i18n/locales/id/common.json
index 4a0d18f2b..57aec7b24 100644
--- a/webui/src/i18n/locales/id/common.json
+++ b/webui/src/i18n/locales/id/common.json
@@ -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",
diff --git a/webui/src/i18n/locales/ja/common.json b/webui/src/i18n/locales/ja/common.json
index 9415083db..ce081603c 100644
--- a/webui/src/i18n/locales/ja/common.json
+++ b/webui/src/i18n/locales/ja/common.json
@@ -2159,7 +2159,6 @@
"turnLatencyTitle": "応答時間(全行程)",
"fileEditViewDiff": "変更を表示",
"fileEditViewLargeDiff": "変更を展開",
- "fileEditDiffLineCount": "{{count}} 行",
"fileEditUnchangedLinesHidden": "未変更の {{count}} 行を非表示",
"fileEditShowMoreLines": "さらに {{count}} 行を表示",
"fileEditShowFewerLines": "表示行数を減らす",
diff --git a/webui/src/i18n/locales/ko/common.json b/webui/src/i18n/locales/ko/common.json
index a6137c1b4..92786701c 100644
--- a/webui/src/i18n/locales/ko/common.json
+++ b/webui/src/i18n/locales/ko/common.json
@@ -2159,7 +2159,6 @@
"turnLatencyTitle": "응답 시간(엔드투엔드)",
"fileEditViewDiff": "변경 보기",
"fileEditViewLargeDiff": "변경 펼치기",
- "fileEditDiffLineCount": "{{count}}줄",
"fileEditUnchangedLinesHidden": "변경되지 않은 {{count}}줄 숨김",
"fileEditShowMoreLines": "{{count}}줄 더 보기",
"fileEditShowFewerLines": "간략히 보기",
diff --git a/webui/src/i18n/locales/pt-BR/common.json b/webui/src/i18n/locales/pt-BR/common.json
index cf03b139f..b989863a0 100644
--- a/webui/src/i18n/locales/pt-BR/common.json
+++ b/webui/src/i18n/locales/pt-BR/common.json
@@ -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",
diff --git a/webui/src/i18n/locales/vi/common.json b/webui/src/i18n/locales/vi/common.json
index 7dda930b5..500c149de 100644
--- a/webui/src/i18n/locales/vi/common.json
+++ b/webui/src/i18n/locales/vi/common.json
@@ -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",
diff --git a/webui/src/i18n/locales/zh-CN/common.json b/webui/src/i18n/locales/zh-CN/common.json
index d912d0cac..9d4cb5397 100644
--- a/webui/src/i18n/locales/zh-CN/common.json
+++ b/webui/src/i18n/locales/zh-CN/common.json
@@ -2538,7 +2538,6 @@
"turnLatencyTitle": "回复耗时",
"fileEditViewDiff": "查看修改",
"fileEditViewLargeDiff": "展开修改",
- "fileEditDiffLineCount": "{{count}} 行",
"fileEditUnchangedLinesHidden": "已隐藏 {{count}} 行未修改内容",
"fileEditShowMoreLines": "显示剩余 {{count}} 行",
"fileEditShowFewerLines": "收起部分行",
diff --git a/webui/src/i18n/locales/zh-TW/common.json b/webui/src/i18n/locales/zh-TW/common.json
index 3bd58b831..5e148a5ae 100644
--- a/webui/src/i18n/locales/zh-TW/common.json
+++ b/webui/src/i18n/locales/zh-TW/common.json
@@ -2158,7 +2158,6 @@
"turnLatencyTitle": "回覆耗時",
"fileEditViewDiff": "檢視修改",
"fileEditViewLargeDiff": "展開修改",
- "fileEditDiffLineCount": "{{count}} 行",
"fileEditUnchangedLinesHidden": "已隱藏 {{count}} 行未修改內容",
"fileEditShowMoreLines": "顯示其餘 {{count}} 行",
"fileEditShowFewerLines": "收起部分行",
diff --git a/webui/src/tests/agent-activity-cluster.test.tsx b/webui/src/tests/agent-activity-cluster.test.tsx
index d4779c79f..2f057a160 100644
--- a/webui/src/tests/agent-activity-cluster.test.tsx
+++ b/webui/src/tests/agent-activity-cluster.test.tsx
@@ -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 ;")).not.toBeInTheDocument();