Reserve global shortcuts for chat selection and search
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
import '../../core/api_gateway.dart';
|
import '../../core/api_gateway.dart';
|
||||||
import '../../shell/shell_bar.dart';
|
import '../../shell/shell_bar.dart';
|
||||||
|
import '../../shell/shell_search_focus.dart';
|
||||||
import '../../ui/adaptive/host.dart';
|
import '../../ui/adaptive/host.dart';
|
||||||
import '../../ui/adaptive/segmented_bar.dart';
|
import '../../ui/adaptive/segmented_bar.dart';
|
||||||
import 'data/search_repository.dart';
|
import 'data/search_repository.dart';
|
||||||
@@ -44,6 +45,7 @@ class SearchScreen extends StatefulWidget {
|
|||||||
class _SearchScreenState extends State<SearchScreen> {
|
class _SearchScreenState extends State<SearchScreen> {
|
||||||
late final OmniSearchController _controller;
|
late final OmniSearchController _controller;
|
||||||
late final TextEditingController _text;
|
late final TextEditingController _text;
|
||||||
|
final FocusNode _focus = FocusNode(debugLabel: 'omni-search');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -76,11 +78,15 @@ class _SearchScreenState extends State<SearchScreen> {
|
|||||||
_controller.removeListener(_onState);
|
_controller.removeListener(_onState);
|
||||||
_controller.dispose();
|
_controller.dispose();
|
||||||
_text.dispose();
|
_text.dispose();
|
||||||
|
_focus.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) =>
|
||||||
|
ShellSearchShortcut(onFocus: _focus.requestFocus, child: _build(context));
|
||||||
|
|
||||||
|
Widget _build(BuildContext context) {
|
||||||
// Follow the actual host app class: Cupertino only under an explicit
|
// Follow the actual host app class: Cupertino only under an explicit
|
||||||
// Cupertino host, Material on every platform otherwise.
|
// Cupertino host, Material on every platform otherwise.
|
||||||
final cupertino = widget.cupertino ?? usesCupertinoHost(context);
|
final cupertino = widget.cupertino ?? usesCupertinoHost(context);
|
||||||
@@ -112,6 +118,7 @@ class _SearchScreenState extends State<SearchScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _controls(bool cupertino) => SearchBarControls(
|
Widget _controls(bool cupertino) => SearchBarControls(
|
||||||
|
focusNode: _focus,
|
||||||
cupertino: cupertino,
|
cupertino: cupertino,
|
||||||
text: _text,
|
text: _text,
|
||||||
kind: _controller.parsed.kind,
|
kind: _controller.parsed.kind,
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class SearchBarControls extends StatelessWidget {
|
|||||||
required this.onCleared,
|
required this.onCleared,
|
||||||
required this.onKind,
|
required this.onKind,
|
||||||
this.autofocus = true,
|
this.autofocus = true,
|
||||||
|
this.focusNode,
|
||||||
});
|
});
|
||||||
|
|
||||||
final bool cupertino;
|
final bool cupertino;
|
||||||
@@ -39,6 +40,7 @@ class SearchBarControls extends StatelessWidget {
|
|||||||
final VoidCallback onCleared;
|
final VoidCallback onCleared;
|
||||||
final ValueChanged<SearchKind> onKind;
|
final ValueChanged<SearchKind> onKind;
|
||||||
final bool autofocus;
|
final bool autofocus;
|
||||||
|
final FocusNode? focusNode;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// The pill grows with the bar, so the field and the results share both
|
// The pill grows with the bar, so the field and the results share both
|
||||||
@@ -55,6 +57,7 @@ class SearchBarControls extends StatelessWidget {
|
|||||||
clearKey: const ValueKey('search.clear'),
|
clearKey: const ValueKey('search.clear'),
|
||||||
controller: text,
|
controller: text,
|
||||||
autofocus: autofocus,
|
autofocus: autofocus,
|
||||||
|
focusNode: focusNode,
|
||||||
inBar: true,
|
inBar: true,
|
||||||
cupertino: cupertino,
|
cupertino: cupertino,
|
||||||
placeholder: 'Search pipelines, runs, artifacts and chats',
|
placeholder: 'Search pipelines, runs, artifacts and chats',
|
||||||
|
|||||||
@@ -273,34 +273,24 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
|||||||
if (previous != null) _select(previous);
|
if (previous != null) _select(previous);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles this before focused text controls can insert or traverse on
|
/// App-wide search and conversation-list selection are handled before text
|
||||||
/// Ctrl+Tab. The handler is scoped to the shell's lifetime, not onboarding.
|
/// fields. Split-pane navigation belongs to the chat workspace; tab changes
|
||||||
///
|
/// have no global keyboard chord.
|
||||||
/// Ctrl+1…Ctrl+9 open the Nth item of the open tab's list the same way, in
|
|
||||||
/// the list's on-screen order; a page (Settings) has no list.
|
|
||||||
bool _handleDestinationKeyEvent(KeyEvent event) {
|
bool _handleDestinationKeyEvent(KeyEvent event) {
|
||||||
final listIndex = shellListShortcutIndex(
|
final keyboard = HardwareKeyboard.instance;
|
||||||
event,
|
if (shellSearchShortcut(event, keyboard)) {
|
||||||
HardwareKeyboard.instance,
|
_select(AppDestination.search);
|
||||||
);
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
if (listIndex != null) {
|
if (mounted && _selected == AppDestination.search) {
|
||||||
if (!shellTabDestinations.contains(_selected)) return false;
|
_bar.searchFocus.request();
|
||||||
return _bar.lists.open(_selected, listIndex);
|
}
|
||||||
|
});
|
||||||
|
WidgetsBinding.instance.ensureVisualUpdate();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (event is! KeyDownEvent ||
|
final listIndex = shellListShortcutIndex(event, keyboard);
|
||||||
event.logicalKey != LogicalKeyboardKey.tab ||
|
if (listIndex == null || _selected != AppDestination.chat) return false;
|
||||||
!HardwareKeyboard.instance.isControlPressed) {
|
return _bar.lists.open(AppDestination.chat, listIndex);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final current = shellTabDestinations.indexOf(shellTabFor(_selected));
|
|
||||||
final direction = HardwareKeyboard.instance.isShiftPressed ? -1 : 1;
|
|
||||||
final next = (current + direction) % shellTabDestinations.length;
|
|
||||||
_select(
|
|
||||||
shellTabDestinations[next < 0
|
|
||||||
? next + shellTabDestinations.length
|
|
||||||
: next],
|
|
||||||
);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<FloatingDestinationItem> _destinationItems() =>
|
List<FloatingDestinationItem> _destinationItems() =>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/widgets.dart';
|
|||||||
|
|
||||||
import 'destination.dart';
|
import 'destination.dart';
|
||||||
import 'shell_list_shortcuts.dart';
|
import 'shell_list_shortcuts.dart';
|
||||||
|
import 'shell_search_focus.dart';
|
||||||
|
|
||||||
/// What the open screen of a tab puts in the app bar: its title, a Back
|
/// What the open screen of a tab puts in the app bar: its title, a Back
|
||||||
/// control and its actions. Absent, the bar shows the tab's own name.
|
/// control and its actions. Absent, the bar shows the tab's own name.
|
||||||
@@ -66,9 +67,11 @@ class ShellBarRegistry extends ChangeNotifier {
|
|||||||
final _Notifier _bar = _Notifier();
|
final _Notifier _bar = _Notifier();
|
||||||
final _Notifier _badgeNotifier = _Notifier();
|
final _Notifier _badgeNotifier = _Notifier();
|
||||||
|
|
||||||
/// How each tab's list opens its Nth item (Ctrl+1…Ctrl+9).
|
/// Registered list openers; keyboard shortcuts invoke Chat only.
|
||||||
final ShellListShortcuts lists = ShellListShortcuts();
|
final ShellListShortcuts lists = ShellListShortcuts();
|
||||||
|
|
||||||
|
final ShellSearchFocus searchFocus = ShellSearchFocus();
|
||||||
|
|
||||||
/// The destination whose bar is on screen; null treats every destination
|
/// The destination whose bar is on screen; null treats every destination
|
||||||
/// as shown. Bar changes of other destinations are kept without notifying:
|
/// as shown. Bar changes of other destinations are kept without notifying:
|
||||||
/// the host rebuilds when it changes the focus.
|
/// the host rebuilds when it changes the focus.
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import 'package:flutter/widgets.dart';
|
|||||||
import 'destination.dart';
|
import 'destination.dart';
|
||||||
import 'shell_bar.dart';
|
import 'shell_bar.dart';
|
||||||
|
|
||||||
/// Opens the Nth item of a tab's list: what each tab's list screen published
|
/// List openers registered by destination. The shell invokes only Chat for
|
||||||
/// for Ctrl+1…Ctrl+9 (also Command on macOS). One opener per tab;
|
/// Ctrl+1…Ctrl+9 (also Command on macOS); Pipelines and Runs have no chord.
|
||||||
/// the latest mounted list wins.
|
/// One opener per destination; the latest mounted list wins.
|
||||||
class ShellListShortcuts {
|
class ShellListShortcuts {
|
||||||
final Map<AppDestination, (Object, bool Function(int index))> _openers = {};
|
final Map<AppDestination, (Object, bool Function(int index))> _openers = {};
|
||||||
|
|
||||||
@@ -34,13 +34,8 @@ int? shellListShortcutIndex(
|
|||||||
HardwareKeyboard keyboard, {
|
HardwareKeyboard keyboard, {
|
||||||
TargetPlatform? platform,
|
TargetPlatform? platform,
|
||||||
}) {
|
}) {
|
||||||
final control = keyboard.isControlPressed && !keyboard.isMetaPressed;
|
|
||||||
final command =
|
|
||||||
(platform ?? defaultTargetPlatform) == TargetPlatform.macOS &&
|
|
||||||
keyboard.isMetaPressed &&
|
|
||||||
!keyboard.isControlPressed;
|
|
||||||
if (event is! KeyDownEvent ||
|
if (event is! KeyDownEvent ||
|
||||||
!(control || command) ||
|
!shellPrimaryModifier(keyboard, platform: platform) ||
|
||||||
keyboard.isShiftPressed ||
|
keyboard.isShiftPressed ||
|
||||||
keyboard.isAltPressed) {
|
keyboard.isAltPressed) {
|
||||||
return null;
|
return null;
|
||||||
@@ -49,6 +44,28 @@ int? shellListShortcutIndex(
|
|||||||
return index < 0 ? null : index;
|
return index < 0 ? null : index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Ctrl on any host, or Command on the actual macOS host. Theme overrides do
|
||||||
|
/// not change keyboard conventions in a browser.
|
||||||
|
bool shellPrimaryModifier(
|
||||||
|
HardwareKeyboard keyboard, {
|
||||||
|
TargetPlatform? platform,
|
||||||
|
}) =>
|
||||||
|
(keyboard.isControlPressed && !keyboard.isMetaPressed) ||
|
||||||
|
((platform ?? defaultTargetPlatform) == TargetPlatform.macOS &&
|
||||||
|
keyboard.isMetaPressed &&
|
||||||
|
!keyboard.isControlPressed);
|
||||||
|
|
||||||
|
bool shellSearchShortcut(
|
||||||
|
KeyEvent event,
|
||||||
|
HardwareKeyboard keyboard, {
|
||||||
|
TargetPlatform? platform,
|
||||||
|
}) =>
|
||||||
|
event is KeyDownEvent &&
|
||||||
|
event.logicalKey == LogicalKeyboardKey.slash &&
|
||||||
|
shellPrimaryModifier(keyboard, platform: platform) &&
|
||||||
|
!keyboard.isAltPressed &&
|
||||||
|
!keyboard.isShiftPressed;
|
||||||
|
|
||||||
const _digits = [
|
const _digits = [
|
||||||
LogicalKeyboardKey.digit1,
|
LogicalKeyboardKey.digit1,
|
||||||
LogicalKeyboardKey.digit2,
|
LogicalKeyboardKey.digit2,
|
||||||
@@ -62,8 +79,8 @@ const _digits = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
/// Publishes, while mounted, how its tab's list opens its Nth item, so the
|
/// Publishes, while mounted, how its tab's list opens its Nth item, so the
|
||||||
/// shell's Ctrl+1…Ctrl+9 open it from anywhere in the tab (also while a text
|
/// shell can open an item without coupling to its screen (also while a text
|
||||||
/// field has focus). [onOpenIndex] reads the list at key time, in on-screen
|
/// field has focus). Keyboard dispatch currently invokes only Chat. [onOpenIndex] reads the list at key time, in on-screen
|
||||||
/// order, and reports whether an item was opened. Outside a shell it does
|
/// order, and reports whether an item was opened. Outside a shell it does
|
||||||
/// nothing.
|
/// nothing.
|
||||||
class ShellListShortcut extends StatefulWidget {
|
class ShellListShortcut extends StatefulWidget {
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
|
import 'destination.dart';
|
||||||
|
import 'shell_bar.dart';
|
||||||
|
|
||||||
|
/// The mounted Search screen publishes its field focus without clearing query
|
||||||
|
/// state. The shell requests it after switching destinations has settled.
|
||||||
|
class ShellSearchFocus {
|
||||||
|
Object? _owner;
|
||||||
|
VoidCallback? _focus;
|
||||||
|
void request() => _focus?.call();
|
||||||
|
|
||||||
|
void _set(Object owner, VoidCallback focus) {
|
||||||
|
_owner = owner;
|
||||||
|
_focus = focus;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _clear(Object owner) {
|
||||||
|
if (_owner != owner) return;
|
||||||
|
_owner = null;
|
||||||
|
_focus = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ShellSearchShortcut extends StatefulWidget {
|
||||||
|
const ShellSearchShortcut({
|
||||||
|
super.key,
|
||||||
|
required this.onFocus,
|
||||||
|
required this.child,
|
||||||
|
});
|
||||||
|
final VoidCallback onFocus;
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ShellSearchShortcut> createState() => _ShellSearchShortcutState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ShellSearchShortcutState extends State<ShellSearchShortcut> {
|
||||||
|
final _owner = Object();
|
||||||
|
ShellBarScope? _scope;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
final scope = ShellBarScope.maybeOf(context);
|
||||||
|
if (scope == _scope) return;
|
||||||
|
_scope?.registry.searchFocus._clear(_owner);
|
||||||
|
_scope = scope;
|
||||||
|
if (scope?.destination == AppDestination.search) {
|
||||||
|
scope!.registry.searchFocus._set(_owner, () => widget.onFocus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_scope?.registry.searchFocus._clear(_owner);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => widget.child;
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ import 'destination.dart';
|
|||||||
|
|
||||||
/// The tabs the operator left, most recent first, for the system Back.
|
/// The tabs the operator left, most recent first, for the system Back.
|
||||||
///
|
///
|
||||||
/// Every tab change (a tap, Ctrl+Tab, a search result or notification opening
|
/// Every tab change (a tap, a search result or notification opening
|
||||||
/// another tab) goes through [record]: the tab being left moves to the top
|
/// another tab) goes through [record]: the tab being left moves to the top
|
||||||
/// and the tab being opened leaves the stack, so each tab appears at most once
|
/// and the tab being opened leaves the stack, so each tab appears at most once
|
||||||
/// and the current tab is never in it. A page that belongs to a tab
|
/// and the current tab is never in it. A page that belongs to a tab
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# Chat workspace keyboard remapping
|
||||||
|
|
||||||
|
Ctrl+/ opens the persistent Search tab and focuses its existing field. On the actual macOS host Command+/ does the same, even when web Material theme advertises Android. Repeating the chord refocuses Search without resetting its query or filter. The search screen owns and disposes its field FocusNode and publishes a scoped callback to the shell; the callback is requested after the destination transition rebuild.
|
||||||
|
|
||||||
|
Ctrl+1…9 and macOS Command+1…9 still choose conversation rows, in the visible list order. Pipelines and Runs no longer receive digit shortcuts. Ctrl+Tab and Ctrl+Shift+Tab no longer switch destinations; workspace pane navigation is handled separately. Extra Shift/Alt or combined Ctrl+Command modifiers pass through for both Search and digit selection. No socket or backend changes.
|
||||||
|
|
||||||
|
Checks: bounded analysis clean. 188 shell/Search tests passed through the memory watchdog (peak1713MB,14s). Tests cover exact modifiers on macOS/Windows, actual SearchScreen focus from a composer, repeat/revisit retaining query, Android-theme/macOS-host mismatch, chat-only digits, unchanged destination/history for removed chords, and normal Tab traversal. Browser interaction for the full split workspace is recorded by the parent integration task; this lane has no visual layout change.
|
||||||
@@ -9,81 +9,83 @@ void main() {
|
|||||||
for (final cupertino in [false, true]) {
|
for (final cupertino in [false, true]) {
|
||||||
final host = cupertino ? 'Cupertino' : 'Material';
|
final host = cupertino ? 'Cupertino' : 'Material';
|
||||||
|
|
||||||
testWidgets('$host Ctrl+Tab changes destinations and wraps from the ends', (
|
testWidgets(
|
||||||
tester,
|
'$host Ctrl+Tab and Ctrl+Shift+Tab leave destinations unchanged',
|
||||||
) async {
|
(tester) async {
|
||||||
final app = AdaptiveShell(
|
final app = AdaptiveShell(
|
||||||
cupertino: cupertino,
|
cupertino: cupertino,
|
||||||
destinationBodies: {
|
destinationBodies: {
|
||||||
for (final destination in shellTabDestinations)
|
for (final destination in shellTabDestinations)
|
||||||
destination: (_) => Focus(
|
destination: (_) => Focus(
|
||||||
autofocus: destination == AppDestination.pipelines,
|
autofocus: destination == AppDestination.pipelines,
|
||||||
child: Text(destination.name),
|
child: Text(destination.name),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
cupertino ? CupertinoApp(home: app) : MaterialApp(home: app),
|
cupertino ? CupertinoApp(home: app) : MaterialApp(home: app),
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<void> press({required bool shift}) async {
|
Future<void> press({required bool shift}) async {
|
||||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||||
if (shift) await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
|
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);
|
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||||
if (shift) await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
|
|
||||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
}
|
expect(find.text('runs'), findsNothing);
|
||||||
|
},
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,65 +51,80 @@ void main() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
testWidgets('Ctrl+1…9 reach only the open tab\'s list; other chords pass', (
|
testWidgets(
|
||||||
tester,
|
'Ctrl+1…9 select chat rows only; other destinations and chords pass',
|
||||||
) async {
|
(tester) async {
|
||||||
final opened = <(AppDestination, int)>[];
|
final opened = <(AppDestination, int)>[];
|
||||||
final field = FocusNode();
|
final field = FocusNode();
|
||||||
addTearDown(field.dispose);
|
addTearDown(field.dispose);
|
||||||
Widget list(AppDestination destination) => ShellListShortcut(
|
Widget list(AppDestination destination) => ShellListShortcut(
|
||||||
onOpenIndex: (index) {
|
onOpenIndex: (index) {
|
||||||
if (index > 4) return false;
|
if (index > 4) return false;
|
||||||
opened.add((destination, index));
|
opened.add((destination, index));
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
child: TextField(focusNode: field),
|
child: destination == AppDestination.runs
|
||||||
);
|
? TextField(focusNode: field)
|
||||||
await tester.pumpWidget(
|
: const SizedBox.shrink(),
|
||||||
MaterialApp(
|
);
|
||||||
home: AdaptiveShell(
|
await tester.pumpWidget(
|
||||||
destination: AppDestination.runs,
|
MaterialApp(
|
||||||
destinationBodies: {
|
home: AdaptiveShell(
|
||||||
AppDestination.runs: (_) => list(AppDestination.runs),
|
destination: AppDestination.runs,
|
||||||
AppDestination.pipelines: (_) => list(AppDestination.pipelines),
|
destinationBodies: {
|
||||||
},
|
AppDestination.runs: (_) => list(AppDestination.runs),
|
||||||
|
AppDestination.pipelines: (_) => list(AppDestination.pipelines),
|
||||||
|
AppDestination.chat: (_) => list(AppDestination.chat),
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
);
|
await tester.pumpAndSettle();
|
||||||
await tester.pumpAndSettle();
|
field.requestFocus();
|
||||||
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.pump();
|
await tester.pump();
|
||||||
}
|
|
||||||
|
|
||||||
await press(LogicalKeyboardKey.digit1);
|
Future<void> press(
|
||||||
await press(LogicalKeyboardKey.digit5);
|
LogicalKeyboardKey key, {
|
||||||
expect(opened, [(AppDestination.runs, 0), (AppDestination.runs, 4)]);
|
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.digit1);
|
||||||
await press(
|
await press(LogicalKeyboardKey.digit5);
|
||||||
LogicalKeyboardKey.digit2,
|
expect(opened, isEmpty);
|
||||||
held: [LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.shiftLeft],
|
await tester.tap(
|
||||||
);
|
find.byKey(const ValueKey('shell.destination.pipelines')),
|
||||||
await press(
|
);
|
||||||
LogicalKeyboardKey.digit2,
|
await tester.pumpAndSettle();
|
||||||
held: [LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.metaLeft],
|
await press(LogicalKeyboardKey.digit1);
|
||||||
);
|
expect(opened, isEmpty);
|
||||||
await press(LogicalKeyboardKey.digit2, held: const []);
|
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
|
||||||
await press(LogicalKeyboardKey.digit0);
|
await tester.pumpAndSettle();
|
||||||
expect(opened, isEmpty);
|
await press(LogicalKeyboardKey.digit1);
|
||||||
expect(field.hasFocus, isTrue);
|
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);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -99,7 +99,9 @@ void main() {
|
|||||||
expect(exits, ['SystemNavigator.pop']);
|
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);
|
final exits = _recordExits(tester);
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
MaterialApp(home: AdaptiveShell(destinationBodies: _bodies())),
|
MaterialApp(home: AdaptiveShell(destinationBodies: _bodies())),
|
||||||
@@ -108,11 +110,11 @@ void main() {
|
|||||||
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
_expectShown(AppDestination.runs);
|
_expectShown(AppDestination.pipelines);
|
||||||
|
|
||||||
await _back(tester);
|
await _back(tester);
|
||||||
_expectShown(AppDestination.pipelines);
|
_expectShown(AppDestination.pipelines);
|
||||||
expect(exits, isEmpty);
|
expect(exits, ['SystemNavigator.pop']);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('a page open in the tab closes before Back changes tabs', (
|
testWidgets('a page open in the tab closes before Back changes tabs', (
|
||||||
|
|||||||
Reference in New Issue
Block a user