From 1eece0ae51f76ee93b2136bfe72aa67b0265878f Mon Sep 17 00:00:00 2001 From: LU XIANGRUI <1078666705@qq.com> Date: Wed, 2 Dec 2026 12:20:42 +0900 Subject: [PATCH] fix(editor): scale gutter icons with the editor font zoom (#7352) Gutter icons kept a fixed 14px while the editor font zoomed. They now follow the font size through --openidea-gutter-icon-size (14px at the default size, within 10-32px), applied to the icon area, the http/GraphQL/database run gutters and the feature icon wrappers. Closes #7332 Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com> --- src/editor/core/cm/iconArea.test.ts | 45 ++++++++++++++++++- src/editor/core/cm/iconArea.ts | 23 +++++++++- src/editor/core/cm/renderedDocs.ts | 2 +- src/editor/navigation/LineMarkers.module.css | 8 ++-- .../build-tools/PomNavigation.module.css | 4 +- src/features/database/Database.module.css | 2 +- src/features/graphql/GraphQL.module.css | 4 +- .../http-client/HttpClient.module.css | 4 +- src/features/run/Run.module.css | 4 +- src/features/services/Services.module.css | 4 +- 10 files changed, 82 insertions(+), 18 deletions(-) diff --git a/src/editor/core/cm/iconArea.test.ts b/src/editor/core/cm/iconArea.test.ts index 16b308cb57..823551b3ba 100644 --- a/src/editor/core/cm/iconArea.test.ts +++ b/src/editor/core/cm/iconArea.test.ts @@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { fireEvent } from "@testing-library/react"; import { EditorState, RangeSet, StateEffect, StateField } from "@codemirror/state"; import { EditorView, GutterMarker } from "@codemirror/view"; -import { SETTLE_MS, iconAreaExtension, iconAreaSource, mapLineStart } from "./iconArea"; +import { GUTTER_ICON_SIZE, SETTLE_MS, iconAreaExtension, iconAreaSource, mapLineStart } from "./iconArea"; class Dot extends GutterMarker { constructor(readonly name: string) { @@ -169,3 +169,46 @@ it("moves a line's marker down with its text when Enter is pressed at the line's // Joined into the line above, it goes with its text. expect(after(1, "", lineB)).toBe(0); }); + +describe("icon size under font zoom", () => { + // The px the CSS resolves to for an editor font of `font` px. + function sizeAt(font: number): number { + const m = + /^clamp\((\d+)px, calc\(var\(--openidea-editor-font-size, var\(--fs-code\)\) \+ (\d+)px\), (\d+)px\)$/.exec( + GUTTER_ICON_SIZE, + ); + if (!m) throw new Error(`unexpected size: ${GUTTER_ICON_SIZE}`); + return Math.min(Number(m[3]), Math.max(Number(m[1]), font + Number(m[2]))); + } + + it.each([ + [13, 14], // default font: the 14px icons + [7, 10], // zoomed out to the smallest font: kept clickable + [9, 10], + [10, 11], + [16, 17], + [20, 21], + [31, 32], + [49, 32], // zoomed in to the largest font: capped + ])("a %ipx font gives %ipx icons", (font, size) => { + expect(sizeAt(font)).toBe(size); + }); + + const css = () => [...document.querySelectorAll("style")].map((s) => s.textContent).join("\n"); + + it("sets the size on the editor and sizes the spacer, so lines with and without icons stay aligned", () => { + open([{ order: 10, markers: (view) => RangeSet.of([new Dot("run").range(lineStart(view.state, 1))]) }]); + expect(css()).toContain(`--openidea-gutter-icon-size: ${GUTTER_ICON_SIZE}`); + expect(css()).toMatch(/\.cm-openidea-iconSpacer \{[^}]*width: var\(--openidea-gutter-icon-size, 14px\)/); + }); + + it("scales the 14px and 12px icon markup in the icon gutters, keeping the play glyph's ratio", () => { + open([]); + expect(css()).toMatch( + /\.cm-openidea-iconArea svg\[width="14"\][^{]*\{[^}]*width: var\(--openidea-gutter-icon-size, 14px\)/, + ); + expect(css()).toMatch( + /\.cm-openidea-db-gutter svg\[width="12"\][^{]*\{[^}]*width: calc\(var\(--openidea-gutter-icon-size, 14px\) \* 6 \/ 7\)/, + ); + }); +}); diff --git a/src/editor/core/cm/iconArea.ts b/src/editor/core/cm/iconArea.ts index 7a837a5b1a..f42fb737af 100644 --- a/src/editor/core/cm/iconArea.ts +++ b/src/editor/core/cm/iconArea.ts @@ -138,7 +138,28 @@ const areaGutter = gutter({ }, }); +/** + * The size of a gutter icon, as IDEA scales its gutter icons with the editor font: 14px at the + * default 13px font, one px larger than the font when zoomed, within 10..32px so icons stay + * clickable when zoomed out and don't crowd the code when zoomed in. Whole px, so SVGs stay crisp. + */ +export const GUTTER_ICON_SIZE = "clamp(10px, calc(var(--openidea-editor-font-size, var(--fs-code)) + 1px), 32px)"; +const iconSize = "var(--openidea-gutter-icon-size, 14px)"; +const smallIcon = `calc(${iconSize} * 6 / 7)`; +/** The gutters of icons: this area, and the run columns of `.http`, GraphQL and database consoles. */ +const iconGutters = [ + ".cm-openidea-iconArea", + ".cm-openidea-gutter-http", + ".cm-openidea-gutter-graphql", + ".cm-openidea-db-gutter", +]; + const areaTheme = EditorView.baseTheme({ + // On the editor, so every gutter (and the icons' wrappers in feature CSS) reads one size. + "&": { "--openidea-gutter-icon-size": GUTTER_ICON_SIZE }, + // Icon markup carries a fixed 14px (12px for the plain play glyph, see `gutterIconMarkup`). + [iconGutters.map((g) => `${g} svg[width="14"]`).join(", ")]: { width: iconSize, height: iconSize }, + [iconGutters.map((g) => `${g} svg[width="12"]`).join(", ")]: { width: smallIcon, height: smallIcon }, ".cm-openidea-iconArea .cm-gutterElement": { display: "flex", alignItems: "center", @@ -152,7 +173,7 @@ const areaTheme = EditorView.baseTheme({ }, // The spacer's icons are laid out as the line's own. ".cm-openidea-iconAreaSpacer": { display: "contents" }, - ".cm-openidea-iconSpacer": { display: "inline-block", width: "14px" }, + ".cm-openidea-iconSpacer": { display: "inline-block", width: iconSize }, }); /** Installed in every editor; empty (no width) while no source has markers or reserves room. */ diff --git a/src/editor/core/cm/renderedDocs.ts b/src/editor/core/cm/renderedDocs.ts index 474bb36c60..8c70e9de19 100644 --- a/src/editor/core/cm/renderedDocs.ts +++ b/src/editor/core/cm/renderedDocs.ts @@ -916,7 +916,7 @@ const docsTheme = EditorView.theme({ alignItems: "center", justifyContent: "center", // An icon's width, like the other icons of the area, so showing it doesn't widen the area. - width: "14px", + width: "var(--openidea-gutter-icon-size, 14px)", height: "var(--openidea-editor-line-height, var(--lh-code))", padding: "0", border: "none", diff --git a/src/editor/navigation/LineMarkers.module.css b/src/editor/navigation/LineMarkers.module.css index 1ee0df69af..e80e45e283 100644 --- a/src/editor/navigation/LineMarkers.module.css +++ b/src/editor/navigation/LineMarkers.module.css @@ -1,7 +1,7 @@ /* Editor gutter inheritance icons (implemented / overridden / implementing / overriding). */ .marker { - width: 14px; - height: 14px; + width: var(--openidea-gutter-icon-size, 14px); + height: var(--openidea-gutter-icon-size, 14px); display: flex; align-items: center; justify-content: center; @@ -11,8 +11,8 @@ /* Python stub / implementation icon (a button, so it also works from the keyboard). */ .stubMarker { - width: 14px; - height: 14px; + width: var(--openidea-gutter-icon-size, 14px); + height: var(--openidea-gutter-icon-size, 14px); display: flex; align-items: center; justify-content: center; diff --git a/src/features/build-tools/PomNavigation.module.css b/src/features/build-tools/PomNavigation.module.css index fa7870a968..78c0afa815 100644 --- a/src/features/build-tools/PomNavigation.module.css +++ b/src/features/build-tools/PomNavigation.module.css @@ -1,7 +1,7 @@ /* IDEA's Navigate to Managing Dependency icon in the shared editor icon area. */ .managedMarker { - width: 14px; - height: 14px; + width: var(--openidea-gutter-icon-size, 14px); + height: var(--openidea-gutter-icon-size, 14px); display: flex; align-items: center; justify-content: center; diff --git a/src/features/database/Database.module.css b/src/features/database/Database.module.css index e28846e7a1..ed2b168bd4 100644 --- a/src/features/database/Database.module.css +++ b/src/features/database/Database.module.css @@ -850,7 +850,7 @@ user-select: none; } :global(.cm-openidea-db-gutter) { - width: 16px; + width: calc(var(--openidea-gutter-icon-size, 14px) + 2px); } :global(.cm-openidea-db-gutter .cm-gutterElement) { display: flex; diff --git a/src/features/graphql/GraphQL.module.css b/src/features/graphql/GraphQL.module.css index 01fd83ca13..62d077459e 100644 --- a/src/features/graphql/GraphQL.module.css +++ b/src/features/graphql/GraphQL.module.css @@ -209,8 +209,8 @@ justify-content: flex-start; } .runMarker { - width: 14px; - height: 14px; + width: var(--openidea-gutter-icon-size, 14px); + height: var(--openidea-gutter-icon-size, 14px); display: flex; align-items: center; justify-content: center; diff --git a/src/features/http-client/HttpClient.module.css b/src/features/http-client/HttpClient.module.css index babaf06830..e61d1481bc 100644 --- a/src/features/http-client/HttpClient.module.css +++ b/src/features/http-client/HttpClient.module.css @@ -6,8 +6,8 @@ justify-content: flex-end; } .runMarker { - width: 14px; - height: 14px; + width: var(--openidea-gutter-icon-size, 14px); + height: var(--openidea-gutter-icon-size, 14px); display: flex; align-items: center; justify-content: center; diff --git a/src/features/run/Run.module.css b/src/features/run/Run.module.css index 7a29d2056e..c7fc269593 100644 --- a/src/features/run/Run.module.css +++ b/src/features/run/Run.module.css @@ -1188,8 +1188,8 @@ justify-content: flex-end; } .runMarker { - width: 14px; - height: 14px; + width: var(--openidea-gutter-icon-size, 14px); + height: var(--openidea-gutter-icon-size, 14px); display: flex; align-items: center; justify-content: center; diff --git a/src/features/services/Services.module.css b/src/features/services/Services.module.css index 3f1954ea0f..055063fc92 100644 --- a/src/features/services/Services.module.css +++ b/src/features/services/Services.module.css @@ -149,8 +149,8 @@ border: 0; background: transparent; color: inherit; - width: 14px; - height: 14px; + width: var(--openidea-gutter-icon-size, 14px); + height: var(--openidea-gutter-icon-size, 14px); display: flex; align-items: center; justify-content: center;