Files
pipelines/app/lib/features/chat/domain/chat_cycle.dart
T
alan 23d8658e80 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>
2026-12-01 14:28:18 +00:00

53 lines
2.3 KiB
Dart

import '../../../core/api_gateway.dart';
import 'chat_sessions.dart';
/// The rows the chat list draws, top to bottom: the [query]'s matches in
/// Starred, then Chats by directory, then Closed, leaving out every section
/// [isOpen] reports folded. Ctrl+1…Ctrl+9 and Next chat both count these.
List<JsonMap> chatSessionsShown(
List<JsonMap> sessions, {
required String query,
required bool Function(String title) isOpen,
}) => chatSessionsInListOrder(
chatSessionSections(filterChatSessions(sessions, query)),
isOpen: isOpen,
);
/// The row after [currentId] in [shown], wrapping from the last row to the
/// first. A chat not among [shown] (its section is folded) moves to the
/// first row. Null when no other row is shown, so there is nothing to move to.
JsonMap? chatSessionAfter(List<JsonMap> shown, String currentId) {
final index = shown.indexWhere((row) => '${row['id'] ?? ''}' == currentId);
final others = index < 0 ? shown.length : shown.length - 1;
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];
}