12c7642e35
Ctrl+K lists open chats most recently used first (tracked on open and pane focus, persisted per server) and preselects the previous chat, so Ctrl+K, Enter returns to it. Rows mark needs you / working / unread; a query also lists matching closed chats under Closed, and choosing one reopens it. Alt+N (Option+N) starts a new chat and Alt+J (Option+J) opens the next chat waiting for you, unread or failed, cycling; the terminal keeps both. In run detail, bare 1-4 switch tabs when not typing. Cheatsheet entries added. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
120 lines
4.2 KiB
Dart
120 lines
4.2 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter/services.dart';
|
||
import 'package:flutter_test/flutter_test.dart';
|
||
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||
import 'package:pipelines_app/shell/destination.dart';
|
||
import 'package:pipelines_app/shell/shell_chat_actions_shortcut.dart';
|
||
import 'package:pipelines_app/ui/input/keyboard_owner.dart';
|
||
|
||
KeyDownEvent _down(PhysicalKeyboardKey physical, LogicalKeyboardKey logical) =>
|
||
KeyDownEvent(
|
||
physicalKey: physical,
|
||
logicalKey: logical,
|
||
timeStamp: Duration.zero,
|
||
);
|
||
|
||
final _n = _down(PhysicalKeyboardKey.keyN, LogicalKeyboardKey.keyN);
|
||
final _j = _down(PhysicalKeyboardKey.keyJ, LogicalKeyboardKey.keyJ);
|
||
|
||
Future<void> _alt(WidgetTester tester, LogicalKeyboardKey key) async {
|
||
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
|
||
await tester.sendKeyEvent(key);
|
||
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
|
||
await tester.pump();
|
||
}
|
||
|
||
void main() {
|
||
test('Alt+N is New chat and Alt+J the next chat needing you, alone', () {
|
||
ShellChatAction? chord(Set<LogicalKeyboardKey> held, KeyEvent event) =>
|
||
shellChatActionShortcut(event, _FakeKeyboard(held));
|
||
const alt = LogicalKeyboardKey.altLeft;
|
||
expect(chord({alt}, _n), ShellChatAction.newChat);
|
||
expect(chord({alt}, _j), ShellChatAction.nextAttention);
|
||
expect(chord({}, _n), isNull);
|
||
expect(chord({alt, LogicalKeyboardKey.shiftLeft}, _n), isNull);
|
||
expect(chord({alt, LogicalKeyboardKey.controlLeft}, _j), isNull);
|
||
expect(chord({alt, LogicalKeyboardKey.metaLeft}, _j), isNull);
|
||
expect(chord({LogicalKeyboardKey.controlLeft}, _n), isNull);
|
||
// Option+N is a dead key (˜) on a Mac: matched by position.
|
||
final dead = _down(
|
||
PhysicalKeyboardKey.keyN,
|
||
const LogicalKeyboardKey(0x02dc),
|
||
);
|
||
expect(chord({alt}, dead), ShellChatAction.newChat);
|
||
expect(
|
||
shellChatActionLabel(ShellChatAction.newChat, TargetPlatform.macOS),
|
||
'Option+N',
|
||
);
|
||
expect(
|
||
shellChatActionLabel(ShellChatAction.nextAttention, TargetPlatform.linux),
|
||
'Alt+J',
|
||
);
|
||
});
|
||
|
||
testWidgets('the chords show Chat and report the action; the terminal '
|
||
'keeps them', (tester) async {
|
||
final terminal = FocusNode();
|
||
addTearDown(terminal.dispose);
|
||
final actions = <ShellChatAction>[];
|
||
await tester.pumpWidget(
|
||
MaterialApp(
|
||
home: AdaptiveShell(
|
||
onChatAction: actions.add,
|
||
destinationBodies: {
|
||
AppDestination.pipelines: (_) => TypingSurface(
|
||
child: Focus(focusNode: terminal, child: const Text('terminal')),
|
||
),
|
||
AppDestination.chat: (_) => const Text('chat body'),
|
||
},
|
||
),
|
||
),
|
||
);
|
||
terminal.requestFocus();
|
||
await tester.pump();
|
||
await _alt(tester, LogicalKeyboardKey.keyN);
|
||
expect(actions, isEmpty);
|
||
expect(find.text('chat body'), findsNothing);
|
||
|
||
terminal.unfocus();
|
||
await tester.pump();
|
||
await _alt(tester, LogicalKeyboardKey.keyJ);
|
||
expect(actions, [ShellChatAction.nextAttention]);
|
||
expect(find.text('chat body'), isOnstage);
|
||
await _alt(tester, LogicalKeyboardKey.keyN);
|
||
expect(actions, [ShellChatAction.nextAttention, ShellChatAction.newChat]);
|
||
});
|
||
|
||
testWidgets('a dialog keeps the chords', (tester) async {
|
||
final actions = <ShellChatAction>[];
|
||
await tester.pumpWidget(
|
||
MaterialApp(
|
||
home: AdaptiveShell(
|
||
onChatAction: actions.add,
|
||
destinationBodies: {
|
||
AppDestination.pipelines: (context) => TextButton(
|
||
onPressed: () => showDialog<void>(
|
||
context: context,
|
||
builder: (_) =>
|
||
const AlertDialog(content: TextField(autofocus: true)),
|
||
),
|
||
child: const Text('dialog'),
|
||
),
|
||
AppDestination.chat: (_) => const Text('chat body'),
|
||
},
|
||
),
|
||
),
|
||
);
|
||
await tester.tap(find.text('dialog'));
|
||
await tester.pumpAndSettle();
|
||
await _alt(tester, LogicalKeyboardKey.keyN);
|
||
expect(actions, isEmpty);
|
||
});
|
||
}
|
||
|
||
class _FakeKeyboard extends HardwareKeyboard {
|
||
_FakeKeyboard(this.pressed);
|
||
final Set<LogicalKeyboardKey> pressed;
|
||
@override
|
||
bool isLogicalKeyPressed(LogicalKeyboardKey key) => pressed.contains(key);
|
||
}
|