Chat: Ctrl+Tab cycles the list's chats, starred only when any are starred

Ctrl+Tab / Ctrl+Shift+Tab on the Chat destination now steps through the
chat list's open chats in list order (wrapping) instead of the workspace
panes: only the starred chats when any open chat is starred, otherwise all
open chats. From a chat outside the cycle it goes to the first (Shift: last).
The target opens as a list click does, focusing the pane already showing it.
The terminal's claim on Ctrl+Tab and floating-window cycling are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 14:28:18 +00:00
parent 364e0cb3c9
commit 23d8658e80
8 changed files with 309 additions and 69 deletions
@@ -86,6 +86,7 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
ChatSessionsController get _sessionsForSidebar;
ChatSectionFolds get _foldsForSidebar;
void _openSidebarSession(JsonMap session);
void _openByShortcut(JsonMap session);
void _dropSession(
ChatWorkspacePane target,
@@ -315,10 +316,14 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
String? _publishedWorkspaceSession;
String _workspaceSignature = '';
/// Ctrl+Tab cycles a single tiled pane through the open chats in sidebar
/// order. The pane is replaced in place so its retained view keeps the
/// transcript and draft. With multiple panes it cycles those panes. A
/// focused floating chat window handles the key itself (see [ChatWindows]).
/// Ctrl+Tab (Ctrl+Shift+Tab backwards) opens the next (previous) chat of
/// the list's cycle (see [chatTabCycle]): the starred chats when any is
/// starred, otherwise every open chat, wrapping. The chat opens as a click
/// on its row would: in the active pane, or by focusing the pane that
/// already shows it, so no chat gets a second pane. Its composer takes the
/// keyboard. Closed, hidden and floating chats are left out. It is handled
/// before the focus tree, so it works from the composer too. A focused
/// floating chat window handles the key itself (see [ChatWindows]).
/// Command+Tab stays with the operating system's application switcher, and
/// the terminal keeps Ctrl+Tab for its own tabs.
bool _cycleChatKey(KeyEvent event) {
@@ -333,67 +338,21 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
!_chatOwnsKeyboard()) {
return false;
}
if (!_workspaceVisible || _workspace.paneCount == 0) return false;
if (_workspace.paneCount == 1) {
final pane = _workspace.activePane;
if (pane == null) return false;
final floating = widget.windows?.floatingSessionIds.toSet() ?? const {};
final sessions = chatSessionsShown(
_sessionsForSidebar.sessions
.where(
(row) =>
row['closed_at'] == null &&
row['closed'] != true &&
!floating.contains('${row['id'] ?? ''}'),
)
.toList(),
query: '',
// Cycling is independent of a collapsed section: the sidebar's
// ordering is still used, but every open-chat row remains reachable.
isOpen: (_) => true,
);
final active = sessions.indexWhere(
(row) => '${row['id'] ?? ''}' == pane.sessionId,
);
if (sessions.length < 2 || active < 0) return false;
final direction = keyboard.isShiftPressed ? -1 : 1;
final target = sessions[(active + direction) % sessions.length];
final targetId = '${target['id'] ?? ''}';
if (targetId.isEmpty) return false;
_workspace.replacePaneSession(pane.id, targetId);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted ||
!_workspaceVisible ||
_workspace.activePane?.sessionId != targetId) {
return;
}
final destination = ShellBarScope.maybeOf(context)?.registry.focus;
if (destination == null || destination == AppDestination.chat) {
_composerFocus.request(targetId);
}
});
WidgetsBinding.instance.ensureVisualUpdate();
return true;
}
final panes = _workspace.panes;
final active = panes.indexWhere(
(pane) => pane.id == _workspace.activePaneId,
final current = _workspaceVisible ? _workspace.activePane : null;
if (current == null) return false;
final floating = widget.windows?.floatingSessionIds.toSet() ?? const {};
final cycle = chatTabCycle(
_sessionsForSidebar.sessions
.where((row) => !floating.contains('${row['id'] ?? ''}'))
.toList(),
);
final direction = keyboard.isShiftPressed ? -1 : 1;
final target =
panes[((active < 0 ? 0 : active) + direction) % panes.length];
_workspace.activate(target.id);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted ||
!_workspaceVisible ||
_workspace.activePaneId != target.id) {
return;
}
final destination = ShellBarScope.maybeOf(context)?.registry.focus;
if (destination == null || destination == AppDestination.chat) {
_composerFocus.request(target.sessionId);
}
});
final target = chatTabTarget(
cycle,
current.sessionId,
keyboard.isShiftPressed ? -1 : 1,
);
if (target == null || '${target['id'] ?? ''}'.isEmpty) return false;
_openByShortcut(target);
WidgetsBinding.instance.ensureVisualUpdate();
return true;
}
@@ -22,3 +22,31 @@ JsonMap? chatSessionAfter(List<JsonMap> shown, String currentId) {
if (others < 1) return null;
return shown[(index + 1) % shown.length];
}
/// The chats Ctrl+Tab steps through, in the order the list draws them: the
/// starred chats when any open chat is starred, otherwise every open chat
/// (Chats by directory). Closed chats never take part, and a folded section
/// does not hide its rows from the cycle.
List<JsonMap> chatTabCycle(List<JsonMap> sessions) {
final open = sessions
.where((row) => row['closed_at'] == null && row['closed'] != true)
.toList();
final sections = chatSessionSections(open);
final starred = sections.where((section) => section.title == 'Starred');
return chatSessionsInListOrder(
starred.isNotEmpty ? starred.toList() : sections,
isOpen: (_) => true,
);
}
/// The chat [step] (1 forward, -1 back) from [currentId] in [cycle],
/// wrapping. A chat outside the cycle (unstarred while starred chats exist)
/// moves to the first chat, or the last going back. Null when there is no
/// other chat to move to.
JsonMap? chatTabTarget(List<JsonMap> cycle, String currentId, int step) {
if (cycle.isEmpty) return null;
final index = cycle.indexWhere((row) => '${row['id'] ?? ''}' == currentId);
if (index < 0) return step < 0 ? cycle.last : cycle.first;
if (cycle.length < 2) return null;
return cycle[(index + step) % cycle.length];
}
+1
View File
@@ -229,6 +229,7 @@ class _ChatScreenState extends State<ChatScreen>
/// Opens [session] from the keyboard: its composer takes focus once built,
/// also when it is the chat already open.
@override
void _openByShortcut(JsonMap session) => _open(session, focusComposer: true);
/// Opens [session] chosen by a tap, click or Next chat: its composer takes