c5af000453
- Desktop and web terminals use the text-input path too, so IMEs, dead keys, the emoji picker and dictation work; the key handler still encodes special keys and chords first (handled keys are never typed again), composing text is drawn at the cursor and sent on commit, the platform editable sits at the cursor, and a closed input reopens on the next key. The editable terminal is a semantics text field so web typing also works with semantics on. - Web: "Capture browser keys" (terminal menu and right-click menu) goes full screen and calls navigator.keyboard.lock(); hold Esc to leave. No-op where unsupported; cheatsheet and menu note give alternatives. - Touch: scrollable key row with sticky Ctrl/Alt (tap once, double-tap lock), Esc, Tab, arrows, Home/End, PgUp/PgDn and symbols through the hardware encoder; soft keyboard types per key (delete detection, Return as Enter); the line field moves behind the row's Line button. - Capture kit: compose=, --semantics false, --user-agent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
155 lines
5.3 KiB
Dart
155 lines
5.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/terminal/terminal_browser_keys.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_tab_strip.dart';
|
|
|
|
import '../chat/shell/terminal_view_harness.dart';
|
|
import 'terminal_fixtures.dart';
|
|
|
|
/// A browser's Keyboard Lock, recorded.
|
|
class FakeBrowserKeys implements TerminalBrowserKeysBackend {
|
|
FakeBrowserKeys({this.supported = true, this.grant = true});
|
|
|
|
@override
|
|
final bool supported;
|
|
final bool grant;
|
|
int locks = 0;
|
|
int unlocks = 0;
|
|
void Function()? released;
|
|
|
|
@override
|
|
Future<bool> lock() async {
|
|
locks++;
|
|
return grant;
|
|
}
|
|
|
|
@override
|
|
Future<void> unlock() async => unlocks++;
|
|
|
|
@override
|
|
set onReleased(void Function() callback) => released = callback;
|
|
}
|
|
|
|
void main() {
|
|
final original = TerminalBrowserKeys.instance;
|
|
tearDown(() => TerminalBrowserKeys.instance = original);
|
|
|
|
test('capture locks the keys until released by the app or the browser '
|
|
'(Esc held)', () async {
|
|
final backend = FakeBrowserKeys();
|
|
final keys = TerminalBrowserKeys(backend: backend);
|
|
expect(keys.supported, isTrue);
|
|
expect(await keys.capture(), isTrue);
|
|
expect(keys.active, isTrue);
|
|
expect(terminalBrowserKeysLabel(keys), 'Release browser keys');
|
|
await keys.release();
|
|
expect((keys.active, backend.unlocks), (false, 1));
|
|
await keys.capture();
|
|
backend.released!();
|
|
expect(keys.active, isFalse);
|
|
expect(terminalBrowserKeysLabel(keys), 'Capture browser keys');
|
|
});
|
|
|
|
test('a refused lock or an unsupported browser leaves it off', () async {
|
|
final refused = TerminalBrowserKeys(backend: FakeBrowserKeys(grant: false));
|
|
expect(await refused.capture(), isFalse);
|
|
expect(refused.active, isFalse);
|
|
final none = FakeBrowserKeys(supported: false);
|
|
final unsupported = TerminalBrowserKeys(backend: none);
|
|
expect(await unsupported.capture(), isFalse);
|
|
expect(none.locks, 0);
|
|
});
|
|
|
|
test('native builds (and tests) have nothing to capture', () {
|
|
expect(TerminalBrowserKeys().supported, isFalse);
|
|
});
|
|
|
|
Future<void> pumpStrip(WidgetTester tester) async {
|
|
final hub = TerminalHub(TestMachines([]));
|
|
addTearDown(hub.dispose);
|
|
final layout = TerminalLayout(store: MemoryLayoutStore());
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: TerminalTabStrip(hub: hub, layout: layout),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
const item = ValueKey('terminal-browser-keys');
|
|
|
|
testWidgets('the terminal menu offers Capture browser keys where the '
|
|
'browser can, checked while on', (tester) async {
|
|
final backend = FakeBrowserKeys();
|
|
TerminalBrowserKeys.instance = TerminalBrowserKeys(backend: backend);
|
|
await pumpStrip(tester);
|
|
await tester.tap(find.byTooltip('Terminal options'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(item), findsOneWidget);
|
|
expect(
|
|
tester.widget<CheckedPopupMenuItem<Object?>>(find.byKey(item)).checked,
|
|
isFalse,
|
|
);
|
|
await tester.tap(find.byKey(item));
|
|
await tester.pumpAndSettle();
|
|
expect(backend.locks, 1);
|
|
expect(find.textContaining('Hold Esc'), findsOneWidget);
|
|
await tester.tap(find.byTooltip('Terminal options'));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester.widget<CheckedPopupMenuItem<Object?>>(find.byKey(item)).checked,
|
|
isTrue,
|
|
);
|
|
await tester.tap(find.byKey(item));
|
|
await tester.pumpAndSettle();
|
|
expect(backend.unlocks, 1);
|
|
expect(TerminalBrowserKeys.instance.active, isFalse);
|
|
});
|
|
|
|
testWidgets('no such item where the browser cannot capture its keys', (
|
|
tester,
|
|
) async {
|
|
TerminalBrowserKeys.instance = TerminalBrowserKeys(
|
|
backend: FakeBrowserKeys(supported: false),
|
|
);
|
|
await pumpStrip(tester);
|
|
await tester.tap(find.byTooltip('Terminal options'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(item), findsNothing);
|
|
expect(find.byKey(const ValueKey('terminal-hide')), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('a refused capture says so', (tester) async {
|
|
TerminalBrowserKeys.instance = TerminalBrowserKeys(
|
|
backend: FakeBrowserKeys(grant: false),
|
|
);
|
|
await pumpStrip(tester);
|
|
await tester.tap(find.byTooltip('Terminal options'));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.byKey(item));
|
|
await tester.pumpAndSettle();
|
|
expect(find.textContaining('did not let the page'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets("the chat terminal's right-click menu has it too", (
|
|
tester,
|
|
) async {
|
|
final backend = FakeBrowserKeys();
|
|
TerminalBrowserKeys.instance = TerminalBrowserKeys(backend: backend);
|
|
final harness = TerminalViewHarness();
|
|
await harness.pump(tester);
|
|
await harness.rightClick(tester, 1, 0);
|
|
final menuItem = find.byKey(const ValueKey('terminal-menu-browserKeys'));
|
|
expect(menuItem, findsOneWidget);
|
|
expect(find.text('Capture browser keys'), findsOneWidget);
|
|
await tester.tap(menuItem);
|
|
await tester.pumpAndSettle();
|
|
expect(backend.locks, 1);
|
|
await harness.rightClick(tester, 1, 0);
|
|
expect(find.text('Release browser keys'), findsOneWidget);
|
|
}, variant: desktops);
|
|
}
|