mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
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.
This commit is contained in:
@@ -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",
|
||||
});
|
||||
});
|
||||
@@ -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<EditorBanner["actions"]> = [];
|
||||
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 (
|
||||
<div className={`${styles.banner} ${styles.libraryBanner}`} role="status">
|
||||
<Icon name={decompiled ? "info" : "lock"} size={14} className={styles.bannerIcon} />
|
||||
<span className={styles.virtualBannerText}>
|
||||
{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).")}
|
||||
<Banner icon={decompiled ? "info" : "lock"} level="warning" actions={actions}>
|
||||
<span>
|
||||
<T>{message}</T>
|
||||
{reason && ` ${tx(reason)}`}
|
||||
</span>
|
||||
{sources.message && <span>{tx(sources.message)}</span>}
|
||||
{sources.busy ? (
|
||||
{sources.message && (
|
||||
<>
|
||||
<span>{tx("Loading library sources…")}</span>
|
||||
<button
|
||||
type="button"
|
||||
className={styles.bannerLink}
|
||||
onClick={() => void executeAction("editor.cancelSourceDownload", path)}
|
||||
>
|
||||
<T>Cancel</T>
|
||||
</button>
|
||||
{" "}
|
||||
<span>{tx(sources.message)}</span>
|
||||
</>
|
||||
) : (
|
||||
)}
|
||||
{sources.busy && (
|
||||
<>
|
||||
{sources.download && (
|
||||
<button
|
||||
type="button"
|
||||
className={styles.bannerLink}
|
||||
onClick={() => void executeAction("editor.downloadSources", path)}
|
||||
>
|
||||
<T>Download Sources</T>
|
||||
</button>
|
||||
)}
|
||||
{sources.choose && (
|
||||
<button
|
||||
type="button"
|
||||
className={styles.bannerLink}
|
||||
onClick={() => void executeAction("editor.chooseSources", path)}
|
||||
>
|
||||
<T>Choose Sources…</T>
|
||||
</button>
|
||||
)}
|
||||
{" "}
|
||||
<span>
|
||||
<T>Loading library sources…</T>
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
{description && (
|
||||
<span className={styles.bannerDetail} title={description}>
|
||||
{description}
|
||||
</span>
|
||||
<>
|
||||
{" "}
|
||||
<span className={styles.bannerDetail} title={description}>
|
||||
{description}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</Banner>
|
||||
);
|
||||
}
|
||||
|
||||
function Banner({ icon, level, actions, children }: Omit<EditorBanner, "text"> & { children: ReactNode }) {
|
||||
const warning = level === "warning";
|
||||
return (
|
||||
<div className={`${styles.banner} ${warning ? styles.warningBanner : ""}`} role="status">
|
||||
<span className={styles.bannerMessage}>
|
||||
<Icon name={icon ?? (warning ? "warning" : "info")} size={16} className={styles.bannerIcon} />
|
||||
<span className={styles.bannerText}>{children}</span>
|
||||
</span>
|
||||
{!!actions?.length && (
|
||||
<div className={styles.bannerActions}>
|
||||
{actions.map(({ label, run }) => (
|
||||
<button key={label} type="button" className={styles.bannerLink} onClick={run}>
|
||||
<T>{label}</T>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ContributedBanner({ banner, path }: { banner: EditorBannerContribution; path: string }) {
|
||||
const b = banner.useBanner(path);
|
||||
if (!b) return null;
|
||||
return (
|
||||
<div className={`${styles.banner} ${b.level === "warning" ? styles.libraryBanner : ""}`} role="status">
|
||||
<Icon name={b.icon ?? (b.level === "warning" ? "warning" : "info")} size={14} className={styles.bannerIcon} />
|
||||
<span className={styles.bannerText}>
|
||||
<T>{b.text}</T>
|
||||
</span>
|
||||
<span className={styles.bannerSpacer} />
|
||||
{b.actions?.map((a) => (
|
||||
<button key={a.label} type="button" className={styles.bannerLink} onClick={a.run}>
|
||||
<T>{a.label}</T>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
const notice = banner.useBanner(path);
|
||||
return notice ? (
|
||||
<Banner icon={notice.icon} level={notice.level} actions={notice.actions}>
|
||||
<T>{notice.text}</T>
|
||||
</Banner>
|
||||
) : null;
|
||||
}
|
||||
|
||||
/** Banners features contribute for `path` (`registerEditorBanner`), in order. */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user