Skip to content

fix(conversation): cycle visible sessions with ctrl+tab#1623

Merged
piorpua merged 4 commits intoiOfficeAI:mainfrom
Eric-Song-Nop:shortcuts
Mar 24, 2026
Merged

fix(conversation): cycle visible sessions with ctrl+tab#1623
piorpua merged 4 commits intoiOfficeAI:mainfrom
Eric-Song-Nop:shortcuts

Conversation

@Eric-Song-Nop
Copy link
Copy Markdown
Contributor

Summary

  • change Ctrl+Tab session switching to follow the visible sidebar conversation order
  • include pinned conversations and expanded workspace conversations while skipping hidden collapsed items
  • keep Cmd/Ctrl+T behavior and add regression coverage for the new cycling logic

Changes

  • add a shared visible conversation order utility and hook based on grouped history state
  • update the global conversation shortcut hook to navigate by visible sidebar sessions instead of custom workspace tabs
  • synchronize workspace expansion state so shortcut order matches the current sidebar UI
  • add unit and DOM tests for visible ordering and Ctrl+Tab navigation behavior

Related Issue

Closes #1142

Test Plan

  • bun run lint:fix
  • bun run format
  • bunx tsc --noEmit
  • bun run test

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fa35ed6c4a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

useDeepLink();
useNotificationClick();
const navigate = useNavigate();
useConversationShortcuts({ navigate });
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Mount the shortcut hook under LayoutContext.Provider

Because useConversationShortcuts is invoked before LayoutContext.Provider is rendered, useVisibleConversationIds() always gets useLayoutContext() === null and falls back to siderCollapsed = false (src/renderer/pages/conversation/GroupedHistory/hooks/useVisibleConversationIds.ts). In the exact case this change is trying to fix—cycling while the sidebar is collapsed—workspace conversations are still treated as hidden, so Ctrl+Tab skips them or stops entirely for conversations inside collapsed workspaces.

Useful? React with 👍 / 👎.

Comment on lines +46 to +48
if (isConversationTabShortcut(event)) {
event.preventDefault();
const currentConversationId = location.pathname.match(/^\/conversation\/([^/]+)/)?.[1] ?? null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid preventing Ctrl+Tab on non-conversation routes

This handler calls preventDefault() before confirming that the user is actually on /conversation/:id. Since Layout.tsx mounts the hook at the app-shell level, authenticated /guid and /settings/* pages now swallow Ctrl+Tab without navigating anywhere. That is a user-visible regression in the web/PWA build, where Ctrl+Tab is otherwise the browser's native tab-switch shortcut.

Useful? React with 👍 / 👎.

@kaizhou-lab
Copy link
Copy Markdown
Collaborator

kaizhou-lab commented Mar 24, 2026

👍 Ctrl+Tab 会话切换

这个功能很棒!按侧边栏可见顺序循环切换对话,体验很自然。代码结构也很清晰,buildVisibleConversationIds 作为纯函数提取出来方便测试,工作区展开状态通过 CustomEvent 同步的设计也很合理。


1. 建议关注 WebUI 兼容性

目前快捷键在所有环境下都会生效,在 WebUI(浏览器)中会与浏览器原生快捷键冲突:

  • Ctrl+Tab — 浏览器原生的标签页切换会被 preventDefault() 拦截
  • Cmd/Ctrl+T — 浏览器原生的新建标签页会被拦截

建议参考 PR #1625Cmd/Ctrl+Shift+F 的处理方式,为快捷键添加桌面端环境判断:

// 只在 Electron 桌面端拦截,WebUI 中保留浏览器原生行为
if (typeof window !== 'undefined' && !window.electronAPI) return;

可以加在 handleKeyDown 函数的入口处,或者分别加在 isConversationTabShortcutisNewConversationShortcut 中。


2. buildGroupedHistory 重复计算

useVisibleConversationIds 中独立调用了 buildGroupedHistory(conversations, t)useVisibleConversationIds.ts#L16-18),而 useConversations(侧边栏)中已经对同一份 conversations 做了一模一样的分组计算。这意味着每次对话列表变化时,分组逻辑会执行两遍。

对话数量少时影响不大,但随着对话增多会有不必要的性能开销。建议考虑:

  • groupedHistory 提升为共享 context/store,两个 hook 共用同一份计算结果
  • 或者让 useVisibleConversationIds 直接接收 groupedHistory 作为参数,避免内部重复计算

@kaizhou-lab kaizhou-lab self-assigned this Mar 24, 2026
@piorpua piorpua merged commit 6e7199b into iOfficeAI:main Mar 24, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: 快捷键切换对话

3 participants