Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions frontend/src/components/ui/native-title-tooltip-host.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { NATIVE_TITLE_SHOW_DELAY_MS } from './native-title-tooltip';
describe('NativeTitleTooltipHost', () => {
beforeEach(() => {
vi.useFakeTimers();
vi.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockReturnValue(80);
vi.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(28);
});

afterEach(() => {
Expand Down Expand Up @@ -124,6 +126,69 @@ describe('NativeTitleTooltipHost', () => {
);
});

it('keeps a conversation-tab tooltip hidden until its measured width is centered', () => {
vi.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockReturnValue(0);
vi.spyOn(window, 'requestAnimationFrame').mockImplementation(() => 1);

render(
<div>
<NativeTitleTooltipHost />
<button type="button" title="新会话4">
新会话4
</button>
</div>
);

fireEvent.pointerOver(screen.getByRole('button', { name: '新会话4' }), {
pointerType: 'mouse',
});
act(() => {
vi.advanceTimersByTime(NATIVE_TITLE_SHOW_DELAY_MS);
});

const tooltip = screen.getByRole('tooltip', { hidden: true });
expect(tooltip).toHaveStyle({ visibility: 'hidden' });
expect(tooltip).not.toHaveAttribute('data-placed');
});

it('centers the tooltip on the measured capsule before showing it', () => {
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({
top: 40,
left: 200,
width: 92,
height: 28,
right: 292,
bottom: 68,
x: 200,
y: 40,
toJSON() {
return this;
},
} as DOMRect);
vi.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockReturnValue(120);
vi.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(28);

render(
<div>
<NativeTitleTooltipHost />
<button type="button" title="新会话4">
新会话4
</button>
</div>
);

fireEvent.pointerOver(screen.getByRole('button', { name: '新会话4' }), {
pointerType: 'mouse',
});
act(() => {
vi.advanceTimersByTime(NATIVE_TITLE_SHOW_DELAY_MS);
});

const tooltip = screen.getByRole('tooltip');
expect(tooltip).toHaveAttribute('data-placed', 'true');
expect(tooltip).toHaveStyle({ left: '186px', visibility: 'visible' });
});

it('does not mount a native surface occlusion hold and hides on pointerout into native child surfaces', () => {
render(
<div>
Expand Down
69 changes: 37 additions & 32 deletions frontend/src/components/ui/native-title-tooltip-host.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import { usePortalContainer } from '@/contexts/PortalContainerContext';
import {
Expand All @@ -17,27 +17,32 @@ type TooltipState = {
left: number;
side: 'bottom' | 'top';
arrowLeft: number;
placed: boolean;
};

function isMousePointer(event: PointerEvent): boolean {
return event.pointerType === 'mouse' || event.pointerType === '';
}

function estimateTooltipWidth(text: string): number {
let width = 24;
for (const ch of text) {
width += ch.charCodeAt(0) > 0x7f ? 12.5 : 7.2;
}
return Math.min(352, Math.max(48, Math.ceil(width)));
function unplacedTooltip(text: string): TooltipState {
return {
text,
top: 0,
left: 0,
side: 'bottom',
arrowLeft: 0,
placed: false,
};
}

export function NativeTitleTooltipHost() {
const container = usePortalContainer();
const tooltipRef = useRef<HTMLDivElement>(null);
const anchorRef = useRef<Element | null>(null);
const [tooltip, setTooltip] = useState<TooltipState | null>(null);

useEffect(() => {
let showTimer: number | null = null;
let rafId: number | null = null;
let active: Element | null = null;
let observer: MutationObserver | null = null;
const suppressed = new Set<Element>();
Expand All @@ -47,10 +52,6 @@ export function NativeTitleTooltipHost() {
window.clearTimeout(showTimer);
showTimer = null;
}
if (rafId != null) {
window.cancelAnimationFrame(rafId);
rafId = null;
}
};

const suppress = (element: Element) => {
Expand All @@ -63,26 +64,16 @@ export function NativeTitleTooltipHost() {
observer?.disconnect();
observer = null;
active = null;
anchorRef.current = null;
setTooltip(null);
};

const place = (element: Element, text: string) => {
const node = document.querySelector<HTMLElement>(
`.${NATIVE_TITLE_TOOLTIP_CLASS}[data-native-title-tooltip='true']`
);
const tooltipSize =
node && node.offsetWidth > 0 && node.offsetHeight > 0
? { width: node.offsetWidth, height: node.offsetHeight }
: {
width: estimateTooltipWidth(text),
height: 28,
};
const next = positionHoverTooltip(
element.getBoundingClientRect(),
tooltipSize,
{ width: window.innerWidth, height: window.innerHeight }
);
setTooltip({ text, ...next });
anchorRef.current = element;
// Publish text only. The measured width is not known until the capsule
// is in the layout, and an estimate for CJK session titles is too wide,
// so centering it would paint left of the tab and then jump.
setTooltip(unplacedTooltip(text));
};

const watchTitle = (element: Element) => {
Expand Down Expand Up @@ -113,10 +104,6 @@ export function NativeTitleTooltipHost() {
active = element;
watchTitle(element);
place(element, text);
rafId = window.requestAnimationFrame(() => {
rafId = null;
if (active === element) place(element, text);
});
};

const onPointerOver = (event: PointerEvent) => {
Expand Down Expand Up @@ -176,19 +163,37 @@ export function NativeTitleTooltipHost() {
};
}, []);

useLayoutEffect(() => {
if (!tooltip || tooltip.placed) return;
const node = tooltipRef.current;
const anchor = anchorRef.current;
if (!node || !anchor || node.offsetWidth <= 0 || node.offsetHeight <= 0) {
return;
}
const next = positionHoverTooltip(
anchor.getBoundingClientRect(),
{ width: node.offsetWidth, height: node.offsetHeight },
{ width: window.innerWidth, height: window.innerHeight }
);
setTooltip({ text: tooltip.text, ...next, placed: true });
}, [tooltip]);

if (!tooltip) return null;

const node = (
<div
ref={tooltipRef}
role="tooltip"
data-native-title-tooltip="true"
data-placed={tooltip.placed ? 'true' : undefined}
data-side={tooltip.side}
className={NATIVE_TITLE_TOOLTIP_CLASS}
style={{
position: 'fixed',
top: tooltip.top,
left: tooltip.left,
zIndex: 10000,
visibility: tooltip.placed ? 'visible' : 'hidden',
pointerEvents: 'none',
}}
>
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/components/ui/tooltip.styles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ describe('inverted hover tooltip and icon button chrome', () => {
expect(arrow.fill?.value).toBe('hsl(var(--foreground))');
});

it('does not fade or slide the native title tooltip while it is being centered', () => {
const rules = declarationsFor(
".app-hover-tooltip[data-native-title-tooltip='true']"
);

expect(rules.animation?.value).toBe('none');
expect(rules.transition?.value).toBe('none');
});

it('restyles Astryx tooltips to the same inverted chrome', () => {
const rules = declarationsFor('.astryx-tooltip');

Expand Down
21 changes: 19 additions & 2 deletions frontend/src/styles/dockview-ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
--dv-connected-chrome: var(--surface-dialog);
--dv-tab-gap: calc(var(--radius) * 0.5);
--dv-tab-curve: var(--radius);
/* Active tabs size to their title. A short Conversation title then
collapses the label and leaves the close control as the whole hit
target. Floor = tab padding + surface padding (12px) + icon (16px)
+ gaps (12px) + 6ch of title + close (18px). */
--dv-tab-min-width: calc(2 * var(--dv-tab-gap) + 64px + 6ch);
--dv-activegroup-visiblepanel-tab-background-color: var(
--dv-connected-chrome
);
Expand Down Expand Up @@ -158,6 +163,11 @@
--dv-connected-chrome: var(--surface-dialog);
--dv-tab-gap: calc(var(--radius) * 0.5);
--dv-tab-curve: var(--radius);
/* Active tabs size to their title. A short Conversation title then
collapses the label and leaves the close control as the whole hit
target. Floor = tab padding + surface padding (12px) + icon (16px)
+ gaps (12px) + 6ch of title + close (18px). */
--dv-tab-min-width: calc(2 * var(--dv-tab-gap) + 64px + 6ch);
--dv-activegroup-visiblepanel-tab-background-color: var(
--dv-connected-chrome
);
Expand Down Expand Up @@ -314,14 +324,19 @@
padding-inline: 4px;
}

/* Dockview 5.1 omits .dv-horizontal for the default horizontal direction. */
/* Dockview 5.1 omits .dv-horizontal for the default horizontal direction.
Corner ears extend --dv-tab-curve past the tab face; only --dv-tab-gap
of that sits in the tab padding. The leftover must fit in this padding,
plus 1px, or Dockview's scrollWidth > clientWidth check treats those
pixels as overflow and paints a scrollbar when the strip is hovered. */
[class*='dockview-theme-ayu'] .dv-tabs-container:not(.dv-vertical) {
width: 100%;
max-width: 100%;
box-sizing: border-box;
align-items: stretch;
gap: 0;
padding: 4px 4px 0 2px;
--dv-tab-scroll-slack: calc(var(--dv-tab-curve) - var(--dv-tab-gap) + 1px);
padding: 4px var(--dv-tab-scroll-slack) 0 var(--dv-tab-scroll-slack);
}

[class*='dockview-theme-ayu'] .dv-tabs-container:not(.dv-vertical) > .dv-tab {
Expand Down Expand Up @@ -467,6 +482,7 @@
.dv-tabs-container:not(.dv-vertical)
> .dv-tab.dv-active-tab {
flex: 0 0 auto;
min-width: var(--dv-tab-min-width);
max-width: 200px;
}

Expand Down Expand Up @@ -584,6 +600,7 @@
.dv-tabs-container:not(.dv-vertical)
> .dv-tab.dv-active-tab
.dv-default-tab-content {
min-width: 6ch;
max-width: 15ch;
overflow: hidden;
text-overflow: ellipsis;
Expand Down
23 changes: 22 additions & 1 deletion frontend/src/styles/dockview-tabs.styles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ describe('workspace tab strip chrome', () => {
);

expect(strip['border-bottom']?.value).toBe('0');
expect(tabs.padding?.value).toBe('4px 4px 0 2px');
expect(tabs['--dv-tab-scroll-slack']?.value).toBe(
'calc(var(--dv-tab-curve) - var(--dv-tab-gap) + 1px)'
);
expect(tabs.padding?.value).toBe(
'4px var(--dv-tab-scroll-slack) 0 var(--dv-tab-scroll-slack)'
);
expect(active['border-radius']?.value).toBe(
'var(--radius) var(--radius) 0 0'
);
Expand All @@ -81,12 +86,28 @@ describe('workspace tab strip chrome', () => {
);
expect(theme['--dv-tab-curve']?.value).toBe('var(--radius)');
expect(theme['--dv-tab-gap']?.value).toBe('calc(var(--radius) * 0.5)');
expect(theme['--dv-tab-min-width']?.value).toBe(
'calc(2 * var(--dv-tab-gap) + 64px + 6ch)'
);
expect(ears.width?.value).toBe('var(--dv-tab-curve)');
expect(leftEar.background?.value).toContain('radial-gradient');
expect(leftEar.background?.value).toContain('circle at 0 0');
expect(rightEar.background?.value).toContain('circle at 100% 0');
});

it('keeps a short active tab wide enough to show its title beside the close control', () => {
const activeTab = declarationsFor(
"[class*='dockview-theme-ayu'] .dv-tabs-container:not(.dv-vertical) > .dv-tab.dv-active-tab"
);
const activeTitle = declarationsFor(
"[class*='dockview-theme-ayu'] .dv-tabs-container:not(.dv-vertical) > .dv-tab.dv-active-tab .dv-default-tab-content"
);

expect(activeTab['min-width']?.value).toBe('var(--dv-tab-min-width)');
expect(activeTab['flex']?.value).toBe('0 0 auto');
expect(activeTitle['min-width']?.value).toBe('6ch');
});

it('keeps inactive hover pills white and clear of the panel seam', () => {
const strip = declarationsFor(
"[class*='dockview-theme-ayu'] .dv-groupview > .dv-tabs-and-actions-container"
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/styles/legacy/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -3972,6 +3972,11 @@ html.dark {
white-space: pre-wrap;
}

.app-hover-tooltip[data-native-title-tooltip='true'] {
animation: none;
transition: none;
}

.app-hover-tooltip-arrow {
fill: hsl(var(--foreground));
}
Expand Down