From 507258daec34a7e40a007db43068c43614423deb Mon Sep 17 00:00:00 2001 From: Bert Verhelst Date: Mon, 23 Nov 2026 13:59:37 +0100 Subject: [PATCH] fix(editor): stop clipping Code Vision hints that are taller than 16px (#5418) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Code Vision row above a declaration (usage count, author) cut off the top or bottom of its text, most visibly for Chinese labels like "10 个用法" / "无用法". The row was a fixed `height: 16px` with `overflow: hidden`, while its text is the editor font size minus 1px. At larger editor fonts, or with CJK fallback fonts that ink below the Latin metrics (Microsoft YaHei, Noto Sans CJK), the glyphs didn't fit. The row now has `min-height: 16px`, and its items use `line-height: normal`, so the row grows to the ascent and descent of the fonts actually used. At the default font a Latin-only row is still exactly 16px. The line-end hint (Code Vision kinds set to "right") has the same 1em box with `overflow: hidden`. It keeps its size and position but now clips only horizontally. Co-authored-by: bertyhell <1710840+bertyhell@users.noreply.github.com> --- e2e/codeLensLayout.spec.ts | 52 ++++++++++++++++++++++++++++++++++ src/editor/core/cm/codeLens.ts | 12 ++++++-- 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 e2e/codeLensLayout.spec.ts diff --git a/e2e/codeLensLayout.spec.ts b/e2e/codeLensLayout.spec.ts new file mode 100644 index 000000000..a6e8fccb9 --- /dev/null +++ b/e2e/codeLensLayout.spec.ts @@ -0,0 +1,52 @@ +import type { Locator, Page } from "@playwright/test"; +import { expect, openFromTree, stubDesktop, test } from "./fixtures"; + +/** Opens the sample with the server's lenses `titles` above its first line, at editor font `fontSize`. */ +async function lensRow(page: Page, fontSize: number, titles: string[]): Promise<{ editor: Locator; row: Locator }> { + const editor = await openFromTree(page, "build.gradle.kts"); + await stubDesktop(page); + await page.evaluate( + async ({ fontSize, titles }) => { + const projectPath = "/src/platform/project.ts"; + const { useProject } = await import(/* @vite-ignore */ projectPath); + const settings = useProject.getState().settings; + useProject.setState({ settings: { ...settings, editor: { ...settings?.editor, fontSize } } }); + const at = { line: 0, col: 0 }; + window.__ipc.handlers.lsp_code_lens = () => + titles.map((title) => ({ range: { start: at, end: at }, command: { title, command: "noop", arguments: [] } })); + }, + { fontSize, titles }, + ); + // An edit asks the server for its lenses again. + await editor.locator(".cm-line").first().click(); + await page.keyboard.press("End"); + await page.keyboard.type(" "); + const row = editor.locator(".cm-openidea-lens"); + await expect(row).toContainText(titles[0]!); + return { editor, row }; +} + +test("a Code Vision row fits CJK hints at a large editor font", async ({ workbench: page }) => { + const { editor, row } = await lensRow(page, 20, ["10 个用法", "无用法"]); + const overflow = await row.evaluate((el) => { + const box = el.getBoundingClientRect(); + return [...el.querySelectorAll(".cm-openidea-lensItem")].map((item) => { + const range = document.createRange(); + range.selectNodeContents(item); + const text = range.getBoundingClientRect(); + return Math.max(box.top - text.top, text.bottom - box.bottom); + }); + }); + expect(overflow).toHaveLength(2); + for (const px of overflow) expect(px).toBeLessThanOrEqual(0); + // The editor measured the taller row: the lines below it still sit beside their numbers. + const line = editor.locator(".cm-line", { hasText: "class OrderController" }); + const number = editor.locator(".cm-lineNumbers .cm-gutterElement", { hasText: /^8$/ }); + const [lineTop, numberTop] = [(await line.boundingBox())!.y, (await number.boundingBox())!.y]; + expect(Math.abs(lineTop - numberTop)).toBeLessThanOrEqual(1); +}); + +test("a Code Vision row keeps its height at the default editor font", async ({ workbench: page }) => { + const { row } = await lensRow(page, 13, ["3 usages"]); + expect((await row.boundingBox())!.height).toBe(16); +}); diff --git a/src/editor/core/cm/codeLens.ts b/src/editor/core/cm/codeLens.ts index 4d64ccd00..dc476393b 100644 --- a/src/editor/core/cm/codeLens.ts +++ b/src/editor/core/cm/codeLens.ts @@ -238,11 +238,13 @@ function buildDecorations(state: EditorState): DecorationSet { const lensTheme = EditorView.theme({ // IDEA paints code vision with the colour scheme's Inline hints attribute. + // At least 16px, and taller when the hint font needs it: the row grows with its items, so a + // large editor font or a fallback font that inks below the baseline (CJK) is never cut off. ".cm-openidea-lens": { display: "flex", alignItems: "center", gap: "12px", - height: "16px", + minHeight: "16px", color: "var(--fg-inlay, var(--fg-muted))", WebkitUserSelect: "none", userSelect: "none", @@ -276,7 +278,10 @@ const lensTheme = EditorView.theme({ // Pinned to the line, the hint may run past the editor's edge (IDEA clips it there); cap it so a // long one cannot stretch across the whole window first. maxWidth: "min(60ch, 50vw)", - overflow: "hidden", + // The box is 1em tall (the anchor's `lineHeight: 1`): clip only past the side, so a glyph that + // inks above or below its em box (CJK fallback fonts) still shows whole. + overflowX: "clip", + overflowY: "visible", pointerEvents: "auto", }, ".cm-openidea-lensItem": { @@ -293,6 +298,9 @@ const lensTheme = EditorView.theme({ fontFamily: "var(--font-ui)", fontSize: "calc(1em - 1px)", }, + // The row's items size to the fonts their text is drawn with (fallback fonts included), not to the + // editor's line height, which `font: inherit` brings along. + ".cm-openidea-lens > .cm-openidea-lensItem": { lineHeight: "normal" }, ".cm-openidea-lensAction": { cursor: "pointer" }, ".cm-openidea-lensAction:hover": { color: "var(--accent)", textDecoration: "underline" }, ".cm-openidea-lensIcon-run": { color: "var(--success)" },