Close menus with Escape and keep a window's popups focused
AppMenuAnchor is the app's one MenuAnchor: root overlay, takes the keyboard while open (Escape and arrows work wherever focus was) and gives it back. A window no longer takes the keyboard back from a popup its own press opened. In a window, Files opens as a page of that window and Chat details is in the More menu.
This commit is contained in:
@@ -7,6 +7,8 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_manager.dart';
|
||||
|
||||
import 'package:pipelines_app/ui/motion/surface_visibility.dart';
|
||||
|
||||
import 'window_test_harness.dart';
|
||||
|
||||
/// Layering acceptance (docs/plans/floating-windows.md, Phase 1.4): every
|
||||
@@ -210,6 +212,31 @@ void main() {
|
||||
expect(find.text('Sheet item').hitTestable(), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a popup opened by the press that focuses its window keeps the '
|
||||
'keyboard', (tester) async {
|
||||
await open(tester, 0);
|
||||
// The keyboard is in the app behind, as after using another tab.
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(const ValueKey('b-sheet')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Sheet item').hitTestable(), findsOneWidget);
|
||||
final focus = FocusManager.instance.primaryFocus!.context!;
|
||||
expect(ModalRoute.of(focus), isA<PopupRoute<void>>());
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Sheet item'), findsNothing);
|
||||
// The window content is not the current surface under a popup.
|
||||
await tester.tap(find.byKey(const ValueKey('b-dialog')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
SurfaceVisibility.currentOf(
|
||||
tester.element(find.byKey(const ValueKey('content-b'))),
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Escape closes the popup, not the window', (tester) async {
|
||||
await open(tester, 0);
|
||||
await tester.tap(find.byKey(const ValueKey('a-dialog')));
|
||||
|
||||
@@ -3,23 +3,20 @@ import 'dart:io';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
/// Window content takes input only inside its window (see `WindowNavigator`),
|
||||
/// so a `MenuAnchor` panel, which may extend past the window, must be in the
|
||||
/// root overlay. Any content can end up in a window, so every `MenuAnchor` in
|
||||
/// the app opts in.
|
||||
/// so a menu panel, which may extend past the window, must be in the root
|
||||
/// overlay. Any content can end up in a window, so the app's menus are all
|
||||
/// `AppMenuAnchor`, the one place a `MenuAnchor` is built.
|
||||
void main() {
|
||||
test('every MenuAnchor targets the root overlay', () {
|
||||
test('MenuAnchor is used only through AppMenuAnchor', () {
|
||||
final offenders = <String>[];
|
||||
for (final file in Directory('lib').listSync(recursive: true)) {
|
||||
if (file is! File || !file.path.endsWith('.dart')) continue;
|
||||
if (file.path.endsWith('ui/adaptive/app_menu_anchor.dart')) continue;
|
||||
final source = file.readAsStringSync();
|
||||
for (final match in RegExp(r'\bMenuAnchor\(').allMatches(source)) {
|
||||
final end = (match.end + 400).clamp(0, source.length);
|
||||
if (!source
|
||||
.substring(match.end, end)
|
||||
.contains('useRootOverlay: true')) {
|
||||
final line = '\n'.allMatches(source.substring(0, match.start)).length;
|
||||
offenders.add('${file.path}:${line + 1}');
|
||||
}
|
||||
if (match.start > 0 && source[match.start - 1] == 'p') continue;
|
||||
final line = '\n'.allMatches(source.substring(0, match.start)).length;
|
||||
offenders.add('${file.path}:${line + 1}');
|
||||
}
|
||||
}
|
||||
expect(offenders, isEmpty);
|
||||
|
||||
Reference in New Issue
Block a user