From 802400c324353dff925db516432f58e7ec2692f7 Mon Sep 17 00:00:00 2001 From: Muu Date: Fri, 20 Nov 2026 17:24:40 +0800 Subject: [PATCH] fix(editor): keep long blame tooltips inside a scroll container (#4741) Hovering the inline blame label of a commit with a long message spilled the tooltip over the workbench: it had only a max-width, and the shared editor theme never made the hover host a column flex container, so CodeMirror's height cap near the window edge did not clip it. The blame tooltip now caps its height and scrolls inside, and the base editor theme lets hover sections shrink inside the squeezed host (the rules LSP hovers already had). Co-authored-by: muutot <92625353+muutot@users.noreply.github.com> --- src/editor/core/cm/theme.ts | 5 ++++ src/editor/core/cm/tooltipHost.test.ts | 29 +++++++++++++++++++ .../vcs/__tests__/inlineBlame.test.ts | 7 +++++ src/features/vcs/inlineBlame.ts | 3 ++ 4 files changed, 44 insertions(+) create mode 100644 src/editor/core/cm/tooltipHost.test.ts diff --git a/src/editor/core/cm/theme.ts b/src/editor/core/cm/theme.ts index e59c512d1..b23c983fa 100644 --- a/src/editor/core/cm/theme.ts +++ b/src/editor/core/cm/theme.ts @@ -376,6 +376,11 @@ export const openideaTheme = EditorView.theme({ borderRadius: "var(--radius-popup)", boxShadow: "var(--shadow-popup)", }, + // Near the window edge CodeMirror caps the hover host's height; its sections then shrink and + // scroll inside the popup instead of running past its border. Content tooltips still carry + // their own `max-height` + `overflow` for the space they get when not squeezed. + ".cm-tooltip.cm-tooltip-hover": { display: "flex", flexDirection: "column" }, + ".cm-tooltip-hover > .cm-tooltip-section": { minHeight: 0, flexShrink: 1 }, ".cm-tooltip .cm-tooltip-arrow:before": { borderTopColor: "var(--border-popup)", borderBottomColor: "var(--border-popup)", diff --git a/src/editor/core/cm/tooltipHost.test.ts b/src/editor/core/cm/tooltipHost.test.ts new file mode 100644 index 000000000..04d6a46f8 --- /dev/null +++ b/src/editor/core/cm/tooltipHost.test.ts @@ -0,0 +1,29 @@ +import { afterEach, expect, it } from "vitest"; +import { EditorState } from "@codemirror/state"; +import { EditorView } from "@codemirror/view"; +import { openideaTheme } from "./theme"; + +let view: EditorView | null = null; +afterEach(() => { + view?.destroy(); + view = null; +}); + +it("shrinks hover tooltip sections near the window edge instead of spilling past the popup", () => { + view = new EditorView({ + state: EditorState.create({ extensions: [openideaTheme] }), + parent: document.body, + }); + // The DOM CodeMirror builds: the hover host wraps one section per tooltip. + const host = document.createElement("div"); + host.className = "cm-tooltip cm-tooltip-hover"; + const section = document.createElement("div"); + section.className = "cm-tooltip-section"; + host.appendChild(section); + view.dom.appendChild(host); + const hostStyle = getComputedStyle(host); + expect(hostStyle.display).toBe("flex"); + expect(hostStyle.flexDirection).toBe("column"); + // `min-height: 0` releases the section from the flex minimum so it can shrink and scroll. + expect(getComputedStyle(section).minHeight).toBe("0px"); +}); diff --git a/src/features/vcs/__tests__/inlineBlame.test.ts b/src/features/vcs/__tests__/inlineBlame.test.ts index 339ab9409..037a85991 100644 --- a/src/features/vcs/__tests__/inlineBlame.test.ts +++ b/src/features/vcs/__tests__/inlineBlame.test.ts @@ -484,4 +484,11 @@ describe("current line decoration", () => { // The visible label is the pointer/click region; the anchor stays zero-width. expect(inlineBlameTheme['.cm-vcs-inline-blame-inner[role="button"]']).toEqual({ cursor: "pointer" }); }); + + it("caps the commit tooltip's height and scrolls inside it, so a long message stays on screen", () => { + expect(inlineBlameTheme[".cm-vcs-inline-blame-tooltip"]).toMatchObject({ + maxHeight: expect.any(String), + overflow: "auto", + }); + }); }); diff --git a/src/features/vcs/inlineBlame.ts b/src/features/vcs/inlineBlame.ts index 10742f0d9..865f4d154 100644 --- a/src/features/vcs/inlineBlame.ts +++ b/src/features/vcs/inlineBlame.ts @@ -271,6 +271,9 @@ export const inlineBlameTheme = { ".cm-vcs-inline-blame-tooltip": { padding: "8px 12px", maxWidth: "min(70ch, 80vw)", + maxHeight: "min(420px, 55vh)", + overflow: "auto", + overscrollBehavior: "contain", whiteSpace: "pre-wrap", overflowWrap: "anywhere", },