refactor(webui): unify code and diff highlighting (#6412)

* refactor(webui): unify code and diff highlighting

Replace Prism with shared Highlights tokens and Pierre read-only diffs, retaining rare grammars through lazy Shiki and preserving source, copy, preview and diff controls.

Restore single-session Composer ownership inside the conversation column while retaining the shared multi-pane footer. Keep the measured large-diff scroll regression explicit during review.

* fix(webui): contain highlighting errors and retain diff selections

Refs NAN-343

* test(webui): align pane fixtures after main rebase

* chore(webui): update highlighting dependencies

Keep grammar fallback coverage on a language that still requires Shiki, and align reading-size assertions with main.
This commit is contained in:
chengyongru authored and GitHub committed 2026-11-06 16:41:12 +08:00
1 parent f5c359476b
commit 3a37269f3f
44 files changed
+2261 -1072

No files matched your search

+19 -5
View File
@@ -108,17 +108,24 @@ function BspWorkbenchHarness() {
}
describe("PaneWorkbench", () => {
it("keeps a single conversation's header inside that pane instead of above its previews", () => {
it("keeps a single conversation's header and composer inside its preview layout", () => {
const composer = <textarea aria-label="Composer Alpha" />;
render(<PaneWorkbench panes={[{ key: "alpha", title: "Alpha" }]} activePaneKey="alpha"
layout="columns" chrome showLayoutControl={false} onActivatePane={vi.fn()} onAddPane={vi.fn()}
onLayoutChange={vi.fn()} onPaneOrderChange={vi.fn()}
renderPane={(_pane, context) => {
expect(context.headerPortalTarget).toBeUndefined();
expect(context.multiplePanes).toBe(false);
return <div data-testid="local-toolbar">{context.headerActions}</div>;
return <div data-testid="local-toolbar">
{context.headerActions}
{context.composerPortalTarget === undefined ? composer : context.composerPortalTarget
? createPortal(composer, context.composerPortalTarget) : null}
</div>;
}} />);
expect(screen.getByTestId("workbench-header-host")).toBeEmptyDOMElement();
expect(within(screen.getByTestId("local-toolbar")).getByRole("button", { name: "Add pane" })).toBeVisible();
const conversation = screen.getByTestId("local-toolbar");
expect(within(conversation).getByRole("button", { name: "Add pane" })).toBeVisible();
expect(within(conversation).getByRole("textbox", { name: "Composer Alpha" })).toBeVisible();
});
const originalGetBoundingClientRect = HTMLElement.prototype.getBoundingClientRect;
@@ -168,7 +175,7 @@ describe("PaneWorkbench", () => {
.toEqual(["Alpha", "Beta"]);
expect(screen.getByRole("button", { name: "Focus Alpha" })).toHaveAttribute("data-multiple-panes", "true");
expect(screen.getByRole("button", { name: "Focus Beta" })).toHaveAttribute("data-multiple-panes", "true");
expect(screen.getByLabelText("Composer Beta")).toBeVisible();
expect(within(screen.getByTestId("workbench-composer-host")).getByLabelText("Composer Beta")).toBeVisible();
expect(screen.getByLabelText("Composer Alpha")).not.toBeVisible();
fireEvent.pointerDown(
@@ -400,7 +407,12 @@ describe("PaneWorkbench", () => {
renderPane: (pane: { key: string; title: string }, context: {
headerActions: ReactNode;
multiplePanes: boolean;
}) => <>{context.headerActions}<span data-multiple-panes={context.multiplePanes}>{pane.title}</span></>,
composerPortalTarget: HTMLElement | null | undefined;
}) => <>{context.headerActions}<span data-multiple-panes={context.multiplePanes}>{pane.title}</span>
{context.composerPortalTarget ? createPortal(
<textarea aria-label={`Composer ${pane.title}`} />, context.composerPortalTarget,
) : null}
</>,
};
const { rerender } = render(<PaneWorkbench {...props} activePaneKey="gamma" />);
@@ -408,6 +420,7 @@ describe("PaneWorkbench", () => {
expect(screen.getByTestId("pane-grid").children).toHaveLength(1);
expect(screen.getByTestId("workbench-pane-gamma")).toBeInTheDocument();
expect(screen.getByText("gamma", { selector: "span" })).toHaveAttribute("data-multiple-panes", "false");
expect(within(screen.getByTestId("workbench-composer-host")).getByRole("textbox", { name: "Composer gamma" })).toBeVisible();
expect(screen.queryByRole("button", { name: "Layout" })).not.toBeInTheDocument();
expect(screen.queryByRole("button", { name: "Add pane" })).not.toBeInTheDocument();
expect(screen.queryByRole("separator")).not.toBeInTheDocument();
@@ -415,6 +428,7 @@ describe("PaneWorkbench", () => {
rerender(<PaneWorkbench {...props} activePaneKey="delta" />);
expect(screen.getByTestId("pane-grid").children).toHaveLength(1);
expect(screen.getByTestId("workbench-pane-delta")).toBeInTheDocument();
expect(within(screen.getByTestId("workbench-composer-host")).getByRole("textbox", { name: "Composer delta" })).toBeVisible();
expect(screen.queryByTestId("workbench-pane-gamma")).not.toBeInTheDocument();
});