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,
|
||||
|
||||
@@ -41,10 +41,11 @@ every destination and come back at app start without Chat being opened.
|
||||
takes the keyboard. Open order is the order the windows were opened (a
|
||||
restored window keeps its saved place), so a raise does not change the
|
||||
cycle; the stacking order does change on a raise.
|
||||
- **With no chat window shown**, Ctrl+Tab cycles the tiled panes only and
|
||||
the keys focus the chosen pane's composer. With one tiled pane it does
|
||||
nothing. A chat shown before, or a minimised or floating chat, is never
|
||||
swapped in.
|
||||
- **With no chat window focused**, Ctrl+Tab cycles the tiled panes and the
|
||||
keys focus the chosen pane's composer. With exactly one tiled pane it
|
||||
cycles all open chats in sidebar order, replacing that pane while keeping
|
||||
its transcript and draft; closed, hidden-on-this-device and floating
|
||||
chats are skipped. With two or more panes it cycles the panes only.
|
||||
- Command+Tab stays with the system. While the terminal claims tab keys
|
||||
(shown) Ctrl+Tab switches terminal tabs. A keyboard held by another window
|
||||
(a run, terminal) is left to that window. Alt+` (`windowCycleShortcut`)
|
||||
@@ -80,36 +81,33 @@ every destination and come back at app start without Chat being opened.
|
||||
|
||||
## Checks
|
||||
|
||||
- Focused, 2026-11-12, `tool/memwatch/full.sh` over
|
||||
- Focused, 2026-11-13, `tool/memwatch/full.sh` over
|
||||
`test/features/chat/chat_floating_pane_test.dart`,
|
||||
`test/features/chat/chat_keyboard_focus_test.dart`,
|
||||
`test/features/chat/chat_control_tab_test.dart`,
|
||||
`test/features/chat/windows/chat_windows_test.dart` and
|
||||
`test/features/terminal/terminal_chat_tab_test.dart`: 38 passed, 0 failed.
|
||||
Related Ctrl+Tab users, `tool/memwatch/full.sh` over
|
||||
`test/features/chat/windows/chat_windows_test.dart`,
|
||||
`test/features/terminal/terminal_chat_tab_test.dart`, the keyboard
|
||||
shortcuts registry test and related Ctrl+Tab users: 70 passed, 0 failed.
|
||||
This included `tool/memwatch/full.sh` over
|
||||
`test/shell/destination_shortcuts_test.dart`,
|
||||
`test/shell/tab_history_back_test.dart`, `test/shell/search_escape_test.dart`
|
||||
and `test/features/chat/shell/chat_shell_terminal_test.dart`: 26 passed,
|
||||
0 failed.
|
||||
- New in the first file: Ctrl+Tab and Ctrl+Shift+Tab over three floating chats
|
||||
cycle in open order, not stacking order (order, wrap, composer focus,
|
||||
Command+Tab ignored). With the tiling focused Ctrl+Tab goes to the top-most
|
||||
shown window and leaves the panes alone; with one shown window it does
|
||||
nothing; with the window minimised the panes cycle and the window stays
|
||||
hidden. With one tiled pane and a minimised chat, Ctrl+Tab does nothing and
|
||||
shows nothing. A terminal that claims tab keys keeps Ctrl+Tab over a focused
|
||||
chat window.
|
||||
- Removed: the single-pane recent-chat swap (the chat shown before, opened
|
||||
back into the pane), with its tests in `chat_keyboard_focus_test.dart`. A
|
||||
single pane with no shown window now does nothing on Ctrl+Tab, so
|
||||
`chat_control_tab_test.dart` no longer expects the composer to take focus
|
||||
from the sidebar.
|
||||
- Floating-window Ctrl+Tab and Ctrl+Shift+Tab over three floating chats cycle
|
||||
in open order, not stacking order (order, wrap, composer focus, Command+Tab
|
||||
ignored). With the tiling focused, a single tiled pane cycles the open,
|
||||
device-visible sidebar chats and skips closed, hidden and floating chats;
|
||||
multiple tiled panes cycle panes. A terminal that claims tab keys keeps
|
||||
Ctrl+Tab over a focused chat window.
|
||||
- Changed: a single tiled pane now cycles the open, device-visible sidebar
|
||||
chats in list order, skips closed, hidden-on-this-device and floating chats,
|
||||
wraps in both directions, and focuses the replacement composer. Multiple
|
||||
panes and focused floating windows retain their existing cycles.
|
||||
- `tool/analyze.sh` on `lib/features/chat` and the three chat test files:
|
||||
clean.
|
||||
- Affected states: two or more floating chats; one floating chat shown;
|
||||
floating chat minimised with one tiled pane; tiling focused with windows
|
||||
shown and with none; a window focused; the terminal shown (claimed);
|
||||
Command+Tab.
|
||||
- Affected states: a single tiled pane with open chats; shown or minimised
|
||||
floating chats; two or more tiled panes; a focused floating window; the
|
||||
terminal shown (claimed); Command+Tab.
|
||||
- Not covered: the terminal's own tab switching (the test app has no terminal
|
||||
surface), real browser or device keys, and captures (ui-review's).
|
||||
- Observed, not changed: in the widget harness, floating from a pane's More
|
||||
|
||||
@@ -12,12 +12,17 @@ import 'package:pipelines_app/shell/destination.dart';
|
||||
import 'conversation/chat_thread_fixtures.dart';
|
||||
|
||||
class _Gateway extends FakeChatGateway {
|
||||
_Gateway({this.rows = const ['a', 'b', 'c']});
|
||||
|
||||
final List<String> rows;
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
if (type == 'chat_sessions') {
|
||||
return Future.value({
|
||||
'chat_sessions': [
|
||||
for (final id in ['a', 'b', 'c']) {'id': id, 'title': 'Chat $id'},
|
||||
for (final id in rows)
|
||||
{'id': id, 'title': 'Chat $id', if (id == 'closed') 'closed_at': 1},
|
||||
],
|
||||
});
|
||||
}
|
||||
@@ -57,12 +62,16 @@ Future<void> _chord(
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> _setup(WidgetTester tester, {bool open = true}) async {
|
||||
Future<void> _setup(
|
||||
WidgetTester tester, {
|
||||
bool open = true,
|
||||
List<String> rows = const ['a', 'b', 'c'],
|
||||
}) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = const Size(1800, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
||||
final gateway = _Gateway(rows: rows)..history = (_) async => chatPage([]);
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
@@ -133,20 +142,44 @@ void main() {
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
testWidgets('single pane with no shown window does nothing; empty workspace '
|
||||
'does not consume', (tester) async {
|
||||
await _setup(tester, open: false);
|
||||
await _chord(tester);
|
||||
expect(find.byType(ChatWorkspace), findsNothing);
|
||||
testWidgets(
|
||||
'single pane cycles list chats; empty workspace does not consume',
|
||||
(tester) async {
|
||||
await _setup(tester, open: false);
|
||||
await _chord(tester);
|
||||
expect(find.byType(ChatWorkspace), findsNothing);
|
||||
await tester.tap(find.byKey(const Key('chat-row-a')));
|
||||
await tester.pumpAndSettle();
|
||||
_focusSidebar(tester);
|
||||
await tester.pumpAndSettle();
|
||||
await _chord(tester);
|
||||
expect(find.byType(ChatWorkspace), findsOneWidget);
|
||||
expect(_workspace(tester).paneCount, 1);
|
||||
expect(_workspace(tester).activePane?.sessionId, 'b');
|
||||
expect(_editable(tester, 'b').focusNode.hasPrimaryFocus, isTrue);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('single pane skips closed and hidden-on-this-device chats', (
|
||||
tester,
|
||||
) async {
|
||||
await _setup(tester, open: false, rows: ['a', 'hidden', 'c', 'closed']);
|
||||
await tester.tap(_actions('hidden'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Hide on this device'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-row-a')));
|
||||
await tester.pumpAndSettle();
|
||||
_focusSidebar(tester);
|
||||
await tester.pumpAndSettle();
|
||||
await _chord(tester);
|
||||
expect(find.byType(ChatWorkspace), findsOneWidget);
|
||||
expect(_workspace(tester).paneCount, 1);
|
||||
expect(_editable(tester, 'a').focusNode.hasPrimaryFocus, isFalse);
|
||||
expect(_editable(tester, 'a').controller.text, isEmpty);
|
||||
expect(_workspace(tester).activePane?.sessionId, 'c');
|
||||
await _chord(tester);
|
||||
expect(_workspace(tester).activePane?.sessionId, 'a');
|
||||
|
||||
await _chord(tester, reverse: true);
|
||||
expect(_workspace(tester).activePane?.sessionId, 'c');
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
|
||||
@@ -592,10 +592,8 @@ void main() {
|
||||
await app.stop(tester);
|
||||
});
|
||||
|
||||
testWidgets('with the tiling focused Ctrl+Tab goes to the top-most shown '
|
||||
'window, and cycles the panes only when no window is shown', (
|
||||
tester,
|
||||
) async {
|
||||
testWidgets('with the tiling focused Ctrl+Tab cycles the single pane chat '
|
||||
'list and cycles panes when there are multiple panes', (tester) async {
|
||||
await _saved('a', 'b', 'c');
|
||||
final app = _App(_Store());
|
||||
await app.start(tester);
|
||||
@@ -603,20 +601,20 @@ void main() {
|
||||
expect(app.floating, ['c']);
|
||||
final controller = _workspace(tester);
|
||||
|
||||
// A window is shown: from the tiling, Ctrl+Tab takes the keyboard to it
|
||||
// and the panes stay where they are.
|
||||
// A shown floating chat is skipped while the single tiled pane cycles the
|
||||
// remaining open chats.
|
||||
await tester.tapAt(tester.getCenter(_input('a')));
|
||||
await tester.pump();
|
||||
expect(controller.activePane?.sessionId, 'a');
|
||||
await _tab(tester);
|
||||
expect(controller.activePane?.sessionId, 'a');
|
||||
expect(_composerFocused(tester, 'c'), isTrue);
|
||||
expect(controller.activePane?.sessionId, 'b');
|
||||
expect(_composerFocused(tester, 'b'), isTrue);
|
||||
expect(app.floating, ['c']);
|
||||
|
||||
// A single shown window has nothing to cycle to.
|
||||
// It wraps back to the other non-floating chat.
|
||||
await _tab(tester);
|
||||
expect(controller.activePane?.sessionId, 'a');
|
||||
expect(_composerFocused(tester, 'c'), isTrue);
|
||||
expect(_composerFocused(tester, 'a'), isTrue);
|
||||
expect(app.floating, ['c']);
|
||||
|
||||
// No window shown: the panes cycle and the hidden window stays hidden.
|
||||
|
||||
@@ -150,28 +150,25 @@ void main() {
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
testWidgets('Control Tab over one pane does nothing: it never brings up '
|
||||
'another chat', (tester) async {
|
||||
testWidgets('Control Tab over one pane cycles the sidebar chats in both '
|
||||
'directions', (tester) async {
|
||||
await _setup(tester);
|
||||
await _openRow(tester, 'a');
|
||||
final workspace = _workspace(tester);
|
||||
await _controlTab(tester);
|
||||
expect(workspace.activePane?.sessionId, 'a');
|
||||
expect(_editable(tester, 'a').focusNode.hasPrimaryFocus, isFalse);
|
||||
|
||||
// Opening b replaces the lone pane; a is no longer shown anywhere.
|
||||
await _openRow(tester, 'b');
|
||||
await tester.enterText(_input('b'), 'Draft B');
|
||||
await _focusSidebar(tester);
|
||||
for (final shift in [false, true]) {
|
||||
await _controlTab(tester, shift: shift);
|
||||
expect(workspace.paneCount, 1);
|
||||
expect(workspace.activePane?.sessionId, 'b');
|
||||
expect(_editable(tester, 'b').focusNode.hasPrimaryFocus, isFalse);
|
||||
expect(_editable(tester, 'b').controller.text, 'Draft B');
|
||||
for (final id in ['b', 'c', 'a']) {
|
||||
await _controlTab(tester);
|
||||
expect(workspace.activePane?.sessionId, id);
|
||||
expect(_editable(tester, id).focusNode.hasPrimaryFocus, isTrue);
|
||||
}
|
||||
await _focusSidebar(tester);
|
||||
for (final id in ['c', 'b', 'a']) {
|
||||
await _controlTab(tester, shift: true);
|
||||
expect(workspace.activePane?.sessionId, id);
|
||||
expect(_editable(tester, id).focusNode.hasPrimaryFocus, isTrue);
|
||||
}
|
||||
|
||||
// Two panes cycle the panes, not the history.
|
||||
// Two panes still cycle panes, not the chat list.
|
||||
await _openRow(tester, 'c');
|
||||
await tester.tap(_actions('a'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
@@ -18,7 +18,7 @@ const _implemented = [
|
||||
'Stop a running chat',
|
||||
'Focus the neighbouring chat pane',
|
||||
'Move the active chat pane',
|
||||
'Cycle chat panes and floating chats',
|
||||
'Cycle chats and floating chat panes',
|
||||
'Resize panes with a focused divider',
|
||||
'Scroll a wide transcript block',
|
||||
'Show or hide floating chats',
|
||||
|
||||
Reference in New Issue
Block a user