Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): place menu highlight in layout px during scaled entry
kirozeng32f5f40b4d49
diff --git a/apps/desktop/src/renderer/components/ui/__tests__/dropdownMenuHighlight.test.tsx b/apps/desktop/src/renderer/components/ui/__tests__/dropdownMenuHighlight.test.tsxindex 0ed09de6b6..86146877ed 100644--- a/apps/desktop/src/renderer/components/ui/__tests__/dropdownMenuHighlight.test.tsx+++ b/apps/desktop/src/renderer/components/ui/__tests__/dropdownMenuHighlight.test.tsx@@ -14,7 +14,7 @@ import {DropdownMenuSubTrigger,DropdownMenuTrigger,} from '../dropdown-menu';-import { lockMenuWidth } from '../dropdown-menu-highlight';+import { attachMenuHighlight, lockMenuWidth } from '../dropdown-menu-highlight';import * as menuStyles from '@/features/cc-agent/sidebar/menuStyles';import { MENU_ITEM_CLASS, MENU_ROW_CLASS } from '@/features/cc-agent/sidebar/menuStyles';import { SessionProjectMoveSubmenu } from '@/features/cc-agent/sidebar/SessionProjectMoveSubmenu';@@ -545,6 +545,35 @@ describe('shared dropdown menu glide highlight', () => {expect(Object.keys(menuStyles).sort()).toEqual(['MENU_ITEM_CLASS', 'MENU_ROW_CLASS']);});+ it('places the layer in layout px while the open animation scales the panel', () => {+ // Panel laid out at 200×100, drawn at half size from (100, 50) mid-animation.+ const panel = document.createElement('div');+ panel.setAttribute('data-menu-panel', '');+ const layer = document.createElement('span');+ const row = document.createElement('div');+ row.setAttribute('data-menu-row', '');+ row.setAttribute('data-highlighted', '');+ panel.append(layer, row);+ document.body.append(panel);+ const size = (el: HTMLElement, w: number, h: number) => {+ Object.defineProperty(el, 'offsetWidth', { configurable: true, value: w });+ Object.defineProperty(el, 'offsetHeight', { configurable: true, value: h });+ };+ size(panel, 200, 100);+ size(row, 188, 32);+ vi.spyOn(panel, 'getBoundingClientRect').mockReturnValue(new DOMRect(100, 50, 100, 50));+ // Row at layout (6, 40) → drawn at (103, 70), 94×16.+ vi.spyOn(row, 'getBoundingClientRect').mockReturnValue(new DOMRect(103, 70, 94, 16));+ const detach = attachMenuHighlight(panel, layer, {+ current: (rows) => rows.find((r) => r.hasAttribute('data-highlighted')),+ });+ expect(layer.style.width).toBe('188px');+ expect(layer.style.height).toBe('32px');+ expect(layer.style.transform).toBe('translate(6px, 40px)');+ detach();+ panel.remove();+ });+it('coalesces pointer moves into one update per frame and caches row geometry lookups', () => {const frames: FrameRequestCallback[] = [];vi.stubGlobal('requestAnimationFrame', (cb: FrameRequestCallback) => frames.push(cb));diff --git a/apps/desktop/src/renderer/components/ui/dropdown-menu-highlight.ts b/apps/desktop/src/renderer/components/ui/dropdown-menu-highlight.tsindex 387b290343..b0aedd989f 100644--- a/apps/desktop/src/renderer/components/ui/dropdown-menu-highlight.ts+++ b/apps/desktop/src/renderer/components/ui/dropdown-menu-highlight.ts@@ -132,13 +132,17 @@ export function attachMenuHighlight(};};+ // Client rects include the open animation's scale (on the panel or an ancestor), and the+ // layer inside the panel is scaled again, so measurements are converted back to layout px.const place = (el: HTMLElement) => {const p = panel.getBoundingClientRect();const r = visibleBox(el);- layer.style.width = `${r.width}px`;- layer.style.height = `${r.height}px`;- layer.style.transform = `translate(${r.left - p.left - panel.clientLeft + panel.scrollLeft}px, ${- r.top - p.top - panel.clientTop + panel.scrollTop+ const sx = panel.offsetWidth > 0 && p.width > 0 ? p.width / panel.offsetWidth : 1;+ const sy = panel.offsetHeight > 0 && p.height > 0 ? p.height / panel.offsetHeight : 1;+ layer.style.width = `${r.width / sx}px`;+ layer.style.height = `${r.height / sy}px`;+ layer.style.transform = `translate(${(r.left - p.left) / sx - panel.clientLeft + panel.scrollLeft}px, ${+ (r.top - p.top) / sy - panel.clientTop + panel.scrollTop}px)`;};