Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 插件面板顶带为左上角 ChromeActions 按钮簇挖 no-drag 洞

Lizi03fce4a56a55
diff --git a/apps/desktop/src/renderer/panels/PanelChrome.tsx b/apps/desktop/src/renderer/panels/PanelChrome.tsx
index d277f77b7e..ffcc4b903f 100644
--- a/apps/desktop/src/renderer/panels/PanelChrome.tsx
+++ b/apps/desktop/src/renderer/panels/PanelChrome.tsx
@@ -2,6 +2,9 @@ import type { CSSProperties, ReactNode } from 'react';
import { Maximize2, Minimize2, PictureInPicture2 } from 'lucide-react';
import { useTranslation } from 'react-i18next';
+import { CHROME_ACTIONS_GEOMETRY } from '@/components/layout/chromeActionsGeometry';
+import { useMacFullscreen } from '@/hooks/useMacFullscreen';
+
import { usePanelMaximize } from '../layout/panelMaximize';
/**
@@ -44,6 +47,13 @@ export function PanelChrome({ title, actions, panelKind, onDetach }: PanelChrome
const maximize = usePanelMaximize();
const showMaximize = panelKind !== undefined && maximize !== null;
const isMaximized = showMaximize && maximize.maximizedKind === panelKind;
+ // ChromeActions 按钮簇的窗口坐标(与 ChromeActions.tsx 的 x 同式):
+ // 面板顶带的 no-drag 洞必须钉在这里,见下方洞元素注释。
+ const { isMac, isFullscreen } = useMacFullscreen();
+ const chromeClusterX =
+ isMac && !isFullscreen
+ ? CHROME_ACTIONS_GEOMETRY.macTrafficLightLeft
+ : CHROME_ACTIONS_GEOMETRY.defaultLeft;
return (
<>
{/* 窗口 chrome 让位带(§6 规则 3:顶部 46px 是系统领地,任何面板不得占用)。
@@ -53,7 +63,26 @@ export function PanelChrome({ title, actions, panelKind, onDetach }: PanelChrome
aria-hidden
className="h-[46px] shrink-0 border-b border-[var(--border-default)] bg-[var(--panel-bg)]"
style={{ WebkitAppRegion: 'drag' } as CSSProperties}
- />
+ >
+ {/* ChromeActions 浮层按钮簇的 no-drag 洞:左栏折叠时本面板可能顶到窗口
+ 最左,顶带会盖住左上角折叠/菜单按钮 —— Electron 拖拽区是纯几何
+ (drag 矩形减 no-drag 矩形)且挖洞只在 drag 元素后代上可靠生效,
+ 浮层自身的 no-drag 不算数(同 Sidebar 顶行 / ContentHeader spacer)。
+ fixed 定位取窗口坐标:面板不在左上角时矩形与顶带不相交 = 几何
+ no-op,无需感知自己的列位;pointer-events:none 不挡命中(拖拽区
+ 注册是几何计算,不依赖 DOM 事件)。 */}
+ <div
+ data-testid="panel-chrome-actions-hit-hole"
+ className="pointer-events-none fixed top-0 h-[46px]"
+ style={
+ {
+ left: chromeClusterX,
+ width: CHROME_ACTIONS_GEOMETRY.clusterWidth,
+ WebkitAppRegion: 'no-drag',
+ } as CSSProperties
+ }
+ />
+ </div>
<div
data-panel-drag-handle=""
className="flex h-[36px] shrink-0 items-center justify-between gap-2 border-b border-[var(--border-default)] bg-[var(--panel-bg)] px-3"
diff --git a/apps/desktop/src/renderer/panels/__tests__/PanelChrome.test.tsx b/apps/desktop/src/renderer/panels/__tests__/PanelChrome.test.tsx
index d2c302a493..98b7a3b900 100644
--- a/apps/desktop/src/renderer/panels/__tests__/PanelChrome.test.tsx
+++ b/apps/desktop/src/renderer/panels/__tests__/PanelChrome.test.tsx
@@ -3,6 +3,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
import { useState } from 'react';
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
+import { CHROME_ACTIONS_GEOMETRY } from '../../components/layout/chromeActionsGeometry';
import { PanelMaximizeContext, type PanelMaximizeState } from '../../layout/panelMaximize';
import { PanelChrome } from '../PanelChrome';
@@ -68,4 +69,21 @@ describe('PanelChrome · 撑满系统按钮', () => {
expect(screen.getAllByRole('button')).toHaveLength(1);
expect(screen.getByRole('button', { name: 'panelChrome.detachAria' })).toBeTruthy();
});
+
+ it('46px 顶带为 ChromeActions 按钮簇挖 no-drag 洞(左栏折叠 + 面板顶到窗口最左时按钮可点)', () => {
+ render(<PanelChrome title="测试面板" />);
+ const hole = screen.getByTestId('panel-chrome-actions-hit-hole');
+ const strip = hole.parentElement as HTMLElement;
+ // 洞必须是 drag 顶带的后代(Electron 挖洞只在 drag 元素后代上可靠生效)。
+ expect(
+ (strip.style as CSSStyleDeclaration & { WebkitAppRegion: string }).WebkitAppRegion,
+ ).toBe('drag');
+ expect(
+ (hole.style as CSSStyleDeclaration & { WebkitAppRegion: string }).WebkitAppRegion,
+ ).toBe('no-drag');
+ // fixed 定位钉窗口坐标(jsdom 无 electronAPI → 非 mac → defaultLeft)。
+ expect(hole.className).toContain('fixed');
+ expect(hole.style.left).toBe(`${CHROME_ACTIONS_GEOMETRY.defaultLeft}px`);
+ expect(hole.style.width).toBe(`${CHROME_ACTIONS_GEOMETRY.clusterWidth}px`);
+ });
});