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 <[email protected]>
Цей коміт міститься в:
LU XIANGRUIтаwildcatDownstairs authored and GitHub committed 2026-12-02 11:20:42 +08:00
1 джерело 7361707b63
коміт 1eece0ae51
10 files changed
+82 -18

No files matched your search

+44 -1
Переглянути файл
@@ -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\)/,
);
});
});
+22 -1
Переглянути файл
@@ -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. */
+1 -1
Переглянути файл
@@ -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",
+4 -4
Переглянути файл
@@ -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;
+2 -2
Переглянути файл
@@ -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;
+1 -1
Переглянути файл
@@ -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;
+2 -2
Переглянути файл
@@ -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;
+2 -2
Переглянути файл
@@ -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;
+2 -2
Переглянути файл
@@ -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;
+2 -2
Переглянути файл
@@ -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;