Reserve global shortcuts for chat selection and search

This commit is contained in:
2026-11-06 17:58:12 +00:00
parent 51ee950a5b
commit f668e1eef8
12 changed files with 412 additions and 172 deletions
+74 -72
View File
@@ -9,81 +9,83 @@ void main() {
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('$host Ctrl+Tab changes destinations and wraps from the ends', (
tester,
) async {
final app = AdaptiveShell(
cupertino: cupertino,
destinationBodies: {
for (final destination in shellTabDestinations)
destination: (_) => Focus(
autofocus: destination == AppDestination.pipelines,
child: Text(destination.name),
),
},
);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: app) : MaterialApp(home: app),
);
testWidgets(
'$host Ctrl+Tab and Ctrl+Shift+Tab leave destinations unchanged',
(tester) async {
final app = AdaptiveShell(
cupertino: cupertino,
destinationBodies: {
for (final destination in shellTabDestinations)
destination: (_) => Focus(
autofocus: destination == AppDestination.pipelines,
child: Text(destination.name),
),
},
);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: app) : MaterialApp(home: app),
);
Future<void> press({required bool shift}) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
if (shift) await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
Future<void> press({required bool shift}) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
if (shift)
await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
if (shift) await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pump();
}
expect(find.text('pipelines'), findsOneWidget);
await press(shift: true);
expect(find.text('pipelines'), findsOneWidget);
await press(shift: false);
expect(find.text('pipelines'), findsOneWidget);
},
);
testWidgets(
'$host plain Tab traverses and Ctrl+Tab does not change destinations',
(tester) async {
final first = FocusNode();
final second = FocusNode();
addTearDown(first.dispose);
addTearDown(second.dispose);
final app = AdaptiveShell(
cupertino: cupertino,
destinationBodies: {
AppDestination.pipelines: (_) => Column(
children: [
cupertino
? CupertinoTextField(focusNode: first)
: TextField(focusNode: first),
cupertino
? CupertinoTextField(focusNode: second)
: TextField(focusNode: second),
],
),
AppDestination.runs: (_) => const Text('runs'),
},
);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: app) : MaterialApp(home: app),
);
first.requestFocus();
await tester.pump();
// Plain Tab retains normal traversal semantics and does not select a tab.
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.pump();
expect(second.hasFocus, isTrue);
first.requestFocus();
await tester.pump();
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
if (shift) await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pump();
}
expect(find.text('pipelines'), findsOneWidget);
await press(shift: true);
expect(find.text('search'), findsOneWidget);
await press(shift: false);
expect(find.text('pipelines'), findsOneWidget);
});
testWidgets('$host Ctrl+Tab works in a text field and plain Tab traverses', (
tester,
) async {
final first = FocusNode();
final second = FocusNode();
addTearDown(first.dispose);
addTearDown(second.dispose);
final app = AdaptiveShell(
cupertino: cupertino,
destinationBodies: {
AppDestination.pipelines: (_) => Column(
children: [
cupertino
? CupertinoTextField(focusNode: first)
: TextField(focusNode: first),
cupertino
? CupertinoTextField(focusNode: second)
: TextField(focusNode: second),
],
),
AppDestination.runs: (_) => const Text('runs'),
},
);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: app) : MaterialApp(home: app),
);
first.requestFocus();
await tester.pump();
// Plain Tab retains normal traversal semantics and does not select a tab.
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.pump();
expect(second.hasFocus, isTrue);
first.requestFocus();
await tester.pump();
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pump();
expect(find.text('runs'), findsOneWidget);
expect(first.hasFocus, isFalse);
});
expect(find.text('runs'), findsNothing);
},
);
}
}
+72 -57
View File
@@ -51,65 +51,80 @@ void main() {
});
}
testWidgets('Ctrl+1…9 reach only the open tab\'s list; other chords pass', (
tester,
) async {
final opened = <(AppDestination, int)>[];
final field = FocusNode();
addTearDown(field.dispose);
Widget list(AppDestination destination) => ShellListShortcut(
onOpenIndex: (index) {
if (index > 4) return false;
opened.add((destination, index));
return true;
},
child: TextField(focusNode: field),
);
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destination: AppDestination.runs,
destinationBodies: {
AppDestination.runs: (_) => list(AppDestination.runs),
AppDestination.pipelines: (_) => list(AppDestination.pipelines),
},
testWidgets(
'Ctrl+1…9 select chat rows only; other destinations and chords pass',
(tester) async {
final opened = <(AppDestination, int)>[];
final field = FocusNode();
addTearDown(field.dispose);
Widget list(AppDestination destination) => ShellListShortcut(
onOpenIndex: (index) {
if (index > 4) return false;
opened.add((destination, index));
return true;
},
child: destination == AppDestination.runs
? TextField(focusNode: field)
: const SizedBox.shrink(),
);
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destination: AppDestination.runs,
destinationBodies: {
AppDestination.runs: (_) => list(AppDestination.runs),
AppDestination.pipelines: (_) => list(AppDestination.pipelines),
AppDestination.chat: (_) => list(AppDestination.chat),
},
),
),
),
);
await tester.pumpAndSettle();
field.requestFocus();
await tester.pump();
Future<void> press(
LogicalKeyboardKey key, {
List<LogicalKeyboardKey> held = const [LogicalKeyboardKey.controlLeft],
}) async {
for (final modifier in held) {
await tester.sendKeyDownEvent(modifier);
}
await tester.sendKeyEvent(key);
for (final modifier in held.reversed) {
await tester.sendKeyUpEvent(modifier);
}
);
await tester.pumpAndSettle();
field.requestFocus();
await tester.pump();
}
await press(LogicalKeyboardKey.digit1);
await press(LogicalKeyboardKey.digit5);
expect(opened, [(AppDestination.runs, 0), (AppDestination.runs, 4)]);
Future<void> press(
LogicalKeyboardKey key, {
List<LogicalKeyboardKey> held = const [LogicalKeyboardKey.controlLeft],
}) async {
for (final modifier in held) {
await tester.sendKeyDownEvent(modifier);
}
await tester.sendKeyEvent(key);
for (final modifier in held.reversed) {
await tester.sendKeyUpEvent(modifier);
}
await tester.pump();
}
opened.clear();
await press(
LogicalKeyboardKey.digit2,
held: [LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.shiftLeft],
);
await press(
LogicalKeyboardKey.digit2,
held: [LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.metaLeft],
);
await press(LogicalKeyboardKey.digit2, held: const []);
await press(LogicalKeyboardKey.digit0);
expect(opened, isEmpty);
expect(field.hasFocus, isTrue);
});
await press(LogicalKeyboardKey.digit1);
await press(LogicalKeyboardKey.digit5);
expect(opened, isEmpty);
await tester.tap(
find.byKey(const ValueKey('shell.destination.pipelines')),
);
await tester.pumpAndSettle();
await press(LogicalKeyboardKey.digit1);
expect(opened, isEmpty);
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
await tester.pumpAndSettle();
await press(LogicalKeyboardKey.digit1);
await press(LogicalKeyboardKey.digit5);
expect(opened, [(AppDestination.chat, 0), (AppDestination.chat, 4)]);
opened.clear();
await press(
LogicalKeyboardKey.digit2,
held: [LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.shiftLeft],
);
await press(
LogicalKeyboardKey.digit2,
held: [LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.metaLeft],
);
await press(LogicalKeyboardKey.digit2, held: const []);
await press(LogicalKeyboardKey.digit0);
expect(opened, isEmpty);
expect(opened, isEmpty);
},
);
}
+132
View File
@@ -0,0 +1,132 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/search/search_screen.dart';
import 'package:pipelines_app/features/search/ui/search_bar_controls.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/shell_list_shortcuts.dart';
class _Gateway implements ApiGateway {
@override
Stream<JsonMap> get frames => const Stream.empty();
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async => {
'search_results': {'results': [], 'truncated': false},
};
}
Future<void> _chord(
WidgetTester tester,
List<LogicalKeyboardKey> modifiers,
LogicalKeyboardKey key,
) async {
for (final modifier in modifiers) {
await tester.sendKeyDownEvent(modifier);
}
await tester.sendKeyEvent(key);
for (final modifier in modifiers.reversed) {
await tester.sendKeyUpEvent(modifier);
}
await tester.pumpAndSettle();
}
void main() {
for (final platform in [TargetPlatform.macOS, TargetPlatform.windows]) {
testWidgets('Search accepts exact primary slash on $platform', (
tester,
) async {
final results = <bool>[];
bool handler(KeyEvent event) {
if (event is KeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.slash) {
results.add(
shellSearchShortcut(
event,
HardwareKeyboard.instance,
platform: platform,
),
);
}
return false;
}
HardwareKeyboard.instance.addHandler(handler);
addTearDown(() => HardwareKeyboard.instance.removeHandler(handler));
for (final modifiers in [
[LogicalKeyboardKey.controlLeft],
[LogicalKeyboardKey.metaLeft],
[LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.shiftLeft],
[LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.altLeft],
[LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.metaLeft],
<LogicalKeyboardKey>[],
]) {
await _chord(tester, modifiers, LogicalKeyboardKey.slash);
}
expect(results, [
true,
platform == TargetPlatform.macOS,
false,
false,
false,
false,
]);
});
}
for (final platform in [TargetPlatform.macOS, TargetPlatform.windows]) {
testWidgets(
'Search chord opens and refocuses retained query on $platform',
(tester) async {
final composer = TextEditingController(text: 'draft remains');
final focus = FocusNode();
addTearDown(composer.dispose);
addTearDown(focus.dispose);
await tester.pumpWidget(
MaterialApp(
// The theme deliberately disagrees with the actual macOS host.
theme: ThemeData(platform: TargetPlatform.android),
home: AdaptiveShell(
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) =>
TextField(controller: composer, focusNode: focus),
AppDestination.search: (_) => SearchScreen(
gateway: _Gateway(),
onOpen: (_) {},
embedded: true,
),
},
),
),
);
await tester.pumpAndSettle();
focus.requestFocus();
await tester.pump();
final primary = platform == TargetPlatform.macOS
? LogicalKeyboardKey.metaLeft
: LogicalKeyboardKey.controlLeft;
await _chord(tester, [primary], LogicalKeyboardKey.slash);
var search = tester.widget<TextField>(find.byKey(searchFieldKey));
expect(search.focusNode!.hasFocus, isTrue);
expect(composer.text, 'draft remains');
await tester.enterText(find.byKey(searchFieldKey), 'release');
await tester.pumpAndSettle(const Duration(milliseconds: 300));
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
await tester.pumpAndSettle();
focus.requestFocus();
await tester.pump();
await _chord(tester, [primary], LogicalKeyboardKey.slash);
search = tester.widget<TextField>(find.byKey(searchFieldKey));
expect(search.controller!.text, 'release');
expect(search.focusNode!.hasFocus, isTrue);
search.focusNode!.unfocus();
await tester.pump();
await _chord(tester, [primary], LogicalKeyboardKey.slash);
expect(search.focusNode!.hasFocus, isTrue);
},
variant: TargetPlatformVariant.only(platform),
);
}
}
+5 -3
View File
@@ -99,7 +99,9 @@ void main() {
expect(exits, ['SystemNavigator.pop']);
});
testWidgets('Ctrl+Tab tab changes are part of the history', (tester) async {
testWidgets('Ctrl+Tab no longer switches destinations or changes history', (
tester,
) async {
final exits = _recordExits(tester);
await tester.pumpWidget(
MaterialApp(home: AdaptiveShell(destinationBodies: _bodies())),
@@ -108,11 +110,11 @@ void main() {
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pumpAndSettle();
_expectShown(AppDestination.runs);
_expectShown(AppDestination.pipelines);
await _back(tester);
_expectShown(AppDestination.pipelines);
expect(exits, isEmpty);
expect(exits, ['SystemNavigator.pop']);
});
testWidgets('a page open in the tab closes before Back changes tabs', (