дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-28 21:42:27 +02:00
fix(remote-dev): fix vertical text wrapping and clipping in resource tooltip (#6618)
A truncated element with a long data-tooltip put that text in the tooltip's shortcut slot (nowrap, keys font), which overflowed the bubble and crushed the main text to one character per line, as on the Remote Host Resources status item. The tooltip now shows such text as a wrapping note separate from the shortcut and honours data-no-tooltip up to the tooltip owner. The remote status items opt out of the redundant ellipsis tooltip and ellipsize their labels, and the breadcrumbs yield space first in the status bar. Co-authored-by: dengliu <[email protected]>
Цей коміт міститься в:
1 джерело
4c01ce4443
коміт
68abd00a7f
9 files changed
+92
-10
No files matched your search
@@ -109,6 +109,18 @@ test("shows compact remote CPU+RAM pill beside SSH status and opens detailed das
|
||||
await expect(pill).toBeVisible();
|
||||
await expect(pill).toContainText("22% · 5.8G");
|
||||
|
||||
// Hovering the pill (even on a narrow window) renders a single clean horizontal tooltip, never a vertical char stack.
|
||||
await page.setViewportSize({ width: 480, height: 700 });
|
||||
await pill.hover();
|
||||
const tooltip = page.getByRole("tooltip");
|
||||
await expect(tooltip).toBeVisible();
|
||||
await expect(tooltip).toContainText("CPU 22% · Memory 5.8 GB / 16 GB");
|
||||
await expect(tooltip).not.toContainText("22% · 5.8GCPU");
|
||||
const tipBox = (await tooltip.boundingBox())!;
|
||||
expect(tipBox.height).toBeLessThan(80);
|
||||
expect(tipBox.x + tipBox.width).toBeLessThanOrEqual(480);
|
||||
await page.setViewportSize({ width: 1280, height: 720 });
|
||||
|
||||
// Sits immediately to the right of the Remote Host status bar item.
|
||||
const leftOrder = await statusBar
|
||||
.locator(":scope > [data-status-item]")
|
||||
|
||||
@@ -88,5 +88,11 @@
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1);
|
||||
min-width: 0;
|
||||
color: var(--warning);
|
||||
}
|
||||
.statusLabel {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
@@ -48,6 +48,9 @@
|
||||
}
|
||||
|
||||
.pillText {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
|
||||
|
||||
@@ -120,6 +120,7 @@ export function RemoteResources() {
|
||||
pressure.level === "warn" && styles.levelWarn,
|
||||
pressure.level === "danger" && styles.levelDanger,
|
||||
)}
|
||||
data-no-tooltip=""
|
||||
aria-haspopup="dialog"
|
||||
aria-expanded={open}
|
||||
aria-label={tx`Remote host resources: ${tooltip}`}
|
||||
|
||||
@@ -27,6 +27,7 @@ export function RemoteStatus() {
|
||||
if (lost)
|
||||
return (
|
||||
<BarButton
|
||||
data-no-tooltip=""
|
||||
tooltip={
|
||||
reconnecting
|
||||
? tx`Reconnecting to ${session.host}…`
|
||||
@@ -40,12 +41,13 @@ export function RemoteStatus() {
|
||||
>
|
||||
<span className={styles.lost}>
|
||||
{reconnecting ? <Spinner size={10} /> : <Icon name="warning" size={13} />}
|
||||
{label}
|
||||
<span className={styles.statusLabel}>{label}</span>
|
||||
</span>
|
||||
</BarButton>
|
||||
);
|
||||
return (
|
||||
<BarButton
|
||||
data-no-tooltip=""
|
||||
tooltip={tx`Project runs on ${label}`}
|
||||
aria-label={label}
|
||||
onClick={() => void executeAction("remote.connect")}
|
||||
@@ -62,7 +64,7 @@ export function RemoteStatus() {
|
||||
}}
|
||||
>
|
||||
<Icon name="remote" size={13} />
|
||||
{label}
|
||||
<span className={styles.statusLabel}>{label}</span>
|
||||
</BarButton>
|
||||
);
|
||||
}
|
||||
@@ -22,10 +22,20 @@
|
||||
transition: opacity var(--dur-fast) var(--ease);
|
||||
}
|
||||
/* Long paths wrap inside the bubble; the shortcut stays on one line. */
|
||||
.withNote {
|
||||
flex-wrap: wrap;
|
||||
align-items: baseline;
|
||||
row-gap: var(--space-0-5);
|
||||
}
|
||||
.text {
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.note {
|
||||
min-width: 0;
|
||||
color: color-mix(in srgb, var(--fg-tooltip) 68%, transparent);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.shortcut {
|
||||
font-family: var(--font-keys);
|
||||
font-size: var(--fs-ui);
|
||||
@@ -43,6 +53,7 @@
|
||||
box-shadow: var(--shadow-stripe-tooltip, var(--shadow-tooltip));
|
||||
line-height: 18px;
|
||||
}
|
||||
.stripe .note,
|
||||
.stripe .shortcut {
|
||||
color: color-mix(in srgb, var(--fg-stripe-tooltip, var(--fg-tooltip)) 80%, transparent);
|
||||
}
|
||||
|
||||
@@ -180,7 +180,41 @@ it("shows a tab's cut-off title whole, with the tab's own tooltip beside it", ()
|
||||
act(() => {
|
||||
vi.advanceTimersByTime(TOOLTIP_DELAY);
|
||||
});
|
||||
expect(screen.getByRole("tooltip").textContent).toBe("历史记录: PscPrinted.js/repo/src/history/PscPrinted.js");
|
||||
const tip = screen.getByRole("tooltip");
|
||||
expect(tip.textContent).toBe("历史记录: PscPrinted.js/repo/src/history/PscPrinted.js");
|
||||
expect(tip).toHaveClass(styles.withNote!);
|
||||
expect(tip.querySelector(`.${styles.note!}`)?.textContent).toBe("/repo/src/history/PscPrinted.js");
|
||||
expect(tip.querySelector(`.${styles.shortcut!}`)).toBeNull();
|
||||
cleanup();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("respects data-no-tooltip on a tooltip owner so truncated children show only the owner's own tooltip", () => {
|
||||
vi.useFakeTimers();
|
||||
render(
|
||||
<>
|
||||
<TooltipHost />
|
||||
<button
|
||||
type="button"
|
||||
data-no-tooltip=""
|
||||
{...tooltipAttrs("CPU 1.8% · Memory 2.4 GB / 56 GB · RTT 128 ms", undefined, true)}
|
||||
>
|
||||
<span style={{ textOverflow: "ellipsis" }} data-testid="pill-text">
|
||||
1.8% · 2.4G
|
||||
</span>
|
||||
</button>
|
||||
</>,
|
||||
);
|
||||
const pillText = screen.getByTestId("pill-text");
|
||||
Object.defineProperty(pillText, "scrollWidth", { configurable: true, value: 120 });
|
||||
Object.defineProperty(pillText, "clientWidth", { configurable: true, value: 60 });
|
||||
fireEvent.pointerOver(pillText);
|
||||
act(() => {
|
||||
vi.advanceTimersByTime(TOOLTIP_DELAY);
|
||||
});
|
||||
const tip = screen.getByRole("tooltip");
|
||||
expect(tip.textContent).toBe("CPU 1.8% · Memory 2.4 GB / 56 GB · RTT 128 ms");
|
||||
expect(tip.querySelector(`.${styles.note!}`)).toBeNull();
|
||||
cleanup();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
@@ -30,31 +30,41 @@ const TRUNCATED_DEPTH = 4;
|
||||
|
||||
/** The element whose text is cut off with an ellipsis around `node`, up to `stop`, if any. */
|
||||
function truncatedText(node: Element | null, stop: Element | null): HTMLElement | null {
|
||||
if (stop?.hasAttribute("data-no-tooltip")) return null;
|
||||
let found: HTMLElement | null = null;
|
||||
for (let el = node, depth = 0; el instanceof HTMLElement && depth < TRUNCATED_DEPTH; el = el.parentElement, depth++) {
|
||||
// A native tooltip shows instead, or the element opts out of auto-ellipsis tooltips.
|
||||
if (el.hasAttribute("title") || el.hasAttribute("data-no-tooltip")) return null;
|
||||
if (isTruncated(el)) return el;
|
||||
if (!found && isTruncated(el)) found = el;
|
||||
if (el === stop) break;
|
||||
}
|
||||
return null;
|
||||
return found;
|
||||
}
|
||||
|
||||
const isTruncated = (el: HTMLElement) =>
|
||||
el.scrollWidth > el.clientWidth && getComputedStyle(el).textOverflow === "ellipsis" && !!el.textContent?.trim();
|
||||
|
||||
interface TooltipContent {
|
||||
text: string;
|
||||
note?: string;
|
||||
shortcut?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* What the tooltip of `el` shows: its own text, and the whole of `cut`'s text while that is
|
||||
* cut off (with its own text beside it, when that says something else).
|
||||
*/
|
||||
function tooltipText(el: HTMLElement, cut: HTMLElement | null): { text: string; note?: string } | undefined {
|
||||
function tooltipText(el: HTMLElement, cut: HTMLElement | null): TooltipContent | undefined {
|
||||
const own = el.dataset.tooltipVerbatim === undefined ? tx(el.dataset.tooltip) : el.dataset.tooltip;
|
||||
const shortcut = el.dataset.tooltipShortcut;
|
||||
const whole = cut?.isConnected && isTruncated(cut) ? cut.textContent!.trim().replace(/\s+/g, " ") : undefined;
|
||||
if (!whole) return own ? { text: own, note: el.dataset.tooltipShortcut } : undefined;
|
||||
return { text: whole, note: own && !own.includes(whole) ? own : undefined };
|
||||
if (!whole) return own ? { text: own, shortcut } : undefined;
|
||||
return { text: whole, note: own && !own.includes(whole) ? own : undefined, shortcut };
|
||||
}
|
||||
|
||||
interface Shown {
|
||||
text: string;
|
||||
note?: string;
|
||||
shortcut?: string;
|
||||
x: number;
|
||||
y: number;
|
||||
@@ -88,7 +98,8 @@ export function TooltipHost() {
|
||||
const stripe = el.dataset.tooltipStripe;
|
||||
setShown({
|
||||
text: shows.text,
|
||||
shortcut: shows.note,
|
||||
note: shows.note,
|
||||
shortcut: shows.shortcut,
|
||||
x: -9999,
|
||||
y: -9999,
|
||||
placed: false,
|
||||
@@ -168,11 +179,12 @@ export function TooltipHost() {
|
||||
<div
|
||||
ref={tipRef}
|
||||
role="tooltip"
|
||||
className={clsx(styles.tooltip, shown.stripe && styles.stripe)}
|
||||
className={clsx(styles.tooltip, shown.note && styles.withNote, shown.stripe && styles.stripe)}
|
||||
data-placed={shown.placed || undefined}
|
||||
style={{ left: shown.x, top: shown.y }}
|
||||
>
|
||||
<span className={styles.text}>{shown.text}</span>
|
||||
{shown.note && <span className={styles.note}>{shown.note}</span>}
|
||||
{shown.shortcut && <span className={styles.shortcut}>{shown.shortcut}</span>}
|
||||
</div>,
|
||||
document.body,
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
overflow: hidden;
|
||||
}
|
||||
.shrink[data-status-item="editor.breadcrumbs"]:not(:empty) {
|
||||
flex-shrink: 1000;
|
||||
min-width: min(152px, 28vw);
|
||||
}
|
||||
.shrink > * {
|
||||
|
||||
Reference in new issue
Заблокувати користувача