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): remove stacked pane window spacer

davidf7425bd884d2
diff --git a/apps/desktop/src/renderer/cindy-brain/ghostPanels.tsx b/apps/desktop/src/renderer/cindy-brain/ghostPanels.tsx
index 24c75dbed6..c89e975f2e 100644
--- a/apps/desktop/src/renderer/cindy-brain/ghostPanels.tsx
+++ b/apps/desktop/src/renderer/cindy-brain/ghostPanels.tsx
@@ -6,7 +6,7 @@ import { ghostPanelKind, type GhostManifest, type InstalledGhost } from '../../s
import { minimizeGhostPanel, reconcileGhostPanelBubbles } from '../lib/ghostPanelBubbleState';
import { toast } from '../lib/toast';
import { usePanelMaximize } from '../layout/panelMaximize';
-import { usePaneFill } from '../layout/panePlacement';
+import { usePaneAtWindowTop, usePaneFill } from '../layout/panePlacement';
import { usePanelWidth } from '../layout/paneWidths';
import { PanelChrome } from '../panels/PanelChrome';
import {
@@ -57,6 +57,7 @@ const PANEL_EXIT_MS = 180;
function GhostPanel({ manifest }: PanelComponentProps & { manifest: GhostManifest }): ReactNode {
const kind = ghostPanelKind(manifest.id);
const fillContainer = usePaneFill();
+ const atWindowTop = usePaneAtWindowTop();
// 宽度由引擎下发(fraction × 可用宽,缝把手可拖);兜底用清单 minWidth。
const width = usePanelWidth(kind) ?? manifest.panel?.minWidth ?? 300;
// 撑满态(引擎视图态):固定宽让位给 flex-1,树上的 fraction 账本不动。
@@ -138,6 +139,7 @@ function GhostPanel({ manifest }: PanelComponentProps & { manifest: GhostManifes
>
<PanelChrome
title={manifest.panel?.title ?? manifest.name}
+ showWindowSpacer={atWindowTop}
panelKind={maximizeEnabled ? kind : undefined}
onMinimize={minimizeEnabled ? beginMinimize : undefined}
onDetach={
diff --git a/apps/desktop/src/renderer/layout/LayoutRoot.tsx b/apps/desktop/src/renderer/layout/LayoutRoot.tsx
index d9eae2ca37..5f477a16cc 100644
--- a/apps/desktop/src/renderer/layout/LayoutRoot.tsx
+++ b/apps/desktop/src/renderer/layout/LayoutRoot.tsx
@@ -15,7 +15,7 @@ import { registerBuiltinPanels } from '../panels/builtinPanels';
import { getPanelKind } from '../panels/registry';
import { installLayoutDevTools } from './layoutDevTools';
import { PanelMaximizeContext, type PanelMaximizeState } from './panelMaximize';
-import { PaneFillProvider } from './panePlacement';
+import { PaneAtWindowTopProvider, PaneFillProvider } from './panePlacement';
import { PaneWidthProvider, useContentAvailableWidth } from './paneWidths';
/**
@@ -72,14 +72,24 @@ function isPanelKindVisible(kind: string): boolean {
}
/** 单个 pane 的挂载点:查注册表渲染;不可见 kind = 隐藏(数据保留在树里)。 */
-function PanelHost({ node, fill = false }: { node: PaneNode; fill?: boolean }): ReactNode {
+function PanelHost({
+ node,
+ fill = false,
+ atWindowTop = true,
+}: {
+ node: PaneNode;
+ fill?: boolean;
+ atWindowTop?: boolean;
+}): ReactNode {
const def = getPanelKind(node.panelKind);
if (!def || !isPanelKindVisible(node.panelKind)) return null;
const Component = def.Component;
return (
- <PaneFillProvider value={fill}>
- <Component paneId={node.id} />
- </PaneFillProvider>
+ <PaneAtWindowTopProvider value={atWindowTop}>
+ <PaneFillProvider value={fill}>
+ <Component paneId={node.id} />
+ </PaneFillProvider>
+ </PaneAtWindowTopProvider>
);
}
@@ -257,6 +267,7 @@ function containsPanelKind(node: LayoutNode, kind: string): boolean {
interface NodeViewProps {
node: LayoutNode;
fillPane?: boolean;
+ atWindowTop?: boolean;
liveFractions: Record<string, number> | null;
maximizedKind: string | null;
onLive: (live: Record<string, number> | null) => void;
@@ -267,13 +278,16 @@ interface NodeViewProps {
function NodeView({
node,
fillPane = false,
+ atWindowTop = true,
liveFractions,
maximizedKind,
onLive,
onCommitted,
}: NodeViewProps): ReactNode {
const splitRef = useRef<HTMLDivElement>(null);
- if (node.type === 'pane') return <PanelHost node={node} fill={fillPane} />;
+ if (node.type === 'pane') {
+ return <PanelHost node={node} fill={fillPane} atWindowTop={atWindowTop} />;
+ }
const ledger = activeSplitLedger(node.children);
const visible = ledger.entries;
const items: ReactNode[] = [];
@@ -305,6 +319,10 @@ function NodeView({
}
const share = liveFractions?.[entry.node.id] ?? entry.share;
const hiddenByMaximize = maximizedKind !== null && !entryHasMaximized;
+ const childAtWindowTop =
+ atWindowTop &&
+ (node.direction === 'row' ||
+ (maximizedKind !== null ? entryHasMaximized : i === 0));
items.push(
<div
key={entry.node.id}
@@ -325,6 +343,7 @@ function NodeView({
<NodeView
node={entry.node}
fillPane
+ atWindowTop={childAtWindowTop}
liveFractions={liveFractions}
maximizedKind={maximizedKind}
onLive={onLive}
diff --git a/apps/desktop/src/renderer/layout/__tests__/LayoutRoot.test.tsx b/apps/desktop/src/renderer/layout/__tests__/LayoutRoot.test.tsx
index 5cfecf7e0f..bb8ccec020 100644
--- a/apps/desktop/src/renderer/layout/__tests__/LayoutRoot.test.tsx
+++ b/apps/desktop/src/renderer/layout/__tests__/LayoutRoot.test.tsx
@@ -11,7 +11,7 @@ import {
import { __resetBuiltinPanelsForTest } from '../../panels/builtinPanels';
import { __resetPanelRegistryForTest, registerPanelKind } from '../../panels/registry';
import { LayoutRoot, normalizeSubMinFractions } from '../LayoutRoot';
-import { usePaneFill } from '../panePlacement';
+import { usePaneAtWindowTop, usePaneFill } from '../panePlacement';
const ghostPanelSyncMock = vi.hoisted(() => ({ version: 0 }));
@@ -139,7 +139,11 @@ describe('LayoutRoot · 树驱动的顺序与在场', () => {
it('根级 column split 渲染为插件 grid,两个 pane 填满各自格并带横向分割线', () => {
const GridPane = ({ name }: { name: string }) => (
- <div data-testid={`grid-${name}`} data-fill={String(usePaneFill())} />
+ <div
+ data-testid={`grid-${name}`}
+ data-fill={String(usePaneFill())}
+ data-window-top={String(usePaneAtWindowTop())}
+ />
);
registerPanelKind({
kind: 'ghost:alpha',
@@ -183,6 +187,8 @@ describe('LayoutRoot · 树驱动的顺序与在场', () => {
expect(screen.getByTestId('grid-alpha').getAttribute('data-fill')).toBe('true');
expect(screen.getByTestId('grid-beta').getAttribute('data-fill')).toBe('true');
+ expect(screen.getByTestId('grid-alpha').getAttribute('data-window-top')).toBe('true');
+ expect(screen.getByTestId('grid-beta').getAttribute('data-window-top')).toBe('false');
expect(document.querySelector('[data-layout-root-child-id="grid-alpha"]')).not.toBeNull();
expect(screen.getAllByTestId('layout-divider')).toHaveLength(3);
});
diff --git a/apps/desktop/src/renderer/layout/panePlacement.tsx b/apps/desktop/src/renderer/layout/panePlacement.tsx
index 1eb0640ee0..e8de18db36 100644
--- a/apps/desktop/src/renderer/layout/panePlacement.tsx
+++ b/apps/desktop/src/renderer/layout/panePlacement.tsx
@@ -7,9 +7,16 @@ import { createContext, useContext } from 'react';
* 不能继续拿 manifest 的固定宽度,否则会在列内留下空白或溢出。
*/
const PaneFillContext = createContext(false);
+const PaneAtWindowTopContext = createContext(true);
export const PaneFillProvider = PaneFillContext.Provider;
+export const PaneAtWindowTopProvider = PaneAtWindowTopContext.Provider;
export function usePaneFill(): boolean {
return useContext(PaneFillContext);
}
+
+/** 当前 pane 的可见内容是否贴着主窗口顶边,用于决定是否保留窗口 chrome 拖拽带。 */
+export function usePaneAtWindowTop(): boolean {
+ return useContext(PaneAtWindowTopContext);
+}
diff --git a/apps/desktop/src/renderer/panels/PanelChrome.tsx b/apps/desktop/src/renderer/panels/PanelChrome.tsx
index 98488e5a8a..5ad6c1f92a 100644
--- a/apps/desktop/src/renderer/panels/PanelChrome.tsx
+++ b/apps/desktop/src/renderer/panels/PanelChrome.tsx
@@ -49,6 +49,11 @@ export interface PanelChromeProps {
onMinimize?: () => void;
/** 传入即长出「关闭」系统按钮(恒排最右);二次确认等语义归调用方。 */
onClose?: () => void;
+ /**
+ * 是否渲染贴主窗口顶边的 46px 窗口拖拽带。纵向 Grid 的非首行传 false,
+ * 避免在窗口中部浪费高度并产生误触拖窗区域;默认 true 保持根级面板行为。
+ */
+ showWindowSpacer?: boolean;
}
export function PanelChrome({
@@ -58,6 +63,7 @@ export function PanelChrome({
onDetach,
onMinimize,
onClose,
+ showWindowSpacer = true,
}: PanelChromeProps): ReactNode {
const { t } = useTranslation();
const maximize = usePanelMaximize();
@@ -75,30 +81,33 @@ export function PanelChrome({
{/* 窗口 chrome 让位带(§6 规则 3:顶部 46px 是系统领地,任何面板不得占用)。
做进标准头 = 约束由引擎兜底,面板作者不靠自觉;整条归窗口拖动
(B3 口径:46px 带拖窗、36px 头拖面板),与聊天顶栏/工具面板顶带连成一线。 */}
- <div
- 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 事件)。 */}
+ {showWindowSpacer && (
<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>
+ aria-hidden
+ data-testid="panel-chrome-window-spacer"
+ 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 f8a0f4dedb..73265d6664 100644
--- a/apps/desktop/src/renderer/panels/__tests__/PanelChrome.test.tsx
+++ b/apps/desktop/src/renderer/panels/__tests__/PanelChrome.test.tsx
@@ -87,6 +87,13 @@ describe('PanelChrome · 撑满系统按钮', () => {
expect(hole.style.width).toBe(`${CHROME_ACTIONS_GEOMETRY.clusterWidth}px`);
});
+ it('纵向 Grid 非首行可关闭窗口拖拽带,只保留面板标题栏', () => {
+ render(<PanelChrome title="测试面板" showWindowSpacer={false} />);
+ expect(screen.queryByTestId('panel-chrome-window-spacer')).toBeNull();
+ expect(screen.queryByTestId('panel-chrome-actions-hit-hole')).toBeNull();
+ expect(document.querySelector('[data-panel-drag-handle]')).not.toBeNull();
+ });
+
it('传 onMinimize → 长出气泡最小化按钮并触发回调;三按钮 DOM 顺序 minimize→detach→maximize', () => {
const onMinimize = vi.fn();
render(