Reserve global shortcuts for chat selection and search
This commit is contained in:
@@ -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);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user