Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 协同 tabs 溢出时提供可点的横向滚动
Lengc0c8a72e778e
diff --git a/apps/desktop/src/renderer/features/cc-agent/RolePillDropdown.tsx b/apps/desktop/src/renderer/features/cc-agent/RolePillDropdown.tsxindex 459c313ef3..4528e44d5b 100644--- a/apps/desktop/src/renderer/features/cc-agent/RolePillDropdown.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/RolePillDropdown.tsx@@ -15,7 +15,7 @@ import {type WheelEvent,} from 'react';import { useTranslation } from 'react-i18next';-import { Check, ChevronDown, ChevronUp, Plus, X, EllipsisVertical } from 'lucide-react';+import { Check, ChevronDown, ChevronLeft, ChevronRight, ChevronUp, Plus, X, EllipsisVertical } from 'lucide-react';import { cn } from '@/lib/utils';import { useAppShortcutDisplay } from '@/hooks/useAppShortcut';import { useConfirmDialog } from '@/components/ui/confirm-dialog-provider';@@ -159,6 +159,11 @@ function ensureChildHorizontallyVisible(container: HTMLElement, child: HTMLEleme}}+/** Distance for one overflow nudge. Exported for unit tests. */+export function workerTabsScrollStep(clientWidth: number): number {+ return Math.max(80, Math.floor(clientWidth * 0.7));+}+type WorkerListLayout = 'tabs' | 'dropdown';type DropdownOpenMode = 'transient' | 'pinned' | null;@@ -801,7 +806,8 @@ function WorkerTabsList({<div className="relative min-w-0 flex-1"><divref={scrollRef}- className="flex min-w-0 items-center gap-1 overflow-x-auto pr-3 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"+ data-testid="worker-tabs-scroller"+ className="flex min-w-0 flex-nowrap items-center gap-1 overflow-x-auto overscroll-x-contain pr-3 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"onScroll={updateScrollState}onWheel={handleWheel}>@@ -875,18 +881,46 @@ function WorkerTabsList({})}</div>{scrollState.left && (- <div- aria-hidden- className="pointer-events-none absolute inset-y-0 left-0 w-5"- style={{ background: 'linear-gradient(to right, hsl(var(--content-area)), transparent)' }}- />+ <>+ <div+ aria-hidden+ className="pointer-events-none absolute inset-y-0 left-0 w-8"+ style={{ background: 'linear-gradient(to right, hsl(var(--content-area)), transparent)' }}+ />+ <button+ type="button"+ aria-label={t('orca.rolePill.scrollWorkersLeft')}+ className="absolute inset-y-0 left-0 z-10 inline-flex w-6 items-center justify-center text-[var(--text-secondary)] hover:text-[var(--text-primary)]"+ onClick={() => {+ const element = scrollRef.current;+ if (!element) return;+ element.scrollBy({ left: -workerTabsScrollStep(element.clientWidth), behavior: 'smooth' });+ }}+ >+ <ChevronLeft size={14} />+ </button>+ </>)}{scrollState.right && (- <div- aria-hidden- className="pointer-events-none absolute inset-y-0 right-0 w-7"- style={{ background: 'linear-gradient(to right, transparent, hsl(var(--content-area)))' }}- />+ <>+ <div+ aria-hidden+ className="pointer-events-none absolute inset-y-0 right-0 w-8"+ style={{ background: 'linear-gradient(to right, transparent, hsl(var(--content-area)))' }}+ />+ <button+ type="button"+ aria-label={t('orca.rolePill.scrollWorkersRight')}+ className="absolute inset-y-0 right-0 z-10 inline-flex w-6 items-center justify-center text-[var(--text-secondary)] hover:text-[var(--text-primary)]"+ onClick={() => {+ const element = scrollRef.current;+ if (!element) return;+ element.scrollBy({ left: workerTabsScrollStep(element.clientWidth), behavior: 'smooth' });+ }}+ >+ <ChevronRight size={14} />+ </button>+ </>)}</div>);diff --git a/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.tabsScroll.test.tsx b/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.tabsScroll.test.tsxnew file mode 100644index 0000000000..9776c55011--- /dev/null+++ b/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.tabsScroll.test.tsx@@ -0,0 +1,125 @@+// @vitest-environment jsdom++import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++import type { WorkerInfo } from '../hooks/useWorkers';+import { WorkerListToolbar, workerTabsScrollStep } from '../RolePillDropdown';++vi.mock('react-i18next', () => ({+ useTranslation: () => ({ t: (key: string) => key }),+}));++vi.mock('@/hooks/useAppShortcut', () => ({+ useAppShortcutDisplay: () => '',+}));++vi.mock('@/components/ui/confirm-dialog-provider', () => ({+ useConfirmDialog: () => ({ confirm: vi.fn(async () => false) }),+}));++function worker(overrides: Partial<WorkerInfo> = {}): WorkerInfo {+ return {+ workerId: 'worker-a',+ sessionId: 'session-a',+ role: 'developer',+ agent: 'codex',+ model: 'gpt-5.4',+ effort: null,+ label: null,+ status: 'idle',+ focused: true,+ idleSince: null,+ ...overrides,+ };+}++function manyWorkers(count: number): WorkerInfo[] {+ return Array.from({ length: count }, (_, index) =>+ worker({+ workerId: `worker-${index}`,+ sessionId: `session-${index}`,+ focused: index === 0,+ label: `w${index}`,+ }),+ );+}++function renderOverflowToolbar(workers = manyWorkers(6)) {+ return render(+ <WorkerListToolbar+ worker={workers[0]}+ workers={workers}+ selectedWorkerId={workers[0].workerId}+ activeWorkerCount={workers.length}+ softLimit={5}+ hardLimit={8}+ onSwitchFocus={vi.fn()}+ onOpenCreate={vi.fn()}+ onOpenSettings={vi.fn()}+ onArchiveWorker={vi.fn()}+ />,+ );+}++function mockScrollerOverflow(scroller: HTMLElement, { scrollLeft = 0, clientWidth = 200, scrollWidth = 800 } = {}) {+ Object.defineProperty(scroller, 'clientWidth', { configurable: true, value: clientWidth });+ Object.defineProperty(scroller, 'scrollWidth', { configurable: true, value: scrollWidth });+ Object.defineProperty(scroller, 'scrollLeft', {+ configurable: true,+ get: () => scrollLeft,+ set: (value: number) => {+ scrollLeft = value;+ },+ });+}++describe('WorkerTabsList overflow scrolling', () => {+ beforeEach(() => {+ localStorage.clear();+ });++ afterEach(() => {+ cleanup();+ });++ it('uses a bounded step that fits the visible tab strip', () => {+ expect(workerTabsScrollStep(200)).toBe(140);+ expect(workerTabsScrollStep(40)).toBe(80);+ });++ it('does not show scroll buttons when every tab fits', () => {+ renderOverflowToolbar(manyWorkers(2));+ const scroller = screen.getByTestId('worker-tabs-scroller');+ mockScrollerOverflow(scroller, { clientWidth: 400, scrollWidth: 200 });+ fireEvent.scroll(scroller);+ expect(screen.queryByRole('button', { name: 'orca.rolePill.scrollWorkersLeft' })).toBeNull();+ expect(screen.queryByRole('button', { name: 'orca.rolePill.scrollWorkersRight' })).toBeNull();+ });++ it('shows a right arrow when tabs overflow and scrolls one step', () => {+ renderOverflowToolbar();+ const scroller = screen.getByTestId('worker-tabs-scroller');+ const scrollBy = vi.fn();+ mockScrollerOverflow(scroller, { scrollLeft: 0, clientWidth: 200, scrollWidth: 800 });+ scroller.scrollBy = scrollBy;+ fireEvent.scroll(scroller);++ expect(screen.queryByRole('button', { name: 'orca.rolePill.scrollWorkersLeft' })).toBeNull();+ const right = screen.getByRole('button', { name: 'orca.rolePill.scrollWorkersRight' });+ fireEvent.click(right);+ expect(scrollBy).toHaveBeenCalledWith({ left: workerTabsScrollStep(200), behavior: 'smooth' });+ });++ it('shows a left arrow after scrolling and can scroll back', () => {+ renderOverflowToolbar();+ const scroller = screen.getByTestId('worker-tabs-scroller');+ const scrollBy = vi.fn();+ mockScrollerOverflow(scroller, { scrollLeft: 240, clientWidth: 200, scrollWidth: 800 });+ scroller.scrollBy = scrollBy;+ fireEvent.scroll(scroller);++ fireEvent.click(screen.getByRole('button', { name: 'orca.rolePill.scrollWorkersLeft' }));+ expect(scrollBy).toHaveBeenCalledWith({ left: -workerTabsScrollStep(200), behavior: 'smooth' });+ });+});diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex cd22ff61d4..cb34184e23 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -9763,6 +9763,8 @@"layoutMenuLabel": "Worker list layout","layoutTabs": "Tabs","layoutDropdown": "Dropdown",+ "scrollWorkersLeft": "Scroll to earlier workers",+ "scrollWorkersRight": "Scroll to more workers","errorBadge": "ERR","errorBadgeAria": "A worker has an error"},diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex 37f00953bc..dac6ec16a6 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -9749,6 +9749,8 @@"layoutMenuLabel": "Worker リストの表示方式","layoutTabs": "タブ","layoutDropdown": "ドロップダウン",+ "scrollWorkersLeft": "前の Worker を表示",+ "scrollWorkersRight": "次の Worker を表示","errorBadge": "エラー","errorBadgeAria": "エラーが発生した Worker があります"},diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex ddde704b3f..10410f43af 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -9749,6 +9749,8 @@"layoutMenuLabel": "Worker 목록 표시 방식","layoutTabs": "탭","layoutDropdown": "드롭다운",+ "scrollWorkersLeft": "이전 Worker 보기",+ "scrollWorkersRight": "다음 Worker 보기","errorBadge": "오류","errorBadgeAria": "오류가 발생한 Worker 가 있습니다"},diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 7472f5ab8b..1f0a722f61 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -9749,6 +9749,8 @@"layoutMenuLabel": "Worker 列表显示方式","layoutTabs": "平铺","layoutDropdown": "下拉",+ "scrollWorkersLeft": "向左查看更多 Worker",+ "scrollWorkersRight": "向右查看更多 Worker","errorBadge": "错误","errorBadgeAria": "有 Worker 出错"},diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.jsonindex 21891e86e3..64a5eba29d 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json@@ -9749,6 +9749,8 @@"layoutMenuLabel": "Worker 列表顯示方式","layoutTabs": "平鋪","layoutDropdown": "下拉",+ "scrollWorkersLeft": "向左查看更多 Worker",+ "scrollWorkersRight": "向右查看更多 Worker","errorBadge": "錯誤","errorBadgeAria": "有 Worker 出錯"},