diff --git a/e2e/editorLineNumbersLayout.spec.ts b/e2e/editorLineNumbersLayout.spec.ts new file mode 100644 index 000000000..a3c2d9b63 --- /dev/null +++ b/e2e/editorLineNumbersLayout.spec.ts @@ -0,0 +1,44 @@ +import { expect, test } from "./fixtures"; + +test("line numbers stay smaller than the code and leave room for a breakpoint", async ({ workbench: page }) => { + await page.evaluate(async () => { + const backendPath = "/src/editor/core/backend.ts"; + const servicesPath = "/src/workbench/contributions.ts"; + const { docBackend } = await import(/* @vite-ignore */ backendPath); + const { editorService } = await import(/* @vite-ignore */ servicesPath); + const path = "/dev/acme-api/queue.ts"; + docBackend().files.set(path, ["const queue = [1, 2, 3];", "queue.push(4);", "console.log(queue);"].join("\n")); + await editorService().openFile(path); + }); + const editor = page.locator('.cm-editor[data-language="TypeScript"]'); + const content = editor.locator(".cm-content"); + const number = editor.locator(".cm-lineNumbers").getByText("2", { exact: true }); + await expect(number).toBeVisible(); + const size = await content.evaluate((element) => Number.parseFloat(getComputedStyle(element).fontSize)); + await expect(number).toHaveCSS("font-size", `${size - 1}px`); + await expect(number).toHaveCSS("padding-inline-start", "4px"); + await expect(number).toHaveCSS("padding-inline-end", "4px"); + const column = editor.locator(".cm-lineNumbers"); + expect((await column.boundingBox())!.width).toBeCloseTo(24, 0); + + await number.click(); + const markerSize = () => number.evaluate((element) => getComputedStyle(element, "::before").width); + await expect.poll(markerSize).toBe(`${size}px`); + await expect + .poll(() => + number.evaluate((element) => { + const marker = getComputedStyle(element, "::before"); + return element.clientWidth - Number.parseFloat(marker.left) - Number.parseFloat(marker.width) / 2; + }), + ) + .toBeCloseTo(4, 0); + + await content.press("Alt+Shift+."); + await expect(content).toHaveCSS("font-size", `${size + 1}px`); + await expect(number).toHaveCSS("font-size", `${size}px`); + await expect(number).toHaveCSS( + "line-height", + await content.evaluate((element) => getComputedStyle(element).lineHeight), + ); + await expect.poll(markerSize).toBe(`${size + 1}px`); +}); diff --git a/e2e/stickyLinesLayout.spec.ts b/e2e/stickyLinesLayout.spec.ts index f69c40bd8..0e02c70d6 100644 --- a/e2e/stickyLinesLayout.spec.ts +++ b/e2e/stickyLinesLayout.spec.ts @@ -89,6 +89,8 @@ test("Sticky Lines follows editor text, line numbers and the viewport below Find expect(pinnedGutter!.width).toBeCloseTo(liveGutter!.width, 0); expect(await codeStart(text)).toBeCloseTo(liveX, 0); await expect(sticky).toHaveCSS("font-size", "16px"); + await expect(sticky.locator(".cm-openidea-stickyNumber").first()).toHaveCSS("font-size", "15px"); + await expect(editor.locator(".cm-lineNumbers .cm-gutterElement").first()).toHaveCSS("font-size", "15px"); await expect(sticky).toHaveCSS("tab-size", await content.evaluate((element) => getComputedStyle(element).tabSize)); await scroller.evaluate((element) => { element.scrollLeft = 32; diff --git a/src/editor/core/cm/theme.ts b/src/editor/core/cm/theme.ts index 64649a1ca..6978afdba 100644 --- a/src/editor/core/cm/theme.ts +++ b/src/editor/core/cm/theme.ts @@ -255,8 +255,9 @@ export const openideaTheme = EditorView.theme({ userSelect: "none", }, ".cm-lineNumbers .cm-gutterElement, .cm-openidea-stickyNumber": { - minWidth: "32px", - padding: "0 8px 0 10px", + minWidth: "calc(max(16px, var(--openidea-editor-font-size, var(--fs-code))) + var(--space-2))", + paddingInline: "var(--space-1)", + fontSize: "max(1px, calc(var(--openidea-editor-font-size, var(--fs-code)) - 1px))", textAlign: "right", fontVariantNumeric: "tabular-nums", }, diff --git a/src/features/debugger/editor/editor.module.css b/src/features/debugger/editor/editor.module.css index 40cb4f876..840180e24 100644 --- a/src/features/debugger/editor/editor.module.css +++ b/src/features/debugger/editor/editor.module.css @@ -1,7 +1,4 @@ -/* - * Line-number gutter element class; the marker is a pseudo-element that, like - * IDEA, replaces the number (centred on the element's content box). - */ +/* The marker replaces the number and shares its trailing edge. */ .bp { position: relative; color: transparent !important; @@ -10,8 +7,9 @@ .bp::before { content: ""; position: absolute; - left: calc(50% + 1px); + left: calc(100% - var(--space-1) - 0.5em); top: 50%; + font-size: var(--openidea-editor-font-size, var(--fs-code)); width: 1em; height: 1em; transform: translate(-50%, -50%);