diff --git a/frontend/src/components/ui/native-title-tooltip-host.test.tsx b/frontend/src/components/ui/native-title-tooltip-host.test.tsx index 6045a71d8..853eb2941 100644 --- a/frontend/src/components/ui/native-title-tooltip-host.test.tsx +++ b/frontend/src/components/ui/native-title-tooltip-host.test.tsx @@ -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(() => { @@ -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( +
+ + +
+ ); + + 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( +
+ + +
+ ); + + 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(
diff --git a/frontend/src/components/ui/native-title-tooltip-host.tsx b/frontend/src/components/ui/native-title-tooltip-host.tsx index cdad7d09f..43dfd5ee7 100644 --- a/frontend/src/components/ui/native-title-tooltip-host.tsx +++ b/frontend/src/components/ui/native-title-tooltip-host.tsx @@ -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 { @@ -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(null); + const anchorRef = useRef(null); const [tooltip, setTooltip] = useState(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(); @@ -47,10 +52,6 @@ export function NativeTitleTooltipHost() { window.clearTimeout(showTimer); showTimer = null; } - if (rafId != null) { - window.cancelAnimationFrame(rafId); - rafId = null; - } }; const suppress = (element: Element) => { @@ -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( - `.${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) => { @@ -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) => { @@ -176,12 +163,29 @@ 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 = (
diff --git a/frontend/src/components/ui/tooltip.styles.test.ts b/frontend/src/components/ui/tooltip.styles.test.ts index 28b53567d..2b3cb555c 100644 --- a/frontend/src/components/ui/tooltip.styles.test.ts +++ b/frontend/src/components/ui/tooltip.styles.test.ts @@ -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'); diff --git a/frontend/src/styles/dockview-ayu.css b/frontend/src/styles/dockview-ayu.css index f48490ba0..8d746f21b 100644 --- a/frontend/src/styles/dockview-ayu.css +++ b/frontend/src/styles/dockview-ayu.css @@ -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 ); @@ -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 ); @@ -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 { @@ -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; } @@ -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; diff --git a/frontend/src/styles/dockview-tabs.styles.test.ts b/frontend/src/styles/dockview-tabs.styles.test.ts index 0d5a427e9..d4533486a 100644 --- a/frontend/src/styles/dockview-tabs.styles.test.ts +++ b/frontend/src/styles/dockview-tabs.styles.test.ts @@ -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' ); @@ -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" diff --git a/frontend/src/styles/legacy/index.css b/frontend/src/styles/legacy/index.css index b8fa22a3f..a0ce47b9d 100644 --- a/frontend/src/styles/legacy/index.css +++ b/frontend/src/styles/legacy/index.css @@ -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)); }