Files
pipelines/app/test/features/chat/shell/terminal_typing.dart
T
alan c5af000453 Terminal: text input for IMEs, Capture browser keys, touch key row
- 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>
2026-11-26 02:43:57 +00:00

60 lines
2.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
/// Commits [text] through the platform text input, as an IME, dead key,
/// the emoji picker, dictation or a soft keyboard does: appended to what
/// the focused client last told the platform, the caret at its end.
Future<void> commitText(WidgetTester tester, String text) async {
final before = '${tester.testTextInput.editingState?['text'] ?? ''}';
final value = '$before$text';
tester.testTextInput.updateEditingValue(
TextEditingValue(
text: value,
selection: TextSelection.collapsed(offset: value.length),
),
);
await tester.pump();
}
/// Sends [text] as composing (marked) text: drawn, not yet committed.
Future<void> composeText(WidgetTester tester, String text) async {
final before = '${tester.testTextInput.editingState?['text'] ?? ''}';
final value = '$before$text';
tester.testTextInput.updateEditingValue(
TextEditingValue(
text: value,
selection: TextSelection.collapsed(offset: value.length),
composing: TextRange(start: before.length, end: value.length),
),
);
await tester.pump();
}
/// Presses [key] as a desktop platform does: the key event first, and only
/// if no handler took it, its [character] (default: the key's label in
/// lower case) through the text input. A key the terminal encoded is never
/// typed a second time.
Future<void> typeKey(
WidgetTester tester,
LogicalKeyboardKey key, {
String? character,
}) async {
final handled = await tester.sendKeyEvent(key, character: character);
if (!handled) {
final text = character ?? key.keyLabel.toLowerCase();
if (text.isNotEmpty) await commitText(tester, text);
}
await tester.pump();
}
/// Taps the key toolbar's key [id] (`chat-shell-key-<id>`), scrolling the
/// touch key row to it first.
Future<void> tapKey(WidgetTester tester, String id) async {
final key = find.byKey(Key('chat-shell-key-$id'));
await tester.ensureVisible(key);
await tester.pump();
await tester.tap(key);
await tester.pump();
}