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]>
Цей коміт міститься в:
Deng Liuтаdengliu authored and GitHub committed 2026-11-28 20:29:29 +08:00
1 джерело 4c01ce4443
коміт 68abd00a7f
9 files changed
+92 -10

No files matched your search

+11
Переглянути файл
@@ -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);
}
+35 -1
Переглянути файл
@@ -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();
});
+19 -7
Переглянути файл
@@ -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,