Compare commits

..
Author SHA1 Message Date
l0ng-ai e68ee47052 Merge remote-tracking branch 'origin/main' into d848-5287
# Conflicts:
#	src/platform/locales/text/en.json
2026-11-23 10:32:37 +08:00
l0ng-ai a700e6257e fix(vcs): group Git Log display settings 2026-11-23 08:31:50 +08:00
4 changed files with 87 additions and 182 deletions

No files matched your search

-110
View File
@@ -1,110 +0,0 @@
import type { Page } from "@playwright/test";
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
async function openTable(page: Page, columns: number) {
await stubDesktop(page);
await page.evaluate(async (columns) => {
window.__ipc.handlers.debug_evaluate_in = ({ expression }) => {
const query = String(expression);
const sliced = query.includes("totals.iloc[:2, :2]");
const visibleColumns = sliced ? 2 : Math.min(30, columns);
const columnsInFrame = sliced ? 2 : columns;
const start = query.includes("100, 100,") ? 100 : 0;
const rows = sliced ? 2 : 220;
const count = sliced ? 2 : 100;
const result = query.includes("missing_table")
? { error: "NameError: missing_table" }
: {
kind: "frame",
shape: [rows, columnsInFrame],
rows,
columns: columnsInFrame,
headers: Array.from({ length: visibleColumns }, (_, i) => `Amount ${i + 1}`),
dtypes: Array.from({ length: visibleColumns }, () => "int64"),
index: Array.from({ length: count }, (_, i) => String(i + start)),
cells: Array.from({ length: count }, (_, row) =>
Array.from({ length: visibleColumns }, (_, column) => String((row + start + 1) * 10 + column)),
),
};
return {
name: "",
value: JSON.stringify(JSON.stringify(result)),
typeName: "str",
variablesReference: 0,
evaluateName: null,
};
};
const stateModule = "/src/features/debugger/state.ts";
const overlaysModule = "/src/features/debugger/ui/popoverStore.ts";
const { adoptSession } = await import(/* @vite-ignore */ stateModule);
const { openTableView } = await import(/* @vite-ignore */ overlaysModule);
adoptSession(91, { name: "Settlement review", adapter: "debugpy", status: "paused", selectedFrame: 11 });
openTableView("totals", 91);
}, columns);
const dialog = page.getByRole("dialog", { name: "Table view of totals", exact: true });
await expect(dialog.getByRole("table")).toBeVisible();
return dialog;
}
test("View as Table gives the grid the dialog width and puts the expression below it", async ({ workbench: page }) => {
await page.setViewportSize({ width: 1120, height: 760 });
const dialog = await openTable(page, 3);
const scroll = dialog.getByRole("region", { name: "Table", exact: true });
const grid = dialog.getByRole("table");
const expression = dialog.getByRole("textbox", { name: "Expression", exact: true });
const shape = dialog.getByText("Shape (220, 3)", { exact: true });
const body = (await scroll.boundingBox())!;
const input = (await expression.boundingBox())!;
expect(input.y).toBeGreaterThan(body.y + body.height);
expect((await shape.boundingBox())!.y).toBeLessThan(body.y);
expect(Math.abs((await grid.boundingBox())!.width - (await scroll.evaluate((el) => el.clientWidth)))).toBeLessThan(1);
expect((await dialog.boundingBox())!.width).toBeCloseTo(700, 0);
await expect(expression).toBeFocused();
await expect(grid).toHaveCSS("font-family", /Inter/);
await expect(grid.getByRole("columnheader").nth(1)).toHaveCSS("text-align", "center");
await expect(grid.getByRole("rowheader").first()).toHaveCSS("text-align", "center");
await expect(grid.getByRole("cell").first()).toHaveCSS("text-align", /^(start|left)$/);
});
test("View as Table keeps paging, slice input and Close usable in a narrow window", async ({ workbench: page }) => {
await page.setViewportSize({ width: 450, height: 620 });
const dialog = await openTable(page, 36);
const expression = dialog.getByRole("textbox", { name: "Expression", exact: true });
const scroll = dialog.getByRole("region", { name: "Table", exact: true });
const rows = dialog.getByRole("button", { name: "Next Rows", exact: true });
const columns = dialog.getByRole("button", { name: "Next Columns", exact: true });
const close = dialog.getByRole("button", { name: "Close", exact: true }).filter({ hasText: /^Close$/ });
const input = (await expression.boundingBox())!;
const grid = (await scroll.boundingBox())!;
expect(input.y).toBeGreaterThan(grid.y + grid.height);
expect(input.width).toBeCloseTo(grid.width, 0);
for (const control of [expression, rows, columns, close]) await expect(control).toBeInViewport({ ratio: 0.98 });
await scroll.evaluate((el) => {
el.scrollLeft = 300;
el.scrollTop = 150;
});
await expect(dialog.getByRole("rowheader").filter({ hasText: /^9$/ })).toBeInViewport({ ratio: 0.98 });
await rows.click();
await expect(dialog.getByText("Rows 101–200 of 220", { exact: true })).toBeVisible();
await expect
.poll(() => ipcCalls(page, "debug_evaluate_in"))
.toContainEqual(expect.objectContaining({ expression: expect.stringContaining("100, 100, 0, 30") }));
await expression.fill("totals.iloc[:2, :2]");
await expression.press("Enter");
const sliced = page.getByRole("dialog", { name: "Table view of totals.iloc[:2, :2]", exact: true });
await expect(sliced.getByText("Shape (2, 2)", { exact: true })).toBeVisible();
const slicedExpression = sliced.getByRole("textbox", { name: "Expression", exact: true });
await slicedExpression.fill("missing_table");
await slicedExpression.press("Enter");
const failed = page.getByRole("dialog", { name: "Table view of missing_table", exact: true });
const alert = failed.getByRole("alert");
await expect(alert).toHaveText("NameError: missing_table");
expect((await alert.boundingBox())!.y).toBeGreaterThan(
(await failed.getByRole("textbox", { name: "Expression", exact: true }).boundingBox())!.y,
);
await failed
.getByRole("button", { name: "Close", exact: true })
.filter({ hasText: /^Close$/ })
.click();
await expect(failed).toHaveCount(0);
});
+5
View File
@@ -12,6 +12,11 @@ export function isTableType(typeName: string | null | undefined): boolean {
return !!typeName && TABLE_TYPES.has(typeName);
}
/** Numbers are right-aligned, as in the database grid. */
export function isNumericDtype(dtype: string | undefined): boolean {
return !!dtype && /^(u?int|float|complex|Int|UInt|Float)\d*$/.test(dtype);
}
export const ROW_PAGE = 100;
export const COLUMN_PAGE = 30;
@@ -1,35 +1,39 @@
.dialog {
height: 500px;
height: clamp(320px, 60vh, 760px);
}
/* Scroll only the grid between the toolbar and the expression field. */
/* The table scrolls under a fixed bar, not the whole dialog body. */
.content {
display: flex;
flex-direction: column;
height: 100%;
min-height: 0;
padding: var(--space-2) var(--space-3) 0;
gap: var(--space-2);
}
.bar {
flex: none;
display: flex;
align-items: center;
flex-wrap: wrap;
justify-content: space-between;
gap: var(--space-1) var(--space-2);
gap: var(--space-2);
padding-bottom: var(--space-2);
}
.expression {
flex: none;
flex: 1 1 200px;
min-width: 0;
height: var(--h-list-row);
padding: 0 6px;
font-family: var(--font-mono);
font-size: var(--fs-ui);
color: var(--fg);
background: var(--bg-input);
border: 1px solid var(--border);
border-radius: var(--radius-small);
}
.pagers {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: var(--space-1) var(--space-2);
.expression:focus {
outline: none;
border-color: var(--focus-ring);
}
.summary,
@@ -55,8 +59,7 @@
.table {
border-collapse: separate;
border-spacing: 0;
min-width: 100%;
font-family: var(--font-ui);
font-family: var(--font-mono);
font-size: var(--fs-ui);
color: var(--fg);
}
@@ -74,7 +77,7 @@
position: sticky;
top: 0;
z-index: 1;
text-align: center;
text-align: left;
font-weight: normal;
color: var(--fg-secondary);
background: var(--bg-island);
@@ -83,8 +86,7 @@
.table .index {
position: sticky;
left: 0;
text-align: center;
font-variant-numeric: tabular-nums;
text-align: right;
font-weight: normal;
color: var(--fg-secondary);
background: var(--bg-island);
@@ -98,22 +100,16 @@
background: var(--bg-hover);
}
.numeric {
text-align: right;
}
.dtype {
margin-left: var(--space-1);
color: var(--fg-subtle);
font-size: var(--fs-small);
}
.message {
flex: 1;
min-height: 0;
padding: var(--space-3) 0;
color: var(--fg-secondary);
}
.error {
max-height: 5em;
overflow: auto;
overflow-wrap: anywhere;
color: var(--danger);
}
+58 -44
View File
@@ -1,10 +1,19 @@
/** View as Table: a DataFrame / Series / ndarray of the paused frame, one page of rows and columns at a time. */
import { useEffect, useRef, useState } from "react";
import clsx from "clsx";
import type { DebugSessionId } from "@/platform/ipc";
import { Dialog, IconButton, Input } from "@/ui";
import { Dialog, IconButton } from "@/ui";
import { formatMessage, tx } from "@/platform/i18n";
import { evaluate, useDebug } from "../state";
import { COLUMN_PAGE, ROW_PAGE, clampWindow, parseTableResult, tableExpression, type TableResult } from "../tableView";
import {
COLUMN_PAGE,
ROW_PAGE,
clampWindow,
isNumericDtype,
parseTableResult,
tableExpression,
type TableResult,
} from "../tableView";
import styles from "./TableViewDialog.module.css";
export function TableViewDialog({
@@ -54,7 +63,7 @@ export function TableViewDialog({
};
}, [expression, win, session, stops, frame, paused]);
const page = paused && result && "page" in result ? result.page : null;
const page = result && "page" in result ? result.page : null;
const error = !paused
? tx("Values are available while the program is paused")
: result && "error" in result
@@ -105,37 +114,54 @@ export function TableViewDialog({
open
onClose={onClose}
// An element, not a string: Dialog would translate a variable named like a catalog text ("tasks").
title={<span>{expression}</span>}
width={700}
title={<span>{initial}</span>}
width="clamp(520px, 70vw, 1100px)"
minWidth={420}
minHeight={260}
resizable="both"
aria-label={formatMessage(tx("Table view of {label}"), { label: expression })}
buttons={[{ label: "Close", role: "cancel" }]}
aria-label={formatMessage(tx("Table view of {label}"), { label: initial })}
className={styles.dialog}
>
<div className={styles.content}>
{page && (
<div className={styles.bar}>
<div className={styles.bar}>
<input
className={styles.expression}
value={draft}
spellCheck={false}
autoComplete="off"
aria-label={tx("Expression")}
onChange={(e) => setDraft(e.target.value)}
onKeyDown={(e) => {
if (e.key !== "Enter" || !draft.trim()) return;
e.preventDefault();
setExpression(draft.trim());
setWin({ row: 0, column: 0 });
}}
/>
{page && (
<span className={styles.summary}>
{formatMessage(tx("Shape ({shape})"), { shape: page.shape.join(", ") })}
{page.kind !== "frame" ? ` · ${page.dtypes[0]}` : ""}
</span>
<div className={styles.pagers}>
{pager(win.row, ROW_PAGE, page.rows, (row) => setWin({ ...win, row }), {
range: tx("Rows {from}–{to} of {total}"),
previous: tx("Previous Rows"),
next: tx("Next Rows"),
})}
{pager(win.column, COLUMN_PAGE, page.columns, (column) => setWin({ ...win, column }), {
range: tx("Columns {from}–{to} of {total}"),
previous: tx("Previous Columns"),
next: tx("Next Columns"),
})}
</div>
)}
{page &&
pager(win.row, ROW_PAGE, page.rows, (row) => setWin({ ...win, row }), {
range: tx("Rows {from}–{to} of {total}"),
previous: tx("Previous Rows"),
next: tx("Next Rows"),
})}
{page &&
pager(win.column, COLUMN_PAGE, page.columns, (column) => setWin({ ...win, column }), {
range: tx("Columns {from}–{to} of {total}"),
previous: tx("Previous Columns"),
next: tx("Next Columns"),
})}
</div>
{error ? (
<div className={styles.message} role="alert">
{error}
</div>
)}
{page ? (
) : page ? (
<div className={styles.scroll} tabIndex={0} role="region" aria-label={tx("Table")}>
<table className={styles.table}>
<thead>
@@ -156,7 +182,14 @@ export function TableViewDialog({
{page.index[r]}
</th>
{row.map((cell, c) => (
<td key={c}>{cell}</td>
<td
key={c}
className={clsx(
isNumericDtype(page.kind === "frame" ? page.dtypes[c] : page.dtypes[0]) && styles.numeric,
)}
>
{cell}
</td>
))}
</tr>
))}
@@ -164,26 +197,7 @@ export function TableViewDialog({
</table>
</div>
) : (
<div className={styles.message}>{!error && tx("Loading…")}</div>
)}
<Input
className={styles.expression}
mono
data-autofocus=""
value={draft}
aria-label="Expression"
onChange={(e) => setDraft(e.target.value)}
onKeyDown={(e) => {
if (e.key !== "Enter" || !draft.trim()) return;
e.preventDefault();
setExpression(draft.trim());
setWin({ row: 0, column: 0 });
}}
/>
{error && (
<div className={styles.error} role="alert">
{error}
</div>
<div className={styles.message}>{tx("Loading…")}</div>
)}
</div>
</Dialog>