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): 浏览历史快捷键挂到常驻壳层,默认键位让位用户改绑

WZBbiao9dfa2d2542f6
diff --git a/apps/desktop/src/main/__tests__/appShortcuts.test.ts b/apps/desktop/src/main/__tests__/appShortcuts.test.ts
index 5481e2aba3..a9edddab9b 100644
--- a/apps/desktop/src/main/__tests__/appShortcuts.test.ts
+++ b/apps/desktop/src/main/__tests__/appShortcuts.test.ts
@@ -397,3 +397,28 @@ describe('switch-session slots (mod+1..9)', () => {
expect(effective.get('save-file')).toEqual([sCombo]);
});
});
+
+describe('session history defaults', () => {
+ // 老用户可能在新增这对默认键之前就把别的动作改绑到 ⌘[ / ⌘]:写入侧只校验
+ // 当时的规则,升级后两条默认会同时生效,一次按键既切侧栏又后退。
+ it('yields ⌘[ / ⌘] to an existing user binding on the same combo', () => {
+ const bracketLeft = combo('BracketLeft', { meta: true });
+ const bracketRight = combo('BracketRight', { meta: true });
+ const effective = getEffectiveAppShortcuts(
+ { 'toggle-sidebar': bracketLeft, 'find-in-page': bracketRight },
+ 'darwin',
+ );
+
+ expect(effective.get('session-history-back')).toEqual([]);
+ expect(effective.get('session-history-forward')).toEqual([]);
+ // 用户自己的改绑照常生效,没有被新默认抢走。
+ expect(effective.get('toggle-sidebar')).toEqual([bracketLeft]);
+ expect(effective.get('find-in-page')).toEqual([bracketRight]);
+ });
+
+ it('keeps the defaults when nothing else claims them', () => {
+ const effective = getEffectiveAppShortcuts({}, 'darwin');
+ expect(effective.get('session-history-back')).toEqual([combo('BracketLeft', { meta: true })]);
+ expect(effective.get('session-history-forward')).toEqual([combo('BracketRight', { meta: true })]);
+ });
+});
diff --git a/apps/desktop/src/renderer/components/layout/ChromeActions.tsx b/apps/desktop/src/renderer/components/layout/ChromeActions.tsx
index 06df65d5dd..9e70471a2d 100644
--- a/apps/desktop/src/renderer/components/layout/ChromeActions.tsx
+++ b/apps/desktop/src/renderer/components/layout/ChromeActions.tsx
@@ -39,10 +39,8 @@ import { useTranslation } from 'react-i18next';
import { MenuButton } from '@/components/title-bar/MenuButton';
import { ChromeIconButton } from '@/components/title-bar/ChromeIconButton';
import { Tip } from '@/components/ui/tooltip';
-import { useAuth } from '@/contexts/AuthContext';
import { useMacFullscreen } from '@/hooks/useMacFullscreen';
import { useAppShortcutDisplay } from '@/hooks/useAppShortcut';
-import { useSessionBrowseHistory } from '@/features/cc-agent/useSessionBrowseHistory';
import type { SessionBrowseNavigation } from '@/features/cc-agent/useSessionBrowseHistory';
import { cn } from '@/lib/utils';
@@ -52,6 +50,11 @@ import { CHROME_ACTIONS_GEOMETRY } from './chromeActionsGeometry';
interface ChromeActionsProps {
isSidebarCollapsed: boolean;
onToggleSidebar: () => void;
+ /**
+ * 任务浏览栈。由常驻壳层 MainLayout 持有:设置页会整个卸载本按钮簇,
+ * 快捷键监听不能跟着按钮一起消失。
+ */
+ browseHistory: SessionBrowseNavigation;
/**
* 完全隐藏态 hover peek 的触发钮 props(useSidebarPeek)——只挂在折叠按钮上,
* MenuButton 的 hover 有自己的语义(打开菜单),不参与 peek。
@@ -62,15 +65,11 @@ interface ChromeActionsProps {
export function ChromeActions({
isSidebarCollapsed,
onToggleSidebar,
+ browseHistory,
peekTriggerProps,
}: ChromeActionsProps) {
const { t } = useTranslation();
const { isMac, isFullscreen } = useMacFullscreen();
- // 浏览栈按数据所有者(账号 + 恢复代次)隔离:切号时不能把上一个账号的任务带过来。
- const { dataOwnerId, dataOwnerRecoveryEpoch } = useAuth();
- const browseHistory = useSessionBrowseHistory({
- ownerKey: `${dataOwnerId ?? 'signed-out'}:${dataOwnerRecoveryEpoch}`,
- });
// 钉死左上角:mac 非全屏让位红绿灯(78),其余 8。不随侧栏状态变化。
const x =
diff --git a/apps/desktop/src/renderer/components/layout/MainLayout.tsx b/apps/desktop/src/renderer/components/layout/MainLayout.tsx
index d23856e900..a856ff16c3 100644
--- a/apps/desktop/src/renderer/components/layout/MainLayout.tsx
+++ b/apps/desktop/src/renderer/components/layout/MainLayout.tsx
@@ -102,6 +102,8 @@ import {
toggleAgentIslandSoundEnabled,
} from '@/hooks/useAgentIslandSettings';
import { requestNewWorkerFromShortcut } from '@/features/cc-agent/lib/newWorkerShortcut';
+import { useSessionBrowseHistory } from '@/features/cc-agent/useSessionBrowseHistory';
+import { useAuth } from '@/contexts/AuthContext';
// chat-data-localization F1 V0.4 / M-FE6
import { useCorruptionRestoredToast } from '@/hooks/useCorruptionRestoredToast';
// #37 schema-drift release-side toast
@@ -454,6 +456,15 @@ export function MainLayout() {
const isSettingsRoute = location.pathname === '/settings';
+ // 任务浏览栈与它的快捷键监听挂在常驻壳层:设置页会整个卸载左上按钮簇
+ // (下面的 `!isSettingsRoute && <ChromeActions>`),快捷键不能跟着一起消失——
+ // hook 的语义包含「从设置等栈外页后退回最近任务」。浏览栈按数据所有者
+ // (账号 + 恢复代次)隔离:切号时不能把上一个账号的任务带过来。
+ const { dataOwnerId, dataOwnerRecoveryEpoch } = useAuth();
+ const browseHistory = useSessionBrowseHistory({
+ ownerKey: `${dataOwnerId ?? 'signed-out'}:${dataOwnerRecoveryEpoch}`,
+ });
+
// 完全隐藏态 hover 临时浮出(peek)状态机 —— hover 折叠按钮抽屉滑出预览,
// 点击/⌘B 固定展开(pin)。rail 态(isCollapsed=false)不触发。见 useSidebarPeek。
const sidebarPeek = useSidebarPeek({
@@ -1691,6 +1702,7 @@ export function MainLayout() {
<ChromeActions
isSidebarCollapsed={isSidebarCollapsed}
onToggleSidebar={handleToggleSidebar}
+ browseHistory={browseHistory}
peekTriggerProps={sidebarPeek.triggerProps}
/>
)}
diff --git a/apps/desktop/src/renderer/components/layout/__tests__/ChromeActions.fullscreen.test.tsx b/apps/desktop/src/renderer/components/layout/__tests__/ChromeActions.fullscreen.test.tsx
index 13cf493f16..b73f811d88 100644
--- a/apps/desktop/src/renderer/components/layout/__tests__/ChromeActions.fullscreen.test.tsx
+++ b/apps/desktop/src/renderer/components/layout/__tests__/ChromeActions.fullscreen.test.tsx
@@ -84,6 +84,14 @@ afterEach(() => {
});
describe('ChromeActions fullscreen fallback', () => {
+ // 浏览栈现在由常驻壳层持有,按钮簇只接收它的快照;这组用例与浏览无关。
+ const idleBrowseHistory = {
+ canBack: false,
+ canForward: false,
+ goBack: () => false,
+ goForward: () => false,
+ };
+
it('lets a macOS user exit fullscreen when native traffic lights are unavailable', () => {
const windowExitFullscreen = vi.fn();
Object.defineProperty(window, 'electronAPI', {
@@ -93,7 +101,7 @@ describe('ChromeActions fullscreen fallback', () => {
render(
<MemoryRouter>
- <ChromeActions isSidebarCollapsed={false} onToggleSidebar={vi.fn()} />
+ <ChromeActions isSidebarCollapsed={false} onToggleSidebar={vi.fn()} browseHistory={idleBrowseHistory} />
</MemoryRouter>,
);
fireEvent.click(screen.getByRole('button', { name: 'contentHeader.exitFullscreen' }));
@@ -106,7 +114,7 @@ describe('ChromeActions fullscreen fallback', () => {
render(
<MemoryRouter>
- <ChromeActions isSidebarCollapsed={false} onToggleSidebar={vi.fn()} />
+ <ChromeActions isSidebarCollapsed={false} onToggleSidebar={vi.fn()} browseHistory={idleBrowseHistory} />
</MemoryRouter>,
);
diff --git a/apps/desktop/src/shared/appShortcuts.ts b/apps/desktop/src/shared/appShortcuts.ts
index 5ecc5b276f..af119033a7 100644
--- a/apps/desktop/src/shared/appShortcuts.ts
+++ b/apps/desktop/src/shared/appShortcuts.ts
@@ -168,6 +168,9 @@ export const APP_SHORTCUT_DEFINITIONS: ReadonlyArray<AppShortcutDefinition> = [
labelKey: 'settings.shortcuts.items.session-history-back.label',
descriptionKey: 'settings.shortcuts.items.session-history-back.description',
rebindable: true,
+ // 新增默认键位对用户既有改绑让位:老用户把 toggle-sidebar 等动作改绑到 ⌘[ 是
+ // 历史合法绑定,若两个动作同名生效,一次按键会同时切侧栏与后退。
+ yieldsToUserBindings: true,
getDefaultCombos: (platform) => [modCombo('BracketLeft', platform)],
},
{
@@ -176,6 +179,7 @@ export const APP_SHORTCUT_DEFINITIONS: ReadonlyArray<AppShortcutDefinition> = [
labelKey: 'settings.shortcuts.items.session-history-forward.label',
descriptionKey: 'settings.shortcuts.items.session-history-forward.description',
rebindable: true,
+ yieldsToUserBindings: true,
getDefaultCombos: (platform) => [modCombo('BracketRight', platform)],
},
{