дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
Three inline marks still painted only their font box: the warning lint fill (a flat background-color), the Usages preview match, and the Cmd/Ctrl-hover link, whose pointer cursor stopped at the font so the gap above and below the word showed the I-beam. They now use the inlineBg pattern: the mark grows to the row with padding-block and the fill is a 1lh-capped gradient centred in it; the link only needs the padding. An unnecessary warning still drops the fill, and the active warning keeps it. The usage contrast e2e check reads the fill from the gradient. Closes #7105, closes #7106, closes #7107 Co-authored-by: Inf1mum <[email protected]> Co-authored-by: Inf1mum <[email protected]>
159 рядки
7.3 KiB
TypeScript
159 рядки
7.3 KiB
TypeScript
import { expect, stubDesktop, test } from "./fixtures";
|
|
import { expect as baseExpect, test as baseTest } from "@playwright/test";
|
|
|
|
// Inline marks (lint ranges, Usages preview matches, ⌘-hover links) paint only their font box.
|
|
// With the default 13 px font on a taller line the box leaves gaps above and below the text, so
|
|
// background fills look clipped and the pointer cursor stops where the font box stops (#7105,
|
|
// #7106, #7107). A fill covers the whole row: the mark grows to the row (padding) and the fill
|
|
// is a gradient centred in that box capped at 1lh, so it paints exactly the row, never bleeding.
|
|
|
|
test("a warning's background fill covers the whole row", async ({ workbench: page }, info) => {
|
|
const path = "/dev/acme-api/src/Settlement.ts";
|
|
await page.evaluate(
|
|
async ({ path }) => {
|
|
const backend = "/src/editor/core/backend.ts";
|
|
(await import(/* @vite-ignore */ backend)).docBackend().files.set(path, "const settlement = total;\n");
|
|
const service = "/src/workbench/contributions.ts";
|
|
await (await import(/* @vite-ignore */ service)).editorService().openFile(path);
|
|
},
|
|
{ path },
|
|
);
|
|
await expect(page.locator(".cm-content")).toContainText("settlement");
|
|
await stubDesktop(page);
|
|
await page.evaluate(
|
|
async ({ path }) => {
|
|
const diagnostic = "/src/editor/lsp/diagnostics.ts";
|
|
(await import(/* @vite-ignore */ diagnostic)).setFileDiagnostics(path, "settlement-lint", [
|
|
{
|
|
severity: "warning",
|
|
message: "Review the reported total.",
|
|
range: { start: { line: 0, col: 6 }, end: { line: 0, col: 16 } },
|
|
source: "settlement-lint",
|
|
code: "review",
|
|
},
|
|
]);
|
|
},
|
|
{ path },
|
|
);
|
|
const warning = page.locator(".cm-content .cm-lintRange-warning");
|
|
await expect(warning).toHaveText("settlement");
|
|
const fill = await warning.evaluate((el) => {
|
|
const row = (el.closest(".cm-line") as HTMLElement).getBoundingClientRect();
|
|
const box = el.getBoundingClientRect();
|
|
// The gradient paints min(box, 1lh) centred in the box; the line's height is 1lh.
|
|
const paintHeight = Math.min(box.height, row.height);
|
|
const paintTop = box.top + (box.height - paintHeight) / 2;
|
|
return {
|
|
paintHeight,
|
|
paintTop,
|
|
rowHeight: row.height,
|
|
rowTop: row.top,
|
|
image: getComputedStyle(el).backgroundImage,
|
|
};
|
|
});
|
|
expect(fill.image, "the fill is a capped gradient, not a flat box colour").toContain("linear-gradient");
|
|
expect(fill.paintHeight, "the fill is as tall as the row").toBeCloseTo(fill.rowHeight, 0);
|
|
expect(Math.abs(fill.paintTop - fill.rowTop), "the fill starts at the row's top").toBeLessThanOrEqual(1);
|
|
await page.screenshot({ path: info.outputPath("warning-row-fill.png"), animations: "disabled" });
|
|
});
|
|
|
|
test("the Usages preview match covers the whole row", async ({ workbench: page }, info) => {
|
|
await stubDesktop(page);
|
|
await page.evaluate(async () => {
|
|
const modulePath = "/src/features/code-insight/usages.ts";
|
|
const { useUsagesPopup } = await import(modulePath);
|
|
const path = "/dev/acme-api/src/SettlementService.ts";
|
|
const lines = ["const current = settlement;", "settlement = next;"];
|
|
window.__ipc.handlers.fs_read_text = () => lines.join("\n");
|
|
useUsagesPopup.setState({
|
|
open: true,
|
|
anchor: { x: 100, y: 150 },
|
|
symbol: "settlement",
|
|
loading: false,
|
|
scope: "project",
|
|
groups: [
|
|
{
|
|
path,
|
|
usages: lines.map((text, line) => ({
|
|
path,
|
|
line,
|
|
col: text.indexOf("settlement"),
|
|
endCol: text.indexOf("settlement") + "settlement".length,
|
|
text,
|
|
access: line === 0 ? "read" : "write",
|
|
})),
|
|
},
|
|
],
|
|
});
|
|
});
|
|
const popup = page.getByRole("dialog", { name: "Usages", exact: true });
|
|
await expect(popup.getByRole("option")).toHaveCount(2);
|
|
await popup.getByRole("button", { name: /Open in Find Window/ }).click();
|
|
const view = page.getByRole("region", { name: "Find Usages", exact: true });
|
|
const mark = view.locator("mark").first();
|
|
await expect(mark).toHaveText("settlement");
|
|
const fill = await mark.evaluate((el) => {
|
|
const row = (el.parentElement as HTMLElement).getBoundingClientRect();
|
|
const box = el.getBoundingClientRect();
|
|
const paintHeight = Math.min(box.height, row.height);
|
|
const paintTop = box.top + (box.height - paintHeight) / 2;
|
|
return {
|
|
paintHeight,
|
|
paintTop,
|
|
rowHeight: row.height,
|
|
rowTop: row.top,
|
|
image: getComputedStyle(el).backgroundImage,
|
|
};
|
|
});
|
|
expect(fill.image, "the fill is a capped gradient, not a flat box colour").toContain("linear-gradient");
|
|
expect(fill.paintHeight, "the match is as tall as its preview row").toBeCloseTo(fill.rowHeight, 0);
|
|
expect(fill.paintTop, "the match starts at the row's top").toBeCloseTo(fill.rowTop, 0);
|
|
await page.screenshot({ path: info.outputPath("usages-match-row-fill.png"), animations: "disabled" });
|
|
});
|
|
|
|
// The navigation path needs a resolving target, which the configurationNavigation fixture
|
|
// provides (a stubbed `lspGoto` behind a real CodeMirror editor).
|
|
baseTest("the navigation cursor covers the row's gap above and below the font", async ({ page }) => {
|
|
await page.addInitScript(() => Object.defineProperty(Navigator.prototype, "platform", { get: () => "MacIntel" }));
|
|
await page.goto("/e2e/configurationNavigation.html");
|
|
await expect(page.locator("#config .cm-content")).toContainText("driver-class-name");
|
|
// The same ⌘-hover word, on a line tall enough to have gaps around the font box.
|
|
await page.addStyleTag({ content: "#config .cm-editor { --lh-code: 34px; }" });
|
|
const glyph = await page.evaluate(() => {
|
|
const lines = document.querySelectorAll("#config .cm-content .cm-line");
|
|
for (const line of lines) {
|
|
const walker = document.createTreeWalker(line, NodeFilter.SHOW_TEXT);
|
|
let node: Text | null = null;
|
|
let at = -1;
|
|
while ((node = walker.nextNode() as Text | null)) {
|
|
at = node.data.indexOf("driver-class-name");
|
|
if (at >= 0) break;
|
|
}
|
|
if (!node || at < 0) continue;
|
|
const range = document.createRange();
|
|
range.setStart(node, at);
|
|
range.setEnd(node, at + "driver-class-name".length);
|
|
const box = range.getBoundingClientRect();
|
|
return { x: box.x + box.width / 2, top: box.top, bottom: box.bottom };
|
|
}
|
|
throw new Error("key text node not found");
|
|
});
|
|
await page.keyboard.down("Meta");
|
|
await page.mouse.move(glyph.x, (glyph.top + glyph.bottom) / 2);
|
|
await expect(page.locator("#config .cm-lsp-link")).toHaveText("driver-class-name");
|
|
// A point in the key's own row's gap, above the glyph box but inside the same line.
|
|
const rowTop = await page.evaluate(
|
|
() =>
|
|
(document.querySelector("#config .cm-lsp-link") as HTMLElement).closest(".cm-line")!.getBoundingClientRect().top,
|
|
);
|
|
const gap = { x: glyph.x, y: rowTop + 1 };
|
|
await page.mouse.move(gap.x, gap.y);
|
|
const cursor = await page.evaluate(({ x, y }) => {
|
|
const el = document.elementFromPoint(x, y) as Element | null;
|
|
const link = el?.closest(".cm-lsp-link") as HTMLElement | null;
|
|
return link ? getComputedStyle(link).cursor : null;
|
|
}, gap);
|
|
baseExpect(cursor, "hovering the row's gap inside the word is the link, pointer cursor and all").toBe("pointer");
|
|
await page.keyboard.up("Meta");
|
|
});
|