30934aa71c
Alt+T, Ctrl+T and Cmd+T join Ctrl+` as early focus-manager key handlers, so they toggle the panel, window or narrow page from anywhere without reaching the shell or a text field. Opening with no terminal starts one. The shown terminal takes the keyboard (also on reload and tab changes) and hiding gives it back. The panel slides from the bottom edge as the app shrinks, the window scales and fades, both on Motion.standard and off under reduced motion. While shown, Ctrl+Tab/Ctrl+Shift+Tab move between terminal tabs instead of chat panes. The tooltip and menu list the shortcuts the platform delivers.
106 lines
3.2 KiB
Dart
106 lines
3.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_view.dart';
|
|
import 'package:pipelines_app/features/terminal/terminal_hub.dart';
|
|
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
|
|
import 'package:pipelines_app/features/terminal/terminal_surface.dart';
|
|
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
|
|
|
|
const appField = Key('app-field');
|
|
|
|
/// An app with a text field under the terminal surface, [size] logical
|
|
/// pixels, optionally asking for reduced motion.
|
|
Future<void> pumpTerminalApp(
|
|
WidgetTester tester, {
|
|
required TerminalHub hub,
|
|
required TerminalLayout layout,
|
|
Size size = const Size(1200, 800),
|
|
bool reduceMotion = false,
|
|
}) async {
|
|
tester.view.physicalSize = size;
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
builder: (context, child) => MediaQuery(
|
|
data: MediaQuery.of(context).copyWith(disableAnimations: reduceMotion),
|
|
child: child!,
|
|
),
|
|
home: TerminalSurface(
|
|
hub: hub,
|
|
layout: layout,
|
|
cupertino: false,
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('App'),
|
|
actions: [TerminalToggleButton(layout: layout, cupertino: false)],
|
|
),
|
|
body: const TextField(key: appField),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
}
|
|
|
|
/// Presses [key] with [modifiers] held, then lets the motion finish unless
|
|
/// [settle] is false.
|
|
Future<void> chord(
|
|
WidgetTester tester,
|
|
LogicalKeyboardKey key,
|
|
List<LogicalKeyboardKey> modifiers, {
|
|
bool settle = true,
|
|
}) async {
|
|
for (final modifier in modifiers) {
|
|
await tester.sendKeyDownEvent(modifier);
|
|
}
|
|
await tester.sendKeyEvent(key);
|
|
for (final modifier in modifiers.reversed) {
|
|
await tester.sendKeyUpEvent(modifier);
|
|
}
|
|
if (settle) {
|
|
await tester.pumpAndSettle();
|
|
} else {
|
|
await tester.pump();
|
|
}
|
|
}
|
|
|
|
Future<void> altT(WidgetTester tester, {bool settle = true}) => chord(
|
|
tester,
|
|
LogicalKeyboardKey.keyT,
|
|
[LogicalKeyboardKey.altLeft],
|
|
settle: settle,
|
|
);
|
|
|
|
Future<void> ctrlTab(WidgetTester tester, {bool reverse = false}) => chord(
|
|
tester,
|
|
LogicalKeyboardKey.tab,
|
|
[LogicalKeyboardKey.controlLeft, if (reverse) LogicalKeyboardKey.shiftLeft],
|
|
);
|
|
|
|
/// The terminal whose emulator has the keyboard, or null.
|
|
ChatShellTerminalView? focusedTerminal() => FocusManager
|
|
.instance
|
|
.primaryFocus
|
|
?.context
|
|
?.findAncestorWidgetOfExactType<ChatShellTerminalView>();
|
|
|
|
/// Whether [tab]'s emulator has the keyboard.
|
|
bool terminalFocused(String key) =>
|
|
focusedTerminal()?.key == ValueKey('terminal-view-$key');
|
|
|
|
/// Whether the app's text field has the keyboard.
|
|
bool appFieldFocused(WidgetTester tester) => tester
|
|
.widget<EditableText>(
|
|
find.descendant(
|
|
of: find.byKey(appField),
|
|
matching: find.byType(EditableText),
|
|
),
|
|
)
|
|
.focusNode
|
|
.hasFocus;
|
|
|
|
final Finder panelFinder = find.byKey(const ValueKey('terminal-panel'));
|
|
final Finder floatFinder = find.byKey(const ValueKey('terminal-float'));
|