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(ui): 模型菜单选中底色悬停时让位,补齐跟随会话行与宽度测量

kirozeng66c6af836fef
diff --git a/apps/desktop/src/renderer/__tests__/unifiedModelPanelRendering.test.tsx b/apps/desktop/src/renderer/__tests__/unifiedModelPanelRendering.test.tsx
index 64a76d8c92..90a27f9cbe 100644
--- a/apps/desktop/src/renderer/__tests__/unifiedModelPanelRendering.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/unifiedModelPanelRendering.test.tsx
@@ -566,6 +566,9 @@ describe('统一模型选择器面板', () => {
renderPanel({ followSession: { active: true, label: '跟随会话', onFollow } });
const row = screen.getByText('跟随会话').closest('button') as HTMLElement;
expect(row.getAttribute('aria-selected')).toBe('true');
+ // 模型菜单例外:选中行保留整行底色与勾。
+ expect(row.className).toContain('bg-sidebar-item-hover');
+ expect(row.querySelector('svg.lucide-check')).not.toBeNull();
await act(async () => {
fireEvent.click(row);
});
@@ -614,6 +617,8 @@ describe('统一面板 · 会话内形态', () => {
const selected = list.querySelector<HTMLElement>('[data-model-selected="true"]');
expect(selected).not.toBeNull();
expect(selected!.className).toContain('bg-sidebar-item-hover');
+ // 滑动高亮已盖住悬停行,静态底色在那一刻让位,两层半透明不叠深。
+ expect(selected!.className).toContain('data-[menu-active]:bg-transparent');
expect(selected!.querySelector('svg.lucide-check')).toBeNull();
expect(selected!.querySelector('span[title].font-medium')).not.toBeNull();
const other = Array.from(list.querySelectorAll<HTMLElement>('[data-unified-anchor]')).find(
@@ -836,6 +841,11 @@ describe('统一面板 · 会话内形态', () => {
// 量的是**全量视图**:同引擎视图里看不到的 Opus 5 也在 sizer 里。
expect(sizer?.textContent).toContain('Opus 5');
expect(sizer?.textContent).toContain('GPT-5.5');
+ // 组头与真实组头同字号同字重,量出的宽度才可信。
+ const realLabel = container.querySelector('[role="listbox"] [role="group"] > div');
+ const sizerLabel = sizer?.querySelector(':scope > div > div');
+ expect(sizerLabel?.className).toContain('text-12 font-medium leading-[1.33]');
+ expect(realLabel?.className).toContain('text-12 font-medium leading-[1.33]');
// 不可见、零高度、不进 listbox、不带选中标记(自动对齐永远不会挑中它)。
expect(sizer?.getAttribute('aria-hidden')).toBe('true');
expect(sizer?.className).toContain('invisible');
diff --git a/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx b/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx
index 80b306a220..b4093b4fe6 100644
--- a/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx
@@ -2300,7 +2300,7 @@ function ModelSelectorContentView({
{editHasEfforts && (
<>
<div className="px-2 pb-0.5 pt-1">
- <span className="text-11 font-medium text-[var(--text-tertiary)]">
+ <span className="text-12 font-medium leading-[1.33] text-[var(--cmd-palette-item-meta)]">
{t('newChat.modelSelector.effortLabel')}
</span>
</div>
@@ -2321,7 +2321,7 @@ function ModelSelectorContentView({
className={cn(
COMPOSER_MENU_ROW,
'flex w-full items-center justify-between px-3 py-2 text-left',
- selected && 'bg-sidebar-item-hover',
+ selected && 'bg-sidebar-item-hover data-[menu-active]:bg-transparent',
!available && 'cursor-not-allowed opacity-45',
)}
>
@@ -2597,7 +2597,7 @@ function ModelSelectorContentView({
COMPOSER_MENU_ROW,
'group/row flex w-full cursor-pointer items-center justify-between px-3 py-2',
// Model menu exception (DESIGN §4): the chosen row keeps its whole-row fill.
- isSelected && 'bg-sidebar-item-hover',
+ isSelected && 'bg-sidebar-item-hover data-[menu-active]:bg-transparent',
constrainedListMaxHeight !== undefined && 'min-h-9',
(disabled || paymentRequired) && 'opacity-50',
)}
diff --git a/apps/desktop/src/renderer/components/new-chat/UnifiedModelPanel.tsx b/apps/desktop/src/renderer/components/new-chat/UnifiedModelPanel.tsx
index df9385df59..f793729931 100644
--- a/apps/desktop/src/renderer/components/new-chat/UnifiedModelPanel.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/UnifiedModelPanel.tsx
@@ -1035,6 +1035,8 @@ export function UnifiedModelPanel({
className={cn(
COMPOSER_MENU_ROW,
'flex w-full items-center justify-between px-3 py-2',
+ // Model menu exception (DESIGN §4): the chosen row keeps its fill and check.
+ followSession.active && 'bg-sidebar-item-hover data-[menu-active]:bg-transparent',
interactionDisabled && 'cursor-not-allowed opacity-50',
)}
>
@@ -1167,7 +1169,7 @@ export function UnifiedModelPanel({
{widthSizerSections.map((section) => (
<div key={section.key}>
{/* 组头也要量:供应商名可能比它组里最长的行还宽。 */}
- <div className="flex items-center gap-1.5 px-2.5 pb-1 pt-2 text-11">
+ <div className="flex items-center gap-1.5 px-2.5 pb-1 pt-2 text-12 font-medium leading-[1.33]">
<span className="truncate">{sectionLabel(section)}</span>
</div>
{section.rows.map((row) => {
diff --git a/apps/desktop/src/renderer/components/new-chat/UnifiedModelRow.tsx b/apps/desktop/src/renderer/components/new-chat/UnifiedModelRow.tsx
index c258aa7aa6..38e6de4b3b 100644
--- a/apps/desktop/src/renderer/components/new-chat/UnifiedModelRow.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/UnifiedModelRow.tsx
@@ -226,7 +226,8 @@ export function UnifiedModelRow({
// The model panel is the one exception on the chosen row: whole-row fill, no check.
COMPOSER_MENU_ROW,
'[&+[data-unified-anchor]]:mt-1 group/row flex w-full cursor-pointer flex-col px-3 py-2',
- selected && 'bg-sidebar-item-hover',
+ // The glide layer covers the hovered row, so the static fill steps aside there.
+ selected && 'bg-sidebar-item-hover data-[menu-active]:bg-transparent',
(interactionDisabled || paymentRequired) && 'cursor-not-allowed opacity-50',
)}
>
diff --git a/apps/desktop/src/renderer/components/ui/__tests__/dropdownMenuHighlight.test.tsx b/apps/desktop/src/renderer/components/ui/__tests__/dropdownMenuHighlight.test.tsx
index 051a8f25cf..5461865189 100644
--- a/apps/desktop/src/renderer/components/ui/__tests__/dropdownMenuHighlight.test.tsx
+++ b/apps/desktop/src/renderer/components/ui/__tests__/dropdownMenuHighlight.test.tsx
@@ -380,9 +380,10 @@ describe('shared dropdown menu glide highlight', () => {
expect(icon('Default icon').hasAttribute('data-menu-icon-stroke')).toBe(false);
expect(icon('Default icon').getAttribute('stroke-width')).toBe('2');
expect(icon('Explicit icon').hasAttribute('data-menu-icon-stroke')).toBe(true);
- // The stroke rule lives in globals.css, scoped to shared rows and default-width icons.
+ // The stroke rule lives in globals.css, scoped to shared rows and default-width icons;
+ // non-option blocks (menuSkipAttrs, data-menu-row="skip") keep their stroke.
expect(globals).toMatch(
- /\[data-menu-row\] svg\.lucide\[stroke-width='2'\]:not\(\[data-menu-icon-stroke\]\) \{\s*stroke-width: 1\.5;\s*transition: stroke-width var\(--motion-instant\) var\(--motion-ease-out\);/,
+ /\[data-menu-row\]:not\(\[data-menu-row='skip'\]\) svg\.lucide\[stroke-width='2'\]:not\(\[data-menu-icon-stroke\]\) \{\s*stroke-width: 1\.5;\s*transition: stroke-width var\(--motion-instant\) var\(--motion-ease-out\);/,
);
expect(globals).toMatch(
/\[data-menu-row\]:is\(\s*\[data-menu-active\],\s*\[data-highlighted\],\s*\[data-state='checked'\],\s*\[data-state='open'\]\s*\)\s*svg\.lucide\[stroke-width='2'\]:not\(\[data-menu-icon-stroke\]\) \{\s*stroke-width: 2;/,
diff --git a/apps/desktop/src/renderer/components/ui/__tests__/sharedMenuCallers.test.tsx b/apps/desktop/src/renderer/components/ui/__tests__/sharedMenuCallers.test.tsx
index a93800e565..570aa334c3 100644
--- a/apps/desktop/src/renderer/components/ui/__tests__/sharedMenuCallers.test.tsx
+++ b/apps/desktop/src/renderer/components/ui/__tests__/sharedMenuCallers.test.tsx
@@ -88,7 +88,7 @@ describe('update notice · version jump', () => {
});
describe('right sidebar · add tab', () => {
- function renderStrip(onAdd = vi.fn()) {
+ function renderStrip(onAdd = vi.fn(), container?: HTMLElement) {
render(
<TabStrip
tabs={[{ id: 't1', kind: 'file-browser', title: '', state: {} } as never]}
@@ -98,6 +98,7 @@ describe('right sidebar · add tab', () => {
onReorder={vi.fn()}
onAdd={onAdd}
/>,
+ container ? { container: container.appendChild(document.createElement('div')) } : undefined,
);
const add = screen.getByRole('button', { name: 'rightSidebar.tabs.addAria' });
// jsdom has no layout; the menu closes itself when its anchor has no size.
@@ -122,12 +123,32 @@ describe('right sidebar · add tab', () => {
expect(document.activeElement).toBe(add);
});
- it('closes on Escape without adding a tab', async () => {
+ it('closes on Escape without adding a tab and returns focus to "+"', async () => {
const { add, onAdd } = renderStrip();
await openByKeyboard(add);
await key('Escape');
expect(screen.queryByRole('menu')).toBeNull();
expect(onAdd).not.toHaveBeenCalled();
+ expect(document.activeElement).toBe(add);
+ });
+
+ it('closes when the host pane collapses and leaves focus off the hidden "+"', async () => {
+ vi.stubGlobal('requestAnimationFrame', (cb: FrameRequestCallback) => setTimeout(() => cb(0), 0));
+ vi.stubGlobal('cancelAnimationFrame', (id: number) => clearTimeout(id));
+ const pane = document.createElement('div');
+ pane.setAttribute('data-panel-drag-root', 'right-tabs');
+ document.body.append(pane);
+ const { add, onAdd } = renderStrip(vi.fn(), pane);
+ await openByKeyboard(add);
+ expect(screen.getByRole('menu')).toBeTruthy();
+ await act(async () => {
+ pane.setAttribute('data-pane-collapsed', '');
+ await new Promise((resolve) => setTimeout(resolve, 10));
+ });
+ expect(screen.queryByRole('menu')).toBeNull();
+ expect(onAdd).not.toHaveBeenCalled();
+ expect(document.activeElement).not.toBe(add);
+ pane.remove();
});
});
diff --git a/apps/desktop/src/renderer/components/ui/menu-row.tsx b/apps/desktop/src/renderer/components/ui/menu-row.tsx
index 1112a08a20..9b3f434a32 100644
--- a/apps/desktop/src/renderer/components/ui/menu-row.tsx
+++ b/apps/desktop/src/renderer/components/ui/menu-row.tsx
@@ -62,9 +62,10 @@ export function menuRowAttrs({
/**
* Non-option blocks inside a glide panel (a toggle, a header card): the pointer over them
- * takes the highlight away instead of lighting the nearest option row.
+ * takes the highlight away instead of lighting the nearest option row. `data-menu-row="skip"`
+ * keeps their icons out of the row icon-stroke rule (globals.css).
*/
-export const menuSkipAttrs = { [MENU_ROW_ATTR]: '', [MENU_OWN_HIGHLIGHT_ATTR]: '' } as const;
+export const menuSkipAttrs = { [MENU_ROW_ATTR]: 'skip', [MENU_OWN_HIGHLIGHT_ATTR]: '' } as const;
// Row text is wrapped so its width is reserved at 500: an invisible, zero-height
// ::after copy (generated content, so textContent, typeahead and the accessible name
diff --git a/apps/desktop/src/renderer/styles/globals.css b/apps/desktop/src/renderer/styles/globals.css
index 0217a5e0cd..f3eceb76fa 100644
--- a/apps/desktop/src/renderer/styles/globals.css
+++ b/apps/desktop/src/renderer/styles/globals.css
@@ -2167,8 +2167,9 @@ mark.doc-search-mark [class] {
/* 共享下拉菜单行(components/ui/dropdown-menu.tsx,DESIGN §4):行内 Lucide 图标平时线宽 1.5,
高亮 / 勾选 / 展开时回到 2。只动默认线宽(stroke-width="2")的图标:显式传了其他 strokeWidth 的
- 不命中;显式传 2 的由组件标上 data-menu-icon-stroke(行内直接子元素与普通标签内可识别)。 */
-[data-menu-row] svg.lucide[stroke-width='2']:not([data-menu-icon-stroke]) {
+ 不命中;显式传 2 的由组件标上 data-menu-icon-stroke(行内直接子元素与普通标签内可识别)。
+ data-menu-row="skip" 是面板里的非选项块(开关、价格卡,menu-row.tsx menuSkipAttrs),不变细。 */
+[data-menu-row]:not([data-menu-row='skip']) svg.lucide[stroke-width='2']:not([data-menu-icon-stroke]) {
stroke-width: 1.5;
transition: stroke-width var(--motion-instant) var(--motion-ease-out);
}
diff --git a/docs/design-rules/DESIGN.md b/docs/design-rules/DESIGN.md
index 168faa8e06..2875b9d1bc 100644
--- a/docs/design-rules/DESIGN.md
+++ b/docs/design-rules/DESIGN.md
@@ -450,7 +450,7 @@ Ordinary confirmations opt into standard buttons with `presentation="standard"`
- **Menu hover highlight** (`components/ui/dropdown-menu-highlight.ts`): one `--sidebar-item-hover` surface (8px) per `DropdownMenuContent` / `DropdownMenuSubContent` glides between rows with `transform`; the row nearest the pointer anywhere in the panel wins, and separators do not interrupt the glide. Entering fades in from the checked row (or the target), leaving fades out; keyboard follows Radix's highlighted item, and an open SubTrigger stays highlighted while its submenu is in use. Motion: `transform` / `opacity` on `--motion-instant` / `--motion-ease-out` (fade-out `--motion-ease-in`), size snaps, no slide under reduced motion. Danger rows use the same grey layer. Rows whose caller sets its own `focus:` / `hover:` / `data-[highlighted]:` / `data-[state=open]:` background keep it and get no layer; `hoverHighlight={false}` restores per-row fills. Sidebar menus (`features/cc-agent/sidebar/menuStyles.ts`: `MENU_ITEM_CLASS` / `MENU_ROW_CLASS` = `h-8 gap-2`, triggers `cursor-pointer`) use the same highlight.
- **Panel width must bind to the trigger width** — never narrower or wider than the control that opened it. Radix Select: `position="popper"` + `width: var(--radix-select-trigger-width)`; other primitives measure the trigger. (A repeatedly-tripped rule: dropdown width must match the control above.)
- **Select listbox option rows** (Select only; dropdown menu rows follow the Menu entries above): selected / hovered highlight fills use the **8px inner radius** (see §5 — the panel is a 12px container, the row highlight is the inner 8px tier; the inner radius must be smaller than the container's to nest cleanly). Highlight bg via `--surface-hover` / Radix `data-[highlighted]`; selected rows get the chip fill, unselected rows stay transparent.
-- **Composer dropdown rows — one contract with the shared menu** (2026-10-04, supersedes 2026-07-22): the composer menus keep their own shells — MorphPopover (model / permission / + / agent; §14.4 container transform unchanged), the / and @ lists, the bot-chat @ list and the settings search results — but use the shared menu row parts from `components/ui/menu-row.tsx`: `COMPOSER_MENU_ROW` (8px radius, menu text / weight / motion), `menuRowAttrs`, `withMenuLabels`, and one glide highlight per panel (`useMenuPanel` + `MenuHighlightLayer`, the same `--sidebar-item-hover` layer as the shared menu). Rows set no `hover:` / `focus:` fill of their own. The selected row is marked by a check + 500 and never by a fill — permission, + and agent menus. **The model menu is the one exception** (owner ruling 2026-10-04, keeping the 2026-08-13 ruling): its chosen row keeps a whole-row `--sidebar-item-hover` fill with no check, the model name stays 500, and the effort / follow-session rows keep their fill and existing check; it still takes the shared glide highlight and the glass panel. Danger-tier orange / blue tints the **text only**. Lists that keep focus in a text input (/, @, bot @, settings search) stay focus-in-input: the highlight follows their own current index (`data-menu-current` or `aria-selected`) through `attachMenuHighlight`'s `current` option, never Radix focus. Panels: MorphPopover ends on `--menu-panel-surface` (the shared menu's glass under Cindy themes, opaque on Windows) with `--cmd-palette-border` and `--shadow-menu`; the / and @ lists and the model config flyout use the same 12px panel and `--shadow-menu` (the softer `--cmd-palette-shadow` stays for the command palette and the / tooltip). Group labels use the shared label (12 / 500 / `--cmd-palette-item-meta`). When touching any composer menu's row styles, change them through `menu-row.tsx` — never one menu alone.
+- **Composer dropdown rows — one contract with the shared menu** (2026-10-04, supersedes 2026-07-22): the composer menus keep their own shells — MorphPopover (model / permission / + / agent; §14.4 container transform unchanged), the / and @ lists, the bot-chat @ list and the settings search results — but use the shared menu row parts from `components/ui/menu-row.tsx`: `COMPOSER_MENU_ROW` (8px radius, menu text / weight / motion), `menuRowAttrs`, `withMenuLabels`, and one glide highlight per panel (`useMenuPanel` + `MenuHighlightLayer`, the same `--sidebar-item-hover` layer as the shared menu). Rows inside a glide panel set no `hover:` / `focus:` fill of their own (rows that sit outside any glide panel — the model config card's engine rows, the legacy follow-session and "manage providers" rows — keep a `hover:bg-sidebar-item-hover` fill in the same grey). The selected row is marked by a check + 500 and never by a fill — permission, + and agent menus. **The model menu is the one exception** (owner ruling 2026-10-04, keeping the 2026-08-13 ruling): its chosen row keeps a whole-row `--sidebar-item-hover` fill with no check (`data-[menu-active]:bg-transparent`, so the fill steps aside while the glide layer covers that row instead of stacking two translucent layers), the model name stays 500, and the effort / follow-session rows keep their fill and existing check; it still takes the shared glide highlight and the glass panel. Danger-tier orange / blue tints the **text only**. Lists that keep focus in a text input (/, @, bot @, settings search) stay focus-in-input: the highlight follows their own current index (`data-menu-current` or `aria-selected`) through `attachMenuHighlight`'s `current` option, never Radix focus. Panels: MorphPopover ends on `--menu-panel-surface` (the shared menu's glass under Cindy themes, opaque on Windows) with `--cmd-palette-border` and `--shadow-menu`; the / and @ lists and the model config flyout use the same 12px panel and `--shadow-menu` (the softer `--cmd-palette-shadow` stays for the command palette and the / tooltip). Group labels use the shared label (12 / 500 / `--cmd-palette-item-meta`). When touching any composer menu's row styles, change them through `menu-row.tsx` — never one menu alone.
FormField → Select forwards descriptions, required/error semantics, and the semantic error border; native browser required validation remains opt-in by the business form.