Chat: Ctrl+1-9 puts the keyboard in the opened chat's composer

A chat opened from the keyboard asks its composer for focus; the composer
takes it after the frame it is built in (new detail pane or phone page), or
at once when that chat is already open. Taps and other opens cancel the
request, so they keep focus where it was. The capture kit's press step
accepts modifier chords such as Control+2.
This commit is contained in:
2026-11-03 12:42:28 +00:00
parent d34185b56c
commit d6f636a325
7 changed files with 209 additions and 8 deletions
@@ -82,6 +82,20 @@ Future<void> _ctrl(WidgetTester tester, LogicalKeyboardKey digit) async {
Finder _thread(String id) => find.byKey(ValueKey('chat-thread-$id'));
EditableText _composer(WidgetTester tester, String id) =>
tester.widget<EditableText>(
find.descendant(
of: find.byKey(ValueKey('chat-composer-$id')),
matching: find.byType(EditableText),
),
);
bool _composerFocused(WidgetTester tester, String id) =>
_composer(tester, id).focusNode.hasPrimaryFocus;
String _composerText(WidgetTester tester, String id) =>
_composer(tester, id).controller.text;
void main() {
testWidgets('starred chats lead the list alphabetically', (tester) async {
await _pumpShell(tester, const Size(1280, 800));
@@ -122,6 +136,51 @@ void main() {
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('Ctrl+N puts the keyboard in the opened chat\'s composer', (
tester,
) async {
await _pumpShell(tester, const Size(1280, 800));
// A tap opens a chat without moving focus into its composer.
await tester.tap(find.byKey(const Key('chat-row-r')));
await tester.pumpAndSettle();
expect(_thread('r'), findsOneWidget);
expect(_composerFocused(tester, 'r'), isFalse);
// From the keyboard another chat opens with its composer focused, and
// typing lands there at once.
await _ctrl(tester, LogicalKeyboardKey.digit2);
expect(_thread('z'), findsOneWidget);
expect(_composerFocused(tester, 'z'), isTrue);
// The text connection the focused field opened receives the typing.
tester.testTextInput.enterText('h');
await tester.pump();
expect(_composerText(tester, 'z'), 'h');
// The chat already open: focus returns from elsewhere to its composer.
FocusManager.instance.primaryFocus?.unfocus();
await tester.pump();
expect(_composerFocused(tester, 'z'), isFalse);
await _ctrl(tester, LogicalKeyboardKey.digit2);
expect(_composerFocused(tester, 'z'), isTrue);
// A later tap on another row leaves focus alone.
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
expect(_thread('a'), findsOneWidget);
expect(_composerFocused(tester, 'a'), isFalse);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('Ctrl+N focuses the composer of the chat page on a phone', (
tester,
) async {
await _pumpShell(tester, const Size(390, 844));
await _ctrl(tester, LogicalKeyboardKey.digit3);
expect(_thread('r'), findsOneWidget);
expect(_composerFocused(tester, 'r'), isTrue);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('Ctrl+N opens the chat as its own page on a phone', (
tester,
) async {