Cycle Ctrl-Tab through available chats
When a tiled workspace has one chat pane, navigate the sidebar chat order while preserving pane state and composer focus. Keep pane and floating-window cycling behavior for their existing layouts, and update shortcut documentation and coverage.
This commit is contained in:
@@ -278,14 +278,12 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
String? _publishedWorkspaceSession;
|
||||
String _workspaceSignature = '';
|
||||
|
||||
/// Ctrl+Tab cycles the floating chat windows while any is shown, from the
|
||||
/// tiling as well (see [ChatWindows]). With none shown it cycles the
|
||||
/// retained panes, even when the sidebar or toolbar owns focus, and over a
|
||||
/// single pane it does nothing: it never brings up a chat that is not
|
||||
/// visible in the tiling. Command+Tab stays with the operating system's
|
||||
/// application switcher. While the app's terminal is shown, Ctrl+Tab moves
|
||||
/// between its tabs instead. A floating window that is not a chat, or any
|
||||
/// other window holding the keyboard, keeps the key.
|
||||
/// 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]).
|
||||
/// Command+Tab stays with the operating system's application switcher, and
|
||||
/// the terminal keeps Ctrl+Tab for its own tabs.
|
||||
bool _cycleChatKey(KeyEvent event) {
|
||||
final keyboard = HardwareKeyboard.instance;
|
||||
if (event is! KeyDownEvent ||
|
||||
@@ -298,8 +296,48 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
!_chatOwnsKeyboard()) {
|
||||
return false;
|
||||
}
|
||||
if (widget.windows?.raiseTopFromTiling() ?? false) return true;
|
||||
if (!_workspaceVisible || _workspace.paneCount < 2) 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,
|
||||
|
||||
@@ -237,6 +237,23 @@ class ChatWorkspaceController extends ChangeNotifier {
|
||||
_changed();
|
||||
}
|
||||
|
||||
/// Replaces a pane after its caller has already validated [newId]. Unlike
|
||||
/// [replaceSession], this does not ask the window host to show a floating
|
||||
/// chat; keyboard cycling filters those chats before calling this method.
|
||||
void replacePaneSession(String paneId, String newId) {
|
||||
if (newId.isEmpty) return;
|
||||
final pane = panes.where((p) => p.id == paneId).firstOrNull;
|
||||
if (pane == null) return;
|
||||
final existing = panes.where((p) => p.sessionId == newId).firstOrNull;
|
||||
if (existing != null) {
|
||||
close(pane.id);
|
||||
activate(existing.id);
|
||||
return;
|
||||
}
|
||||
_root = _replace(_root!, pane.id, ChatWorkspacePane(pane.id, newId));
|
||||
_changed();
|
||||
}
|
||||
|
||||
ChatWorkspaceNode _replace(
|
||||
ChatWorkspaceNode node,
|
||||
String id,
|
||||
|
||||
@@ -156,10 +156,10 @@ class KeyboardShortcutRegistry {
|
||||
if (!web)
|
||||
const KeyboardShortcutEntry(
|
||||
group: KeyboardShortcutGroup.chat,
|
||||
action: 'Cycle chat panes and floating chats',
|
||||
action: 'Cycle chats and floating chat panes',
|
||||
keys: 'Ctrl+Tab, Ctrl+Shift+Tab',
|
||||
caveat:
|
||||
'While the terminal is shown, Ctrl+Tab moves between its tabs instead.',
|
||||
'With one tiled pane, cycles open sidebar chats (excluding closed, hidden and floating chats); with multiple panes, cycles panes. While the terminal is shown, Ctrl+Tab moves between its tabs instead.',
|
||||
),
|
||||
const KeyboardShortcutEntry(
|
||||
group: KeyboardShortcutGroup.chat,
|
||||
|
||||
Reference in New Issue
Block a user