From 708ceac09a193bbd05109bcd27c272177fb76e8c Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sun, 22 Nov 2026 01:47:53 +0800 Subject: [PATCH] fix(editor): keep editor banner messages and actions readable (#5050) Editor notification bars group their action links and let the message wrap at the width of the editor pane. Links stay on the same row when there is room and wrap below the message in narrower splits. The banner uses the UI text size and has smaller vertical insets in Compact Mode. --- e2e/editorBannerLayout.spec.ts | 59 ++++++++++ src/editor/core/view/Banner.tsx | 123 +++++++++++---------- src/editor/core/view/EditorArea.module.css | 82 +++++++------- 3 files changed, 166 insertions(+), 98 deletions(-) create mode 100644 e2e/editorBannerLayout.spec.ts diff --git a/e2e/editorBannerLayout.spec.ts b/e2e/editorBannerLayout.spec.ts new file mode 100644 index 000000000..592f71138 --- /dev/null +++ b/e2e/editorBannerLayout.spec.ts @@ -0,0 +1,59 @@ +import { expect, ipcCalls, openFromTree, stubDesktop, test } from "./fixtures"; + +test("editor notification actions stay inside narrow splits", async ({ workbench: page }) => { + await page.setViewportSize({ width: 1160, height: 720 }); + const editor = await openFromTree(page, "build.gradle.kts"); + await stubDesktop(page); + await page.evaluate(async () => { + const path = "/src/platform/project.ts"; + const { useProject } = await import(/* @vite-ignore */ path); + const settings = useProject.getState().settings; + window.__ipc.handlers.settings_set = ({ value }) => ({ + ...settings, + general: { powerSaveMode: value === "true" }, + }); + useProject.setState({ settings: { ...settings, general: { powerSaveMode: true } } }); + }); + const banners = page.getByRole("status").filter({ hasText: /^Power save mode is on/ }); + const message = banners.first().getByText(/^Power save mode is on/); + const turnOff = banners.first().getByRole("button", { name: "Turn Off" }); + await expect(turnOff).toBeVisible(); + await expect(message).toHaveCSS("font-size", "13px"); + const wide = (await message.boundingBox())!; + expect((await turnOff.boundingBox())!.y).toBeLessThan(wide.y + wide.height); + + await editor.locator(".cm-content").focus(); + await page.evaluate(async () => { + const path = "/src/platform/actions.ts"; + await (await import(/* @vite-ignore */ path)).executeAction("editor.splitRight"); + }); + await expect(banners).toHaveCount(2); + await page.setViewportSize({ width: 600, height: 720 }); + await expect + .poll( + () => + banners.evaluateAll((panels) => + panels.every((panel) => { + const box = panel.getBoundingClientRect(); + const action = panel.querySelector("button")!.getBoundingClientRect(); + return action.left >= box.left && action.right <= box.right && panel.scrollWidth <= panel.clientWidth + 1; + }), + ), + { message: "Turn Off fits inside each split editor notification" }, + ) + .toBe(true); + const narrow = (await message.boundingBox())!; + expect(narrow.height).toBeGreaterThan(wide.height * 1.5); + expect((await turnOff.boundingBox())!.y).toBeGreaterThanOrEqual(narrow.y + narrow.height); + + await expect(banners.first()).toHaveCSS("padding-top", "10px"); + await page.locator("html").evaluate((root) => root.setAttribute("data-compact", "")); + await expect(banners.first()).toHaveCSS("padding-top", "6px"); + await turnOff.press("Enter"); + await expect(banners).toHaveCount(0); + expect(await ipcCalls(page, "settings_set")).toContainEqual({ + scope: "global", + key: "general.powerSaveMode", + value: "false", + }); +}); diff --git a/src/editor/core/view/Banner.tsx b/src/editor/core/view/Banner.tsx index e4f4f4f44..4617f02f2 100644 --- a/src/editor/core/view/Banner.tsx +++ b/src/editor/core/view/Banner.tsx @@ -1,6 +1,6 @@ -import { useMemo } from "react"; +import { useMemo, type ReactNode } from "react"; import { Icon, T } from "@/ui"; -import { useEditorBanners, type EditorBannerContribution } from "@/workbench/contributions"; +import { useEditorBanners, type EditorBanner, type EditorBannerContribution } from "@/workbench/contributions"; import { useDocMeta } from "../model/document"; import styles from "./EditorArea.module.css"; import { classFileBreakpointReason } from "@/platform/classFiles"; @@ -43,79 +43,82 @@ export function VirtualBanner({ }) { const reason = classFileBreakpointReason(path); const sources = useLibrarySources(path, decompiled); + const message = decompiled + ? path.startsWith("csharp:") + ? "Decompiled assembly (read-only)." + : "Decompiled .class file: sources are not available." + : gitRevisionOf(path) + ? "File at a Git revision (read-only)." + : "Library source (read-only)."; + const actions: NonNullable = []; + if (sources.busy) { + actions.push({ label: "Cancel", run: () => void executeAction("editor.cancelSourceDownload", path) }); + } else { + if (sources.download) + actions.push({ label: "Download Sources", run: () => void executeAction("editor.downloadSources", path) }); + if (sources.choose) + actions.push({ label: "Choose Sources…", run: () => void executeAction("editor.chooseSources", path) }); + } return ( -
- - - {decompiled - ? path.startsWith("csharp:") - ? tx("Decompiled assembly (read-only).") - : tx("Decompiled .class file: sources are not available.") - : gitRevisionOf(path) - ? tx("File at a Git revision (read-only).") - : tx("Library source (read-only).")} + + + {message} {reason && ` ${tx(reason)}`} - {sources.message && {tx(sources.message)}} - {sources.busy ? ( + {sources.message && ( <> - {tx("Loading library sources…")} - + {" "} + {tx(sources.message)} - ) : ( + )} + {sources.busy && ( <> - {sources.download && ( - - )} - {sources.choose && ( - - )} + {" "} + + Loading library sources… + )} {description && ( - - {description} - + <> + {" "} + + {description} + + + )} + + ); +} + +function Banner({ icon, level, actions, children }: Omit & { children: ReactNode }) { + const warning = level === "warning"; + return ( +
+ + + {children} + + {!!actions?.length && ( +
+ {actions.map(({ label, run }) => ( + + ))} +
)}
); } function ContributedBanner({ banner, path }: { banner: EditorBannerContribution; path: string }) { - const b = banner.useBanner(path); - if (!b) return null; - return ( -
- - - {b.text} - - - {b.actions?.map((a) => ( - - ))} -
- ); + const notice = banner.useBanner(path); + return notice ? ( + + {notice.text} + + ) : null; } /** Banners features contribute for `path` (`registerEditorBanner`), in order. */ diff --git a/src/editor/core/view/EditorArea.module.css b/src/editor/core/view/EditorArea.module.css index 17a4bcf8a..d4c31972f 100644 --- a/src/editor/core/view/EditorArea.module.css +++ b/src/editor/core/view/EditorArea.module.css @@ -111,43 +111,64 @@ .banner { flex: none; display: flex; + flex-wrap: wrap; align-items: center; - gap: var(--space-2); - min-height: 36px; - padding: 0 12px; + gap: var(--space-1-5) var(--space-4); + padding: 10px var(--space-3); background: var(--bg-editor-banner, color-mix(in srgb, var(--accent) 7%, var(--bg-editor, var(--bg-elev)))); border-bottom: 1px solid var(--border-editor-tabs, var(--border)); + font-size: var(--fs-ui); color: var(--fg-strong); } -.bannerIcon { - color: var(--fg-muted); +:global(:root[data-compact]) .banner { + padding-block: var(--space-1-5); } -/* Library class notice (IDEA's yellowish decompiled-file bar). */ -.libraryBanner { - flex-wrap: wrap; +.warningBanner { background: var(--bg-feedback-warning); border-bottom-color: var(--border-feedback-warning); } -.virtualBannerText { - flex: none; +.bannerMessage { + display: flex; + flex: 1 1 auto; + align-items: flex-start; + gap: var(--space-2); min-width: 0; - padding: 8px 0; - white-space: nowrap; } -.bannerText { +.bannerIcon { flex: none; - white-space: nowrap; -} -.bannerDetail { - flex: 1; - min-width: 0; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; + margin-block-start: 1px; color: var(--fg-muted); } -.bannerSpacer { - flex: 1; +.bannerText { + min-width: 0; + overflow-wrap: anywhere; +} +.bannerDetail { + color: var(--fg-muted); +} +.bannerActions { + display: flex; + flex-wrap: wrap; + justify-content: flex-end; + gap: var(--space-1) var(--space-4); + max-width: 100%; + margin-inline-start: auto; +} +.bannerLink { + min-width: 0; + max-width: 100%; + padding: 0; + border: 0; + background: none; + color: var(--link); + font: inherit; + text-align: start; + overflow-wrap: anywhere; + cursor: pointer; +} +.bannerLink:hover { + color: var(--link-hover); + text-decoration: underline; } /* Find / replace bar */ @@ -498,18 +519,3 @@ .codeCrumbsBottom { border-top: 1px solid var(--border-editor-tabs, var(--border)); } - -/* Contributed editor banners (registerEditorBanner): text, then right-aligned links. */ -.bannerLink { - flex: none; - padding: 0; - border: 0; - background: none; - color: var(--link); - font: inherit; - cursor: pointer; -} -.bannerLink:hover { - color: var(--link-hover); - text-decoration: underline; -}