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
@@ -106,7 +106,7 @@ void _focusSidebar(WidgetTester tester) {
}
void main() {
testWidgets('Control Tab wraps visual pane order and focuses each composer', (
testWidgets('Control Tab wraps the chat list, focusing panes and composers', (
tester,
) async {
await _setup(tester);
@@ -168,7 +168,8 @@ void main() {
expect(_editable(tester, id).focusNode.hasPrimaryFocus, isTrue);
}
// Two panes still cycle panes, not the chat list.
// Two panes also cycle the chat list: b opens in the active pane, and
// c, already in the other pane, takes focus there.
await _openRow(tester, 'c');
await tester.tap(_actions('a'));
await tester.pumpAndSettle();
@@ -177,10 +178,11 @@ void main() {
expect(workspace.paneCount, 2);
expect(workspace.activePane?.sessionId, 'a');
await _controlTab(tester);
expect(workspace.activePane?.sessionId, 'c');
expect(workspace.activePane?.sessionId, 'b');
await _controlTab(tester);
expect(workspace.activePane?.sessionId, 'a');
expect(workspace.activePane?.sessionId, 'c');
expect(workspace.paneCount, 2);
expect({for (final pane in workspace.panes) pane.sessionId}, {'b', 'c'});
await tester.pumpWidget(const SizedBox.shrink());
});
}
@@ -0,0 +1,217 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_actions.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/features/terminal/terminal_scope.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'conversation/chat_thread_fixtures.dart';
/// Ctrl+Tab steps through the list's chats: the starred ones when any is
/// starred, otherwise every open chat, opening each as a click would.
class _Gateway extends FakeChatGateway {
_Gateway(this.rows, this.starred);
final List<String> rows;
final Set<String> starred;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
for (final id in rows)
{
'id': id,
'title': 'Chat $id',
if (starred.contains(id)) 'starred': true,
if (id == 'closed') 'closed_at': 1,
},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
return super.call(type, fields);
}
}
class _ClaimingTerminal implements TerminalActions {
const _ClaimingTerminal();
@override
void toggle() {}
@override
bool get claimsTabKeys => true;
@override
Future<String?> openAt(ApiGateway gateway, String cwd) async => null;
}
Finder _input(String id) => find.descendant(
of: find.byKey(ValueKey('chat-composer-$id')),
matching: find.byType(EditableText),
);
ChatWorkspaceController _workspace(WidgetTester tester) =>
tester.widget<ChatWorkspace>(find.byType(ChatWorkspace)).controller;
String? _active(WidgetTester tester) =>
_workspace(tester).activePane?.sessionId;
List<String> _paneSessions(WidgetTester tester) => [
for (final pane in _workspace(tester).panes) pane.sessionId,
];
Future<void> _tab(WidgetTester tester, {bool reverse = false}) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
if (reverse) await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
if (reverse) await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pumpAndSettle();
}
Future<void> _setup(
WidgetTester tester, {
required List<String> rows,
Set<String> starred = const {},
required String open,
Size size = const Size(1800, 1000),
bool terminal = false,
}) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = _Gateway(rows, starred)..history = (_) async => chatPage([]);
addTearDown(gateway.close);
await tester.pumpWidget(
MaterialApp(
builder: terminal
? (context, child) =>
TerminalScope(actions: const _ClaimingTerminal(), child: child!)
: null,
home: AdaptiveShell(
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) => ChatScreen(gateway: gateway),
},
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(Key('chat-row-$open')));
await tester.pumpAndSettle();
}
void main() {
testWidgets('starred chats only, in list order, wrapping both ways', (
tester,
) async {
// Starred sorts by title: Chat b, Chat d.
await _setup(
tester,
rows: ['a', 'd', 'c', 'b', 'closed'],
starred: {'b', 'd'},
open: 'b',
);
await _tab(tester);
expect(_active(tester), 'd');
expect(
tester.widget<EditableText>(_input('d')).focusNode.hasPrimaryFocus,
isTrue,
);
await _tab(tester);
expect(_active(tester), 'b');
await _tab(tester, reverse: true);
expect(_active(tester), 'd');
await _tab(tester, reverse: true);
expect(_active(tester), 'b');
expect(_workspace(tester).paneCount, 1);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('from an unstarred chat: first starred, or last backwards', (
tester,
) async {
await _setup(
tester,
rows: ['a', 'd', 'c', 'b'],
starred: {'b', 'd'},
open: 'a',
);
await _tab(tester);
expect(_active(tester), 'b');
await tester.tap(find.byKey(const Key('chat-row-c')));
await tester.pumpAndSettle();
await _tab(tester, reverse: true);
expect(_active(tester), 'd');
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('no starred chat: every open chat, closed left out', (
tester,
) async {
await _setup(tester, rows: ['a', 'b', 'c', 'closed'], open: 'a');
for (final id in ['b', 'c', 'a']) {
await _tab(tester);
expect(_active(tester), id);
}
await _tab(tester, reverse: true);
expect(_active(tester), 'c');
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('a chat shown in another pane is focused, never duplicated', (
tester,
) async {
await _setup(tester, rows: ['a', 'b', 'c'], open: 'a');
await tester.tap(
find.byWidgetPredicate(
(widget) =>
widget is SessionActionsButton && widget.session['id'] == 'c',
),
);
await tester.pumpAndSettle();
await tester.tap(find.text('Open to the right'));
await tester.pumpAndSettle();
expect(_paneSessions(tester), ['a', 'c']);
expect(_active(tester), 'c');
// c wraps to a, which already has a pane: that pane takes focus.
await _tab(tester);
expect(_paneSessions(tester), ['a', 'c']);
expect(_active(tester), 'a');
// b has no pane: it opens in the active pane, as a click would.
await _tab(tester);
expect(_paneSessions(tester), ['b', 'c']);
expect(_active(tester), 'b');
await _tab(tester);
expect(_paneSessions(tester), ['b', 'c']);
expect(_active(tester), 'c');
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('narrow single-chat view follows the same cycle', (tester) async {
await _setup(
tester,
rows: ['a', 'b', 'c'],
starred: {'a', 'c'},
open: 'a',
size: const Size(400, 800),
);
await _tab(tester);
expect(_active(tester), 'c');
expect(find.byKey(const Key('chat-row-a')).hitTestable(), findsNothing);
await _tab(tester);
expect(_active(tester), 'a');
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('a shown terminal keeps Ctrl+Tab', (tester) async {
await _setup(tester, rows: ['a', 'b', 'c'], open: 'a', terminal: true);
await _tab(tester);
await _tab(tester, reverse: true);
expect(_active(tester), 'a');
await tester.pumpWidget(const SizedBox.shrink());
});
}
@@ -63,4 +63,37 @@ void main() {
expect(_after(const [], 'only'), isNull);
expect(_after(one, 'elsewhere'), 'only');
});
String? tab(List<JsonMap> cycle, String id, int step) =>
chatTabTarget(cycle, id, step)?['id'] as String?;
test('tab cycle: starred only when any open chat is starred', () {
final cycle = chatTabCycle(sessions);
expect(_ids(cycle), ['a', 'z']);
expect(tab(cycle, 'a', 1), 'z');
expect(tab(cycle, 'z', 1), 'a');
expect(tab(cycle, 'a', -1), 'z');
// Outside the cycle: first forwards, last backwards.
expect(tab(cycle, 'r', 1), 'a');
expect(tab(cycle, 'r', -1), 'z');
});
test('tab cycle: every open chat when none is starred', () {
final unstarred = [
for (final row in sessions) {...row}..remove('starred'),
];
final cycle = chatTabCycle(unstarred);
expect(_ids(cycle), ['r', 's', 'z', 'd', 'a']);
expect(tab(cycle, 'a', 1), 'r');
expect(tab(cycle, 'r', -1), 'a');
// A closed starred chat does not make a starred cycle.
final closedStar = <JsonMap>[
{'id': 'x', 'starred': true, 'closed_at': 1},
{'id': 'y'},
{'id': 'w', 'closed': true},
];
expect(_ids(chatTabCycle(closedStar)), ['y']);
expect(tab(chatTabCycle(closedStar), 'y', 1), isNull);
expect(tab(const [], 'y', 1), isNull);
});
}