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", },