Compare commits

..
Author SHA1 Message Date
l0ng-ai dfae74cf5c fix(debugger): align compact editor value hints 2026-11-23 03:19:19 +08:00
8 changed files with 148 additions and 129 deletions

No files matched your search

-60
View File
@@ -85,66 +85,6 @@ test("⌘K commits the checked changes with the typed message", async ({ workben
await expect(changes.getByRole("checkbox", { name: "Include build.gradle.kts in commit" })).toBeHidden();
});
test("commit options align author fields and keep the date editable in a narrow dialog", async ({
workbench: page,
}) => {
await stubRepository(page);
await page.setViewportSize({ width: 1040, height: 700 });
await page.keyboard.press("Meta+k");
const panel = page.getByRole("region", { name: "Commit", exact: true });
await panel.getByRole("button", { name: "Commit Options", exact: true }).click();
const popup = page.getByRole("dialog", { name: "Commit Options", exact: true });
const author = popup.getByRole("textbox", { name: "Author", exact: true });
const date = popup.getByLabel("Author date", { exact: true });
const clear = popup.getByRole("button", { name: "Clear author date", exact: true });
const name = "Regional Ledger Review <[email protected]>";
const time = "2024-06-04T13:20:21";
await author.fill(name);
await date.fill(time);
const authorBox = (await author.boundingBox())!;
const dateBox = (await date.boundingBox())!;
const dateLabel = (await popup.getByText("Author date", { exact: true }).boundingBox())!;
const clearBox = (await clear.boundingBox())!;
expect(authorBox.x).toBeCloseTo(dateBox.x, 0);
expect(dateLabel.y).toBeGreaterThanOrEqual(dateBox.y);
expect(dateLabel.y).toBeLessThan(dateBox.y + dateBox.height);
expect(clearBox.x + clearBox.width).toBeCloseTo(authorBox.x + authorBox.width, 0);
await expect(clear).toBeInViewport({ ratio: 1 });
await page.keyboard.press("Escape");
await expect(popup).toBeHidden();
await page.evaluate(async () => {
const projectModule = "/src/platform/project.ts";
const { useProject } = await import(/* @vite-ignore */ projectModule);
const { settings } = useProject.getState();
useProject.setState({
settings: { ...settings, vcs: { ...settings?.vcs, commit: { ...settings?.vcs?.commit, nonModal: false } } },
});
});
await page.setViewportSize({ width: 650, height: 650 });
await page.keyboard.press("Meta+k");
const dialog = page.getByRole("dialog", { name: "Commit Changes", exact: true });
const options = dialog.getByRole("group", { name: "Commit Options", exact: true });
const compactAuthor = options.getByRole("textbox", { name: "Author", exact: true });
const compactDate = options.getByLabel("Author date", { exact: true });
const compactClear = options.getByRole("button", { name: "Clear author date", exact: true });
await expect(compactAuthor).toHaveValue(name);
await expect(compactDate).toHaveValue(time);
const labelBox = (await options.getByText("Author:", { exact: true }).boundingBox())!;
const inputBox = (await compactAuthor.boundingBox())!;
expect(inputBox.x).toBeCloseTo(labelBox.x, 0);
expect(inputBox.y).toBeGreaterThanOrEqual(labelBox.y + labelBox.height);
const box = (await compactDate.boundingBox())!;
const buttonBox = (await compactClear.boundingBox())!;
expect(box.width).toBeCloseTo(inputBox.width, 0);
expect(buttonBox.y).toBeGreaterThanOrEqual(box.y + box.height);
expect(await options.evaluate((node) => node.scrollWidth - node.clientWidth)).toBeLessThanOrEqual(1);
await compactClear.click();
await expect(compactDate).toHaveValue("");
await expect(compactClear).toBeHidden();
await expect(compactAuthor).toHaveValue(name);
});
test("the Commit window gives its message preferred focus", async ({ workbench: page }) => {
await stubRepository(page);
const stripe = page.locator('[data-stripe-button="commit"]');
+56 -5
View File
@@ -1,9 +1,7 @@
import type { EditorView } from "@codemirror/view";
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
test("Quick Evaluate opens an object tree that fits the editor and returns focus on Escape", async ({
workbench: page,
}) => {
test("Quick Evaluate and hover keep value previews usable in a narrow editor", async ({ workbench: page }) => {
await page.setViewportSize({ width: 445, height: 500 });
await stubDesktop(page);
await page.evaluate(async () => {
@@ -19,7 +17,9 @@ test("Quick Evaluate opens an object tree that fits the editor and returns focus
h.fs_probe = () => ({ size: 48, binary: false, tooLarge: false });
h.fs_read_text = () => "summary = {}\nsubtotal = 42\n";
h.debug_evaluate_in = ({ expression }) =>
expression === "summary" ? value("summary", "{...}", "dict", 101) : value("subtotal", "42", "int");
expression === "summary"
? value("summary", `{'audit': '${"Regional settlement totals ".repeat(8)}'}`, "dict", 101)
: value("subtotal", "42", "int");
h.debug_variables = ({ reference }) =>
reference === 101
? [value("audit", "{...}", "dict", 102), value("total", "47.74", "float")]
@@ -81,8 +81,59 @@ test("Quick Evaluate opens an object tree that fits the editor and returns focus
await evaluate(2);
await expect(hint.getByRole("tree")).toHaveCount(0);
await expect(hint).toHaveText(/subtotal\s*=\s*42/);
expect(await ipcCalls(page, "debug_evaluate_in")).toEqual([
const scalar = hint.locator("[class*='_valueTooltip_']");
const uiFont = await page.locator("body").evaluate((el) => getComputedStyle(el).fontFamily);
await expect(scalar).toHaveCSS("font-family", uiFont);
await expect(scalar).toHaveCSS("font-size", "13px");
await expect(scalar).toHaveCSS("font-weight", "700");
await expect(scalar.locator(".cm-openidea-icon")).toHaveCount(1);
await content.press("Escape");
await expect(hint).toBeHidden();
await page.setViewportSize({ width: 620, height: 480 });
await page.evaluate(async () => {
const layoutModule = "/src/workbench/toolwindows/store.ts";
const servicesModule = "/src/workbench/contributions.ts";
const { moveToolWindow, setToolWindowSize } = await import(/* @vite-ignore */ layoutModule);
const { toolWindowService } = await import(/* @vite-ignore */ servicesModule);
moveToolWindow("project", "left");
setToolWindowSize("left", 220);
toolWindowService().show("project", false);
});
await expect.poll(async () => (await editor.boundingBox())!.x).toBeGreaterThan(160);
const position = await content.evaluate((el) => {
const { view } = (el as HTMLElement & { cmTile: { view: EditorView } }).cmTile;
return view.coordsAtPos(view.state.doc.line(1).from + 2);
});
await page.mouse.move(position!.left, (position!.top + position!.bottom) / 2);
const hover = page.locator(".cm-tooltip-hover").locator("[class*='_valueTooltip_']");
const expand = hover.getByRole("button", { name: "Expand value" });
await expect(hover).toContainText("Regional settlement totals");
await expect(hover).toHaveCSS("font-family", uiFont);
const summary = hover.locator("[class*='_valueText_']");
const textBox = (await summary.boundingBox())!;
const controlBox = (await expand.boundingBox())!;
const iconBox = (await hover.locator(".cm-openidea-icon").boundingBox())!;
expect(textBox.height).toBeGreaterThan(20);
expect(Math.abs(controlBox.y - iconBox.y)).toBeLessThan(1);
expect(textBox.x).toBeGreaterThanOrEqual(iconBox.x + iconBox.width);
const fitsEditor = async () => {
const tooltip = await hover.boundingBox();
const pane = (await editor.boundingBox())!;
return !!tooltip && tooltip.x >= pane.x - 1 && tooltip.x + tooltip.width <= pane.x + pane.width + 1;
};
await expect.poll(fitsEditor).toBe(true);
await page.setViewportSize({ width: 555, height: 480 });
await expect.poll(fitsEditor).toBe(true);
await expand.click();
const pinned = hint.getByRole("tree", { name: "summary" });
await expect(pinned).toBeFocused();
await pinned.press("Escape");
await expect(content).toBeFocused();
const calls = await ipcCalls(page, "debug_evaluate_in");
expect(calls.filter((call) => call.context === "watch")).toEqual([
{ session: 91, frameId: 11, expression: "summary", context: "watch" },
{ session: 91, frameId: 11, expression: "subtotal", context: "watch" },
]);
expect(calls).toContainEqual({ session: 91, frameId: 11, expression: "summary", context: "hover" });
});
@@ -38,7 +38,7 @@ afterEach(() => {
describe("value hint", () => {
it("keeps a hint whose value was expanded past the hint's timeout", () => {
showHint(view, () => valueHint("order", order, session), { pos: 0, timeout: 4000 });
showHint(view, () => valueHint(view, "order", order, session), { pos: 0, timeout: 4000 });
expand();
expect(document.querySelector(".cm-lsp-hint .tree")).not.toBeNull();
vi.advanceTimersByTime(60_000);
@@ -47,7 +47,7 @@ describe("value hint", () => {
it("hands an expanded hover hint to its pin instead of growing in place", () => {
const pin = vi.fn();
showHint(view, () => valueHint("order", order, session, 400, { pin }), { pos: 0 });
showHint(view, () => valueHint(view, "order", order, session, 400, { pin }), { pos: 0 });
expand();
expect(pin).toHaveBeenCalled();
expect(document.querySelector(".tree")).toBeNull();
+23 -8
View File
@@ -169,13 +169,25 @@
/* Data Views › Show value tooltip on mouse hover. */
.valueTooltip {
max-width: 520px;
padding: 4px 8px;
font-family: var(--font-mono);
font-weight: var(--fw-code);
font-size: var(--fs-code);
display: flex;
align-items: flex-start;
gap: var(--space-1);
max-width: min(90vw, calc(var(--debug-value-editor-width, 100vw) - var(--space-2)));
padding: var(--space-1) var(--space-2);
font-family: var(--font-ui);
font-size: var(--fs-ui);
font-weight: 700;
line-height: 1.4;
}
.valueText {
min-width: 0;
white-space: pre-wrap;
word-break: break-word;
overflow-wrap: anywhere;
}
.valueGlyph {
display: inline-flex;
flex: none;
margin-top: 1px;
}
.valueTooltipTree {
display: flex;
@@ -194,19 +206,22 @@
padding: 0;
overflow: hidden;
}
:global(.cm-lsp-hint):has(> .valueTooltip) {
padding: 0;
}
.valueExpand {
display: inline-flex;
align-items: center;
justify-content: center;
width: 16px;
height: 16px;
margin-right: 4px;
flex: none;
margin-top: 1px;
padding: 0;
border: 0;
border-radius: var(--radius-small);
background: transparent;
color: var(--fg-muted);
vertical-align: -3px;
cursor: pointer;
}
.valueExpand:hover {
+2 -2
View File
@@ -49,7 +49,7 @@ class InlineValues extends WidgetType {
e.stopPropagation();
const session = activeSession();
if (!session || session.status !== "paused") return;
showHint(view, () => valueHint(part.name, part.variable, session.id, null), {
showHint(view, () => valueHint(view, part.name, part.variable, session.id, null), {
pos: view.posAtDOM(piece),
timeout: 60_000,
});
@@ -65,7 +65,7 @@ class InlineValues extends WidgetType {
e.stopPropagation();
const session = activeSession();
if (!session || session.status !== "paused") return;
showHint(view, () => valueHint(part.name, part.variable, session.id, null), {
showHint(view, () => valueHint(view, part.name, part.variable, session.id, null), {
pos: view.posAtDOM(show),
timeout: 60_000,
});
+45 -26
View File
@@ -13,6 +13,7 @@ import { activeSession, evaluate, useDebug } from "../state";
import { inlineValue, shownValue } from "../values";
import { tx } from "@/platform/i18n";
import { iconMarkup, selectableText } from "@/ui";
import { iconNode } from "@/ui/iconNode";
import { mountValueTree } from "../ui/ValueHintTree";
import styles from "./editor.module.css";
@@ -96,6 +97,7 @@ export function expressionAt(
/** IDEA's value hint: `expression = value {type}`, objects expandable into a variables tree in place. */
export function valueHint(
view: EditorView,
expression: string,
value: Variable,
session: DebugSessionId,
@@ -104,15 +106,21 @@ export function valueHint(
): { dom: HTMLElement; destroy: () => void } {
const dom = document.createElement("div");
dom.className = `${styles.valueTooltip} ${selectableText}`;
const stopSizing = watchHintWidth(view, dom);
let tree: { unmount(): void } | null = null;
const destroy = () => {
stopSizing();
tree?.unmount();
};
const expandTree = () => {
dom.classList.remove(styles.valueTooltip!);
dom.classList.replace(selectableText, styles.valueTooltipTree!);
dom.replaceChildren();
tree = mountValueTree(dom, expression, value, session);
};
if (value.variablesReference > 0 && opts.expanded) {
expandTree();
return { dom, destroy: () => tree?.unmount() };
return { dom, destroy };
}
if (value.variablesReference > 0) {
// IDEA's value hint: the "+" expands the object into a variables tree in place.
@@ -131,6 +139,8 @@ export function valueHint(
});
dom.append(expand);
}
const summary = document.createElement("span");
summary.className = styles.valueText!;
const name = document.createElement("span");
name.className = styles.valueName!;
name.textContent = `${expression} = `;
@@ -143,11 +153,33 @@ export function valueHint(
span.textContent = text;
return span;
};
dom.append(name);
if (leading) dom.append(type(`${shown.label} `));
dom.append(max === null ? shown.text : inlineValue(shown.text, max));
if (shown.label && !leading) dom.append(type(` ${shown.label}`));
return { dom, destroy: () => tree?.unmount() };
summary.append(name);
if (leading) summary.append(type(`${shown.label} `));
summary.append(max === null ? shown.text : inlineValue(shown.text, max));
if (shown.label && !leading) summary.append(type(` ${shown.label}`));
dom.append(iconNode("variable", 16, styles.valueGlyph), summary);
return { dom, destroy };
}
function watchHintWidth(view: EditorView, dom: HTMLElement): () => void {
let width = 0;
let resizeFrame = 0;
const updateWidth = () => {
const next = view.dom.clientWidth;
if (!next || next === width) return;
width = next;
dom.style.setProperty("--debug-value-editor-width", `${width}px`);
};
updateWidth();
const resize = new ResizeObserver(() => {
cancelAnimationFrame(resizeFrame);
resizeFrame = requestAnimationFrame(updateWidth);
});
resize.observe(view.dom);
return () => {
resize.disconnect();
cancelAnimationFrame(resizeFrame);
};
}
export function showQuickValue(
@@ -158,7 +190,7 @@ export function showQuickValue(
session: DebugSessionId,
) {
if (value.variablesReference > 0) showValueTree(view, pos, expression, value, session);
else showHint(view, () => valueHint(expression, value, session), { pos, timeout: 60_000 });
else showHint(view, () => valueHint(view, expression, value, session), { pos, timeout: 60_000 });
}
export function valueTooltip(): Extension {
@@ -185,7 +217,7 @@ export function valueTooltip(): Extension {
end: expr.to,
above: true,
create: (view) =>
valueHint(expr.text, value, session.id, 400, {
valueHint(view, expr.text, value, session.id, 400, {
// The tree outgrows the hint and may move to the other side of the line, away from the
// mouse, which closed the hover tooltip before it could be reached. Like IDEA's value
// popup it stays until Escape, a click in the editor or the next step.
@@ -208,21 +240,7 @@ function pinnedTree(view: EditorView, expression: string, value: Variable, sessi
const unsubscribe = useDebug.subscribe((s) => {
if (s.stopSeq !== stop || s.sessions[session]?.status !== "paused") hideHint(view);
});
const hint = valueHint(expression, value, session, 400, { expanded: true });
let width = 0;
let resizeFrame = 0;
const updateWidth = () => {
const next = view.dom.clientWidth;
if (!next || next === width) return;
width = next;
hint.dom.style.setProperty("--debug-value-editor-width", `${width}px`);
};
updateWidth();
const resize = new ResizeObserver(() => {
cancelAnimationFrame(resizeFrame);
resizeFrame = requestAnimationFrame(updateWidth);
});
resize.observe(view.dom);
const hint = valueHint(view, expression, value, session, 400, { expanded: true });
// The tree has the focus, so the editor's Escape doesn't reach the hint.
hint.dom.addEventListener("keydown", (e) => {
if (e.key !== "Escape" || e.defaultPrevented) return;
@@ -233,8 +251,6 @@ function pinnedTree(view: EditorView, expression: string, value: Variable, sessi
return {
dom: hint.dom,
destroy: () => {
resize.disconnect();
cancelAnimationFrame(resizeFrame);
unsubscribe();
hint.destroy();
},
@@ -287,7 +303,10 @@ export function selectionValueTooltip(): Extension {
}
// The selection moved on while evaluating.
if (seq !== this.seq) return;
showHint(this.view, () => valueHint(expr.text, value, session.id), { pos: expr.from, timeout: 60_000 });
showHint(this.view, () => valueHint(this.view, expr.text, value, session.id), {
pos: expr.from,
timeout: 60_000,
});
}
destroy() {
+7 -7
View File
@@ -33,17 +33,15 @@ export function CommitAuthorFields({
focusAuthor?: boolean;
onChange: (update: Partial<CommitAuthor>) => void;
}) {
const authorId = useId();
const authorDateId = useId();
const date = authorDate ? new Date(authorDate) : null;
return (
<div className={styles.optIdentity}>
<div className={styles.optIdentityFields}>
<label htmlFor={authorId}>
<>
<label className={styles.optField}>
<span>
<T>Author:</T>
</label>
</span>
<Input
id={authorId}
value={author}
title={tx(
preserveOriginal
@@ -55,6 +53,8 @@ export function CommitAuthorFields({
autoSelect={focusAuthor}
onChange={(e) => onChange({ author: e.target.value })}
/>
</label>
<div className={styles.optDate}>
<label htmlFor={authorDateId}>
<T>Author date</T>
</label>
@@ -81,6 +81,6 @@ export function CommitAuthorFields({
)}
</div>
</div>
</div>
</>
);
}
+13 -19
View File
@@ -309,7 +309,7 @@
}
/* Commit Options popup (gear next to Commit). */
.options {
width: 384px;
width: 340px;
max-height: min(560px, 80vh);
overflow: auto;
padding: 4px 16px 12px;
@@ -350,35 +350,29 @@
flex: 1;
min-width: 0;
}
.optIdentity {
container-type: inline-size;
}
.optIdentityFields {
display: grid;
grid-template-columns: minmax(0, 1fr);
.optField {
display: flex;
align-items: center;
gap: var(--space-1) var(--space-2);
gap: var(--space-2);
color: var(--fg);
font-size: var(--fs-ui);
}
.optIdentityFields > label {
overflow-wrap: anywhere;
.optField > :last-child {
flex: 1;
min-width: 0;
}
@container (min-width: 328px) {
.optIdentityFields {
grid-template-columns: fit-content(32%) minmax(0, 1fr);
row-gap: var(--space-1-5);
}
.optDate {
display: flex;
flex-direction: column;
gap: var(--space-1);
color: var(--fg);
}
.optDateInput {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: flex-end;
gap: var(--space-1);
}
.optDateInput input {
flex: 1 1 min(100%, 212px);
flex: 1;
min-width: 0;
}
.optLink {