Animate chat composer while turns run
Replace the running Stop button with an animated composer border and task spinner. Add Escape, slash-command, and touch-menu stopping paths with focused widget coverage, including reduced-motion behavior.
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||
import '../../../core/api_gateway.dart';
|
||||
import 'chat_background_tasks_controller.dart';
|
||||
import 'chat_background_tasks_dialog.dart';
|
||||
import 'chat_task_spinner.dart';
|
||||
|
||||
/// Compact live task count: a quiet control inside the composer beside Send,
|
||||
/// shown only while tasks run. Details live only in its modal.
|
||||
@@ -146,10 +147,13 @@ class _ChatBackgroundTasksState extends State<ChatBackgroundTasks> {
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
onPressed: _open,
|
||||
icon: Icon(
|
||||
automationOnly ? Icons.schedule : Icons.layers_outlined,
|
||||
size: 16,
|
||||
),
|
||||
// The layers turn only while a task runs; automations stay still.
|
||||
icon: automationOnly
|
||||
? const Icon(Icons.schedule, size: 16)
|
||||
: ChatTaskSpinner(
|
||||
spinning: count > 0,
|
||||
child: const Icon(Icons.layers_outlined, size: 16),
|
||||
),
|
||||
label: caption(),
|
||||
);
|
||||
return Padding(
|
||||
|
||||
@@ -5,7 +5,6 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/scale/ui_scale.dart';
|
||||
import '../../../ui/motion/surface_visibility.dart';
|
||||
import 'chat_stop_icon.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
@@ -30,6 +29,7 @@ import 'composer_focus_request.dart';
|
||||
import 'composer_focus_restore.dart';
|
||||
import 'chat_bar_tint.dart';
|
||||
import 'composer_focus_ring.dart';
|
||||
import 'composer_running_border.dart';
|
||||
import '../shell/chat_shell_command.dart';
|
||||
import '../shell/chat_shell_mode_indicator.dart';
|
||||
|
||||
@@ -70,8 +70,10 @@ double chatComposerBottomMargin([TargetPlatform? platform]) =>
|
||||
? kChatComposerDesktopBottomMargin
|
||||
: kChatComposerBottomMargin;
|
||||
|
||||
/// The single primary control's words while a turn is and is not running.
|
||||
/// The single primary control's words.
|
||||
const String chatSendLabel = 'Send';
|
||||
|
||||
/// The chat's More-menu word for stopping a running turn.
|
||||
const String chatStopLabel = 'Stop';
|
||||
|
||||
/// The primary control's words while the draft is a `!` shell command.
|
||||
@@ -95,7 +97,8 @@ const String chatQueuedNotice =
|
||||
'Queued — it will send when the current turn finishes.';
|
||||
|
||||
/// The foot of one conversation: a native multiline field and Send control,
|
||||
/// with a separate Stop while a turn runs, driven by [ChatComposerController].
|
||||
/// driven by [ChatComposerController]. A running turn shows a travelling
|
||||
/// border, not a stop control.
|
||||
///
|
||||
/// The field owns only its [TextEditingController] and focus; the durable draft
|
||||
/// text lives in the composer controller, so a live transcript rebuild never
|
||||
@@ -153,7 +156,7 @@ class ChatComposerBar extends StatefulWidget {
|
||||
/// session (null) keeps those commands on the unavailable report.
|
||||
final ChatCommandActions? commands;
|
||||
|
||||
/// The thread controller's running bit; shows Stop without hiding Send.
|
||||
/// The thread controller's running bit; shows the running border.
|
||||
final bool running;
|
||||
|
||||
/// The host picker seam; production uses [hostChatAttachmentPicker].
|
||||
@@ -400,6 +403,13 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Whether a send completes the palette's highlighted row instead of running
|
||||
/// the draft. A draft that already names a whole command (`/stop`) runs on
|
||||
/// the first send; only a partial word is completed first.
|
||||
bool _paletteCompletes() =>
|
||||
_paletteCommands().isNotEmpty &&
|
||||
chatCommandNamed(widget.composer.draft) == null;
|
||||
|
||||
/// The recorded commands matching the current draft while the palette is
|
||||
/// open. A dismissed or completed draft keeps its palette closed until the
|
||||
/// operator types something newer.
|
||||
@@ -512,8 +522,8 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
(keyboard.isShiftPressed || keyboard.isAltPressed)) {
|
||||
return;
|
||||
}
|
||||
final commands = _paletteCommands();
|
||||
if (commands.isNotEmpty) {
|
||||
if (_paletteCompletes()) {
|
||||
final commands = _paletteCommands();
|
||||
_completeCommand(commands[_selectedCommand % commands.length]);
|
||||
return;
|
||||
}
|
||||
@@ -943,10 +953,6 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
),
|
||||
child: widget.backgroundTasks!,
|
||||
),
|
||||
if (widget.running) ...[
|
||||
_primary(context, stop: true),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
_primary(context),
|
||||
],
|
||||
),
|
||||
@@ -973,21 +979,41 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
/// the transcript, so the composer reads as a single input rather than a
|
||||
/// row of separate controls, and the conversation shows through it. While
|
||||
/// the field has focus a ring in the chat's colour runs along its edge.
|
||||
Widget _pill(BuildContext context, Widget child) => ComposerFocusRing(
|
||||
focus: _focus,
|
||||
accent: chatFocusRingColor(context, widget.chatColor),
|
||||
shape: _pillShape,
|
||||
child: GlassPill(
|
||||
key: const Key('chat-composer-pill'),
|
||||
shape: _pillShape,
|
||||
// The end controls keep the same gap from the pill's sides as from
|
||||
// its bottom (and its top while the field is one line).
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(GlassBarMetrics.fieldEdgeGap),
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
);
|
||||
///
|
||||
/// While a turn runs a highlight travels around the same edge
|
||||
/// ([ComposerRunningBorder]); it is mounted only for that time.
|
||||
Widget _pill(BuildContext context, Widget child) {
|
||||
final accent = chatFocusRingColor(context, widget.chatColor);
|
||||
return Stack(
|
||||
children: [
|
||||
ComposerFocusRing(
|
||||
focus: _focus,
|
||||
accent: accent,
|
||||
shape: _pillShape,
|
||||
child: GlassPill(
|
||||
key: const Key('chat-composer-pill'),
|
||||
shape: _pillShape,
|
||||
// The end controls keep the same gap from the pill's sides as from
|
||||
// its bottom (and its top while the field is one line).
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(GlassBarMetrics.fieldEdgeGap),
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (widget.running)
|
||||
Positioned.fill(
|
||||
child: IgnorePointer(
|
||||
child: ComposerRunningBorder(
|
||||
shape: _pillShape,
|
||||
primary: accent,
|
||||
tertiary: Theme.of(context).colorScheme.tertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// The attach control: a host button that opens the picker, disabled when the
|
||||
/// host has no picker or one prompt is already awaiting its reply.
|
||||
@@ -1167,21 +1193,19 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _primary(BuildContext context, {bool stop = false}) {
|
||||
/// The single primary control: Send (or Run command for a `!` draft). A
|
||||
/// prompt sent while a turn runs takes the server's queued-prompt path; the
|
||||
/// running turn is stopped by Escape twice, `/stop`, or the More menu.
|
||||
Widget _primary(BuildContext context) {
|
||||
final composer = widget.composer;
|
||||
final enabled = stop
|
||||
? !composer.stopping
|
||||
: !_uploading &&
|
||||
!_shellStarting &&
|
||||
!composer.sending &&
|
||||
composer.draft.trim().isNotEmpty;
|
||||
final enabled =
|
||||
!_uploading &&
|
||||
!_shellStarting &&
|
||||
!composer.sending &&
|
||||
composer.draft.trim().isNotEmpty;
|
||||
void press() {
|
||||
if (stop) {
|
||||
unawaited(composer.stop());
|
||||
return;
|
||||
}
|
||||
final commands = _paletteCommands();
|
||||
if (commands.isNotEmpty) {
|
||||
if (_paletteCompletes()) {
|
||||
final commands = _paletteCommands();
|
||||
_completeCommand(commands[_selectedCommand % commands.length]);
|
||||
} else if (chatDraftIsShell(composer.draft)) {
|
||||
unawaited(_runShellDraft());
|
||||
@@ -1192,36 +1216,23 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
}
|
||||
}
|
||||
|
||||
// Sending while the turn runs uses the server's existing queued-prompt path.
|
||||
// Stopping is always a separate, explicitly named action.
|
||||
final label = stop
|
||||
? chatStopLabel
|
||||
: chatDraftIsShell(composer.draft)
|
||||
final label = chatDraftIsShell(composer.draft)
|
||||
? chatRunShellLabel
|
||||
: chatSendLabel;
|
||||
final key = Key(stop ? 'chat-composer-stop' : 'chat-composer-primary');
|
||||
// A coloured chat's send button takes the chat's colour (its seeded
|
||||
// primary, like the focus ring); stop stays the host's error red.
|
||||
// primary, like the focus ring).
|
||||
final tinted = chatSchemeOf(context, widget.chatColor);
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return IconButton.filled(
|
||||
key: key,
|
||||
key: const Key('chat-composer-primary'),
|
||||
tooltip: label,
|
||||
style: stop
|
||||
? IconButton.styleFrom(
|
||||
backgroundColor: scheme.error,
|
||||
foregroundColor: scheme.onError,
|
||||
)
|
||||
: tinted == null
|
||||
style: tinted == null
|
||||
? null
|
||||
: IconButton.styleFrom(
|
||||
backgroundColor: tinted.primary,
|
||||
foregroundColor: tinted.onPrimary,
|
||||
),
|
||||
onPressed: enabled ? press : null,
|
||||
icon: stop
|
||||
? const ChatStopIcon(child: Icon(Icons.stop))
|
||||
: const Icon(Icons.arrow_upward),
|
||||
icon: const Icon(Icons.arrow_upward),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// The longest gap between two Escape presses that still stops a running turn.
|
||||
const Duration chatEscapeStopWindow = Duration(seconds: 1);
|
||||
|
||||
/// The hint shown after the first Escape while a turn runs.
|
||||
const String chatEscapeStopHint = 'Press Esc again to stop';
|
||||
|
||||
/// Two presses of Escape stop a running turn: the first shows [chatEscapeStopHint]
|
||||
/// and the second, inside [chatEscapeStopWindow], stops it. Pure timing, so the
|
||||
/// clock is the caller's.
|
||||
class ChatEscapeStopTracker {
|
||||
DateTime? _firstAt;
|
||||
|
||||
/// Records one plain Escape press at [now]. Returns true when it completes a
|
||||
/// pair; a press that completes nothing starts a new pair.
|
||||
bool press(DateTime now) {
|
||||
final first = _firstAt;
|
||||
if (first != null && now.difference(first) <= chatEscapeStopWindow) {
|
||||
_firstAt = null;
|
||||
return true;
|
||||
}
|
||||
_firstAt = now;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Forgets a pending first press, for example once the turn has ended.
|
||||
void reset() => _firstAt = null;
|
||||
}
|
||||
|
||||
/// Lets two presses of Escape stop the turn while focus is anywhere inside
|
||||
/// [child] (the composer or the transcript). It only consumes Escape while
|
||||
/// [running]; an idle chat, and any Escape a descendant already handled (a
|
||||
/// command palette, a notice), pass through untouched.
|
||||
class ChatEscapeStop extends StatefulWidget {
|
||||
const ChatEscapeStop({
|
||||
super.key,
|
||||
required this.running,
|
||||
required this.onStop,
|
||||
required this.child,
|
||||
this.clock = DateTime.now,
|
||||
});
|
||||
|
||||
final bool running;
|
||||
|
||||
/// Stops the running turn; called on the second press.
|
||||
final VoidCallback onStop;
|
||||
|
||||
/// Injected time source, so tests control the window.
|
||||
final DateTime Function() clock;
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
State<ChatEscapeStop> createState() => _ChatEscapeStopState();
|
||||
}
|
||||
|
||||
class _ChatEscapeStopState extends State<ChatEscapeStop> {
|
||||
final ChatEscapeStopTracker _tracker = ChatEscapeStopTracker();
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant ChatEscapeStop oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (!widget.running) _tracker.reset();
|
||||
}
|
||||
|
||||
KeyEventResult _onKeyEvent(FocusNode node, KeyEvent event) {
|
||||
if (event.logicalKey != LogicalKeyboardKey.escape || !widget.running) {
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
final keyboard = HardwareKeyboard.instance;
|
||||
if (keyboard.isControlPressed ||
|
||||
keyboard.isMetaPressed ||
|
||||
keyboard.isShiftPressed ||
|
||||
keyboard.isAltPressed) {
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
// Holding Escape is one press, and releasing it is not a press at all.
|
||||
if (event is! KeyDownEvent) {
|
||||
return event is KeyRepeatEvent
|
||||
? KeyEventResult.handled
|
||||
: KeyEventResult.ignored;
|
||||
}
|
||||
if (_tracker.press(widget.clock())) {
|
||||
_tracker.reset();
|
||||
_hideHint();
|
||||
widget.onStop();
|
||||
} else {
|
||||
_showHint();
|
||||
}
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
|
||||
void _showHint() {
|
||||
final messenger = ScaffoldMessenger.maybeOf(context);
|
||||
if (messenger == null) return;
|
||||
messenger
|
||||
..hideCurrentSnackBar()
|
||||
..showSnackBar(
|
||||
const SnackBar(
|
||||
key: Key('chat-escape-stop-hint'),
|
||||
content: Text(chatEscapeStopHint),
|
||||
duration: chatEscapeStopWindow,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _hideHint() => ScaffoldMessenger.maybeOf(context)?.hideCurrentSnackBar();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Focus(
|
||||
canRequestFocus: false,
|
||||
skipTraversal: true,
|
||||
onKeyEvent: _onKeyEvent,
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// Slow, continuous progress motion confined to the Stop glyph. The native
|
||||
/// button, hit target and semantics never rotate. TickerMode pauses hidden UI.
|
||||
class ChatStopIcon extends StatefulWidget {
|
||||
const ChatStopIcon({super.key, required this.child});
|
||||
|
||||
final Widget child;
|
||||
static const period = Duration(seconds: 8);
|
||||
|
||||
@override
|
||||
State<ChatStopIcon> createState() => _ChatStopIconState();
|
||||
}
|
||||
|
||||
class _ChatStopIconState extends State<ChatStopIcon>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final _rotation = AnimationController(
|
||||
vsync: this,
|
||||
duration: ChatStopIcon.period,
|
||||
);
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
if (MediaQuery.maybeDisableAnimationsOf(context) ?? false) {
|
||||
_rotation.stop();
|
||||
_rotation.value = 0;
|
||||
} else if (!_rotation.isAnimating) {
|
||||
_rotation.repeat();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_rotation.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => RepaintBoundary(
|
||||
key: const Key('chat-stop-paint-boundary'),
|
||||
child: RotationTransition(
|
||||
key: const Key('chat-stop-rotation'),
|
||||
turns: _rotation,
|
||||
child: widget.child,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// Turns [child] once every [period] while [spinning]; static otherwise. With
|
||||
/// reduced motion it never turns. Hidden UI is silenced by TickerMode.
|
||||
class ChatTaskSpinner extends StatefulWidget {
|
||||
const ChatTaskSpinner({
|
||||
super.key,
|
||||
required this.spinning,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final bool spinning;
|
||||
final Widget child;
|
||||
|
||||
/// One full turn while tasks run.
|
||||
static const Duration period = Duration(milliseconds: 2500);
|
||||
|
||||
@override
|
||||
State<ChatTaskSpinner> createState() => _ChatTaskSpinnerState();
|
||||
}
|
||||
|
||||
class _ChatTaskSpinnerState extends State<ChatTaskSpinner>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _turns = AnimationController(
|
||||
vsync: this,
|
||||
duration: ChatTaskSpinner.period,
|
||||
);
|
||||
bool _reduced = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_sync();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_reduced = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
|
||||
_sync();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant ChatTaskSpinner oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
_sync();
|
||||
}
|
||||
|
||||
void _sync() {
|
||||
if (widget.spinning && !_reduced) {
|
||||
if (!_turns.isAnimating) _turns.repeat();
|
||||
} else {
|
||||
_turns
|
||||
..stop()
|
||||
..value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_turns.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => RotationTransition(
|
||||
key: const Key('chat-background-tasks-spinner'),
|
||||
turns: _turns,
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
@@ -42,6 +42,7 @@ import 'chat_background_tasks.dart';
|
||||
import 'chat_command_actions.dart';
|
||||
import 'chat_composer_bar.dart';
|
||||
import 'chat_composer_controller.dart';
|
||||
import 'chat_escape_stop.dart';
|
||||
import 'chat_delivery_indicator.dart';
|
||||
import 'chat_draft_store.dart';
|
||||
import 'chat_effort_control.dart';
|
||||
@@ -1383,7 +1384,13 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
// The bar and the jump control float over the transcript and the
|
||||
// composer sits below it; the wheel over them scrolls it, as a page
|
||||
// scrolls under fixed bars.
|
||||
final column = VerticalWheelForwarder(controller: _scroll, child: page);
|
||||
// Two Escape presses stop a running turn while the conversation has
|
||||
// the keyboard; the wheel over the page still scrolls it.
|
||||
final column = ChatEscapeStop(
|
||||
running: _controller.running,
|
||||
onStop: _stopTurn,
|
||||
child: VerticalWheelForwarder(controller: _scroll, child: page),
|
||||
);
|
||||
final wideFiles =
|
||||
_filesVisible && MediaQuery.sizeOf(context).width >= 700;
|
||||
_reportCenterStageFilesWidth();
|
||||
@@ -1479,6 +1486,15 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
],
|
||||
moreActions: [
|
||||
?widget.sidebarControl,
|
||||
// Touch devices have no Escape key; the menu is their way to stop.
|
||||
if (_controller.running)
|
||||
ChatBarAction(
|
||||
key: const Key('chat-thread-stop-menu'),
|
||||
label: chatStopLabel,
|
||||
identifier: 'chat-thread-stop',
|
||||
onPressed: _stopTurn,
|
||||
materialIcon: Icons.stop,
|
||||
),
|
||||
// A window's own title bar names the chat, and its narrow action
|
||||
// bar has no room for the title that opens the details.
|
||||
if (WindowScope.maybeOf(context) != null)
|
||||
@@ -1534,6 +1550,9 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
onChanged: widget.onModeChanged,
|
||||
);
|
||||
|
||||
/// Stops the running turn, as the composer's `/stop` does.
|
||||
void _stopTurn() => unawaited(_composer.stop());
|
||||
|
||||
void _runShellFromMenu() => unawaited(
|
||||
runChatShellFromMenu(context, _shellRuns, showNotice: _showCommandNotice),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// The composer's "agent is working" edge: a soft highlight that travels once
|
||||
/// around the pill's rounded border in [primary] and [tertiary], with a faint
|
||||
/// glow beneath it. Mount it only while a turn runs; disposing it stops the
|
||||
/// animation, so the border ends cleanly with the turn.
|
||||
///
|
||||
/// With reduced motion (the platform's disable-animations setting) it draws
|
||||
/// a static, evenly highlighted border instead and never ticks.
|
||||
class ComposerRunningBorder extends StatefulWidget {
|
||||
const ComposerRunningBorder({
|
||||
super.key,
|
||||
required this.shape,
|
||||
required this.primary,
|
||||
required this.tertiary,
|
||||
});
|
||||
|
||||
/// The pill's shape, so the highlight follows its edge.
|
||||
final OutlinedBorder shape;
|
||||
final Color primary;
|
||||
final Color tertiary;
|
||||
|
||||
/// One lap of the highlight around the border.
|
||||
static const Duration period = Duration(seconds: 4);
|
||||
|
||||
/// The stroke drawn just inside the pill's edge.
|
||||
static const double strokeWidth = 2;
|
||||
|
||||
/// The static border's opacity under reduced motion.
|
||||
static const double staticOpacity = 0.7;
|
||||
|
||||
@override
|
||||
State<ComposerRunningBorder> createState() => _ComposerRunningBorderState();
|
||||
}
|
||||
|
||||
class _ComposerRunningBorderState extends State<ComposerRunningBorder>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _lap = AnimationController(
|
||||
vsync: this,
|
||||
duration: ComposerRunningBorder.period,
|
||||
);
|
||||
bool _reduced = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_lap.repeat();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final reduced = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
|
||||
if (reduced == _reduced) return;
|
||||
_reduced = reduced;
|
||||
if (reduced) {
|
||||
_lap.stop();
|
||||
} else {
|
||||
_lap.repeat();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_lap.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => RepaintBoundary(
|
||||
key: const Key('chat-composer-running-border'),
|
||||
child: CustomPaint(
|
||||
painter: _RunningBorderPainter(
|
||||
shape: widget.shape,
|
||||
primary: widget.primary,
|
||||
tertiary: widget.tertiary,
|
||||
lap: _reduced ? null : _lap,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _RunningBorderPainter extends CustomPainter {
|
||||
_RunningBorderPainter({
|
||||
required this.shape,
|
||||
required this.primary,
|
||||
required this.tertiary,
|
||||
required this.lap,
|
||||
}) : super(repaint: lap);
|
||||
|
||||
final OutlinedBorder shape;
|
||||
final Color primary;
|
||||
final Color tertiary;
|
||||
|
||||
/// The lap's progress, or null for the static reduced-motion border.
|
||||
final Animation<double>? lap;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
if (size.isEmpty) return;
|
||||
const width = ComposerRunningBorder.strokeWidth;
|
||||
final rect = Offset.zero & size;
|
||||
final path = shape.getOuterPath(rect.deflate(width / 2));
|
||||
final glow = Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = width * 3
|
||||
..maskFilter = const MaskFilter.blur(BlurStyle.normal, 4);
|
||||
final line = Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = width;
|
||||
final progress = lap?.value;
|
||||
if (progress == null) {
|
||||
final solid = primary.withValues(
|
||||
alpha: ComposerRunningBorder.staticOpacity,
|
||||
);
|
||||
glow.color = solid.withValues(alpha: solid.a * .4);
|
||||
line.color = solid;
|
||||
} else {
|
||||
final shader = SweepGradient(
|
||||
colors: [
|
||||
primary.withValues(alpha: 0),
|
||||
primary,
|
||||
tertiary,
|
||||
tertiary.withValues(alpha: 0),
|
||||
primary.withValues(alpha: 0),
|
||||
],
|
||||
stops: const [0, .12, .24, .38, 1],
|
||||
transform: GradientRotation(progress * 2 * math.pi),
|
||||
).createShader(rect);
|
||||
glow.shader = shader;
|
||||
line.shader = shader;
|
||||
}
|
||||
canvas
|
||||
..drawPath(path, glow)
|
||||
..drawPath(path, line);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(_RunningBorderPainter oldDelegate) =>
|
||||
oldDelegate.shape != shape ||
|
||||
oldDelegate.primary != primary ||
|
||||
oldDelegate.tertiary != tertiary ||
|
||||
oldDelegate.lap != lap;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
# Composer running state: border, Escape stop, tasks spinner
|
||||
|
||||
## Changes
|
||||
|
||||
- **Stop button removed.** The composer no longer shows a Stop control while a
|
||||
turn runs; Send stays as before (queued/steered prompts unchanged).
|
||||
`chat_stop_icon.dart` and its test are deleted (their only user was the button).
|
||||
- **Running border.** `composer_running_border.dart` draws a sweep highlight
|
||||
(theme primary = chat focus accent, tertiary) once around the pill's rounded
|
||||
edge, 4 s per lap, with a faint blur glow. Mounted only while `running`, so
|
||||
disposal stops the ticker when the turn ends. Reduced motion
|
||||
(`MediaQuery.disableAnimations`) draws a static highlighted border and never ticks.
|
||||
- **Escape stop.** `chat_escape_stop.dart` wraps the conversation column in
|
||||
`chat_thread_view.dart`. Two plain Escape presses within 1 s stop a running turn
|
||||
(`composer.stop()`); the first shows the snackbar "Press Esc again to stop".
|
||||
Escape is consumed only while running; a descendant that handles Escape first
|
||||
(command palette, notice) never counts. Held Escape counts as one press.
|
||||
- **`/stop`.** Already existed (`chat_commands.dart`); unchanged. Typing `/stop`
|
||||
and sending runs it on the first send. A partial word (`/sto`) still
|
||||
completes the palette row first (`_paletteCompletes`).
|
||||
- **More menu Stop.** `chat_thread_view.dart` adds a `Stop` item to the header's
|
||||
More menu while a turn runs (`key chat-thread-stop-menu`). It is shown on every
|
||||
platform, so touch devices without a keyboard can stop.
|
||||
- **Tasks spinner.** `chat_task_spinner.dart` turns the layers icon once per
|
||||
2.5 s while at least one background task runs; static otherwise and under
|
||||
reduced motion. Automation-only state keeps its static schedule icon.
|
||||
|
||||
## Focused tests (memwatch, from app/)
|
||||
|
||||
| Run | Paths | Result |
|
||||
|---|---|---|
|
||||
| 1 | `chat_escape_stop_test`, `chat_task_spinner_test`, `chat_composer_running_test`, `chat_thread_stop_menu_test`, `chat_composer_bar_state_test`, `chat_command_palette_test` | PASS 46/46 |
|
||||
| 2 | Affected users: `chat_background_tasks_*` (4), `chat_thread_view_test`, `chat_thread_header_test`, `chat_composer_*` (bar, focus ring, enter, paste, attachment send, bottom margin), `chat_busy_resume`, `chat_response_pending`, `chat_live_reasoning`, `chat_floating_chrome`, `chat_server_queue`, `chat_delivery`, `composer_focus_restore`, `chat_unfocused_paste_routing`, `chat_floating_pane`, `chat_next_chat`, `chat_shell_composer`, `glass_bar` | PASS 169/169 |
|
||||
|
||||
`tool/analyze.sh` (whole app): clean, exit 0.
|
||||
|
||||
## Affected states (widget tests)
|
||||
|
||||
- Running: no `chat-composer-stop`; Send present; border present; no interrupt sent.
|
||||
- Turn ended: border gone; no animation ticker left.
|
||||
- Reduced motion while running: border present, zero tickers.
|
||||
- `/stop` (one send) interrupts; the notice shows.
|
||||
- Esc once: hint shown, no interrupt. Esc twice (within 1 s): one interrupt.
|
||||
Esc idle: nothing. Esc with palette open: palette closes and does not count.
|
||||
- Transcript-level focus: Esc twice stops (`ChatEscapeStop` unit test). A
|
||||
descendant-handled Esc never counts.
|
||||
- More menu: Stop present while running and triggers the interrupt; absent when idle.
|
||||
- Tasks icon: spins while a task runs; static at rest; reduced motion never turns.
|
||||
|
||||
## Limitations
|
||||
|
||||
- Not captured or reviewed visually (ui-review owns that). The border's colours
|
||||
and glow strength in light and dark are unverified by eye.
|
||||
- Escape stop is verified with synthetic key events in widget tests, not on a
|
||||
physical keyboard or a device. Touch devices are covered by the More menu item
|
||||
only; no device was tested.
|
||||
- The More menu Stop item is shown on every platform while running, not only on
|
||||
touch devices.
|
||||
- A partial command word (`/sto`) still needs two sends (palette completes, then
|
||||
runs); a fully typed `/stop` runs on one send.
|
||||
@@ -22,7 +22,7 @@ void main() {
|
||||
tearDown(() => gateway.close());
|
||||
|
||||
testWidgets(
|
||||
'Stop stays beside Send while running and interrupts this session',
|
||||
'a running turn shows no stop button; Send stays and nothing interrupts',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
composerThread(gateway, newOperationId: nextOperation),
|
||||
@@ -35,18 +35,9 @@ void main() {
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byTooltip(chatSendLabel), findsOneWidget);
|
||||
expect(find.byTooltip(chatStopLabel), findsOneWidget);
|
||||
final button = tester.widget<IconButton>(
|
||||
find.byKey(const Key('chat-composer-stop')),
|
||||
);
|
||||
final scheme = Theme.of(
|
||||
tester.element(find.byKey(const Key('chat-composer-stop'))),
|
||||
).colorScheme;
|
||||
expect(button.style?.backgroundColor?.resolve({}), scheme.error);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-composer-stop')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.interruptBodies.single, {'session_id': 's'});
|
||||
expect(find.byKey(const Key('chat-composer-stop')), findsNothing);
|
||||
expect(find.byTooltip(chatStopLabel), findsNothing);
|
||||
expect(gateway.interruptBodies, isEmpty);
|
||||
expect(gateway.promptBodies, isEmpty);
|
||||
},
|
||||
);
|
||||
@@ -190,7 +181,7 @@ void main() {
|
||||
reply.complete({'chat_queued': true});
|
||||
await tester.pumpAndSettle();
|
||||
expect(fieldText(tester), 'Newer draft');
|
||||
expect(find.byKey(const Key('chat-composer-stop')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-composer-stop')), findsNothing);
|
||||
expect(gateway.interruptBodies, isEmpty);
|
||||
},
|
||||
);
|
||||
@@ -213,7 +204,7 @@ void main() {
|
||||
text,
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.byKey(const Key('chat-composer-stop')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-composer-stop')), findsNothing);
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(fieldText(tester), '');
|
||||
@@ -228,7 +219,7 @@ void main() {
|
||||
'op/2',
|
||||
]);
|
||||
expect(gateway.interruptBodies, isEmpty);
|
||||
expect(find.byKey(const Key('chat-composer-stop')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-composer-stop')), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('the composer wraps at 320 logical px with 2x text', (
|
||||
@@ -267,6 +258,6 @@ void main() {
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byKey(const Key('chat-composer')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-composer-primary')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-composer-stop')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-composer-stop')), findsNothing);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_command_palette.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_escape_stop.dart';
|
||||
|
||||
import 'chat_composer_bar_fixtures.dart';
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
Finder get _border => find.byKey(const Key('chat-composer-running-border'));
|
||||
|
||||
Future<ComposerBarGateway> _pumpThread(WidgetTester tester) async {
|
||||
final gateway = ComposerBarGateway()..page = fixtureTurn();
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(
|
||||
composerThread(gateway, newOperationId: () => 'op/1'),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return gateway;
|
||||
}
|
||||
|
||||
/// Starts a turn. The border repeats for as long as it runs, so the test
|
||||
/// settles by pumping a frame, never by waiting for the tree to go quiet.
|
||||
Future<void> _startTurn(WidgetTester tester, ComposerBarGateway gateway) async {
|
||||
gateway.emitEvent(chatStepFrame('running'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Future<void> _endTurn(WidgetTester tester, ComposerBarGateway gateway) async {
|
||||
gateway.emitEvent(chatStepFrame('ended'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
void _reducedMotion(bool reduced) =>
|
||||
TestWidgetsFlutterBinding.ensureInitialized()
|
||||
.platformDispatcher
|
||||
.accessibilityFeaturesTestValue = FakeAccessibilityFeatures(
|
||||
disableAnimations: reduced,
|
||||
);
|
||||
|
||||
void main() {
|
||||
tearDown(() => _reducedMotion(false));
|
||||
|
||||
testWidgets('the border travels while a turn runs and is gone after it', (
|
||||
tester,
|
||||
) async {
|
||||
_reducedMotion(false);
|
||||
final gateway = await _pumpThread(tester);
|
||||
expect(_border, findsNothing);
|
||||
|
||||
await _startTurn(tester, gateway);
|
||||
expect(_border, findsOneWidget);
|
||||
expect(tester.binding.transientCallbackCount, greaterThan(0));
|
||||
|
||||
await _endTurn(tester, gateway);
|
||||
expect(_border, findsNothing);
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
});
|
||||
|
||||
testWidgets('reduced motion draws the static border and never ticks', (
|
||||
tester,
|
||||
) async {
|
||||
_reducedMotion(true);
|
||||
final gateway = await _pumpThread(tester);
|
||||
await _startTurn(tester, gateway);
|
||||
expect(_border, findsOneWidget);
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
});
|
||||
|
||||
testWidgets('no stop button appears while a turn runs', (tester) async {
|
||||
final gateway = await _pumpThread(tester);
|
||||
await _startTurn(tester, gateway);
|
||||
expect(find.byKey(const Key('chat-composer-stop')), findsNothing);
|
||||
expect(find.byKey(const Key('chat-composer-primary')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('/stop sent in the composer stops the running turn', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = await _pumpThread(tester);
|
||||
await _startTurn(tester, gateway);
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
'/stop',
|
||||
);
|
||||
await tester.pump();
|
||||
// A draft that already names /stop runs on the first send.
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(gateway.interruptBodies, [
|
||||
{'session_id': 's'},
|
||||
]);
|
||||
expect(gateway.promptBodies, isEmpty);
|
||||
expect(find.text(chatStopCommandNotice), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('two Escapes from the composer stop the turn', (tester) async {
|
||||
final gateway = await _pumpThread(tester);
|
||||
await _startTurn(tester, gateway);
|
||||
await tester.tap(find.byKey(const Key('chat-composer-field')));
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pump();
|
||||
expect(gateway.interruptBodies, isEmpty);
|
||||
expect(find.text(chatEscapeStopHint), findsOneWidget);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(gateway.interruptBodies, [
|
||||
{'session_id': 's'},
|
||||
]);
|
||||
});
|
||||
|
||||
testWidgets('a single Escape does not stop the turn', (tester) async {
|
||||
final gateway = await _pumpThread(tester);
|
||||
await _startTurn(tester, gateway);
|
||||
await tester.tap(find.byKey(const Key('chat-composer-field')));
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(gateway.interruptBodies, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('Escape closes the command palette first and does not count', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = await _pumpThread(tester);
|
||||
await _startTurn(tester, gateway);
|
||||
await tester.enterText(find.byKey(const Key('chat-composer-field')), '/');
|
||||
await tester.pump();
|
||||
expect(find.byType(ChatCommandPalette), findsOneWidget);
|
||||
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pump();
|
||||
expect(find.byType(ChatCommandPalette), findsNothing);
|
||||
expect(gateway.interruptBodies, isEmpty);
|
||||
|
||||
// The palette's Escape was not the first of a pair; this one is.
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pump();
|
||||
expect(gateway.interruptBodies, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('Escape does nothing while no turn runs', (tester) async {
|
||||
final gateway = await _pumpThread(tester);
|
||||
await tester.tap(find.byKey(const Key('chat-composer-field')));
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pump();
|
||||
expect(gateway.interruptBodies, isEmpty);
|
||||
expect(find.text(chatEscapeStopHint), findsNothing);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_escape_stop.dart';
|
||||
|
||||
void main() {
|
||||
group('ChatEscapeStopTracker', () {
|
||||
test('a second press inside the window completes a pair', () {
|
||||
final tracker = ChatEscapeStopTracker();
|
||||
final start = DateTime(2026, 11, 12, 10);
|
||||
expect(tracker.press(start), isFalse);
|
||||
expect(
|
||||
tracker.press(start.add(const Duration(milliseconds: 900))),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
test('a press after the window starts a new pair', () {
|
||||
final tracker = ChatEscapeStopTracker();
|
||||
final start = DateTime(2026, 11, 12, 10);
|
||||
expect(tracker.press(start), isFalse);
|
||||
expect(tracker.press(start.add(const Duration(seconds: 2))), isFalse);
|
||||
expect(
|
||||
tracker.press(start.add(const Duration(seconds: 2, milliseconds: 500))),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
test('reset forgets a pending first press', () {
|
||||
final tracker = ChatEscapeStopTracker();
|
||||
final start = DateTime(2026, 11, 12, 10);
|
||||
tracker.press(start);
|
||||
tracker.reset();
|
||||
expect(
|
||||
tracker.press(start.add(const Duration(milliseconds: 100))),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('ChatEscapeStop', () {
|
||||
late DateTime now;
|
||||
late int stops;
|
||||
|
||||
setUp(() {
|
||||
now = DateTime(2026, 11, 12, 10);
|
||||
stops = 0;
|
||||
});
|
||||
|
||||
Widget host({required bool running, Widget? child}) => MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatEscapeStop(
|
||||
running: running,
|
||||
onStop: () => stops++,
|
||||
clock: () => now,
|
||||
child: child ?? const TextField(key: Key('field')),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
testWidgets('a single Escape shows the hint and does not stop', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(host(running: true));
|
||||
await tester.tap(find.byKey(const Key('field')));
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pump();
|
||||
expect(stops, 0);
|
||||
expect(find.text(chatEscapeStopHint), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('two Escapes within a second stop the turn once', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(host(running: true));
|
||||
await tester.tap(find.byKey(const Key('field')));
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
now = now.add(const Duration(milliseconds: 400));
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pump();
|
||||
expect(stops, 1);
|
||||
expect(find.text(chatEscapeStopHint), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('two Escapes more than a second apart do not stop', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(host(running: true));
|
||||
await tester.tap(find.byKey(const Key('field')));
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
now = now.add(const Duration(milliseconds: 1500));
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pump();
|
||||
expect(stops, 0);
|
||||
});
|
||||
|
||||
testWidgets('an idle chat ignores Escape', (tester) async {
|
||||
await tester.pumpWidget(host(running: false));
|
||||
await tester.tap(find.byKey(const Key('field')));
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pump();
|
||||
expect(stops, 0);
|
||||
expect(find.text(chatEscapeStopHint), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('focus on the transcript counts the same as the composer', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
host(
|
||||
running: true,
|
||||
child: const Focus(
|
||||
autofocus: true,
|
||||
child: SizedBox(width: 10, height: 10),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pump();
|
||||
expect(stops, 1);
|
||||
});
|
||||
|
||||
testWidgets('an Escape a descendant already handled never counts', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
host(
|
||||
running: true,
|
||||
child: Focus(
|
||||
autofocus: true,
|
||||
onKeyEvent: (_, event) =>
|
||||
event.logicalKey == LogicalKeyboardKey.escape
|
||||
? KeyEventResult.handled
|
||||
: KeyEventResult.ignored,
|
||||
child: const SizedBox(width: 10, height: 10),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pump();
|
||||
expect(stops, 0);
|
||||
expect(find.text(chatEscapeStopHint), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a held Escape is one press, not a pair', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
host(
|
||||
running: true,
|
||||
child: const Focus(
|
||||
autofocus: true,
|
||||
child: SizedBox(width: 10, height: 10),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.escape);
|
||||
await tester.sendKeyRepeatEvent(LogicalKeyboardKey.escape);
|
||||
await tester.sendKeyRepeatEvent(LogicalKeyboardKey.escape);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pump();
|
||||
expect(stops, 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,174 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_stop_icon.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_composer_controller.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart';
|
||||
import 'package:pipelines_app/ui/motion/motion.dart';
|
||||
|
||||
import 'chat_composer_bar_fixtures.dart';
|
||||
|
||||
class _CountPaint extends CustomPainter {
|
||||
_CountPaint(this.onPaint);
|
||||
final VoidCallback onPaint;
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) => onPaint();
|
||||
@override
|
||||
bool shouldRepaint(_CountPaint oldDelegate) => false;
|
||||
}
|
||||
|
||||
void main() {
|
||||
setUp(() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized()
|
||||
.platformDispatcher
|
||||
.accessibilityFeaturesTestValue = const FakeAccessibilityFeatures(
|
||||
disableAnimations: false,
|
||||
);
|
||||
});
|
||||
tearDown(() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized()
|
||||
.platformDispatcher
|
||||
.accessibilityFeaturesTestValue = const FakeAccessibilityFeatures(
|
||||
disableAnimations: true,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('rotation repaints only the icon, not the surrounding chat', (
|
||||
tester,
|
||||
) async {
|
||||
var paints = 0;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: CustomPaint(
|
||||
painter: _CountPaint(() => paints++),
|
||||
child: const ChatStopIcon(child: Icon(Icons.stop)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final before = paints;
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
expect(paints, before);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'Stop rotates linearly and continuously once every eight seconds',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(body: ChatStopIcon(child: Icon(Icons.stop))),
|
||||
),
|
||||
);
|
||||
RotationTransition rotation() =>
|
||||
tester.widget(find.byKey(const Key('chat-stop-rotation')));
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(rotation().turns.value, closeTo(0.25, 0.001));
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(rotation().turns.value, closeTo(0.5, 0.001));
|
||||
await tester.pump(const Duration(seconds: 8));
|
||||
expect(rotation().turns.value, closeTo(0.5, 0.001));
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('reduced motion stops/reset rotation and resumes when enabled', (
|
||||
tester,
|
||||
) async {
|
||||
final reduce = ValueNotifier<bool>(true);
|
||||
addTearDown(reduce.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ValueListenableBuilder<bool>(
|
||||
valueListenable: reduce,
|
||||
builder: (context, value, _) => MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(disableAnimations: value),
|
||||
child: const ChatStopIcon(child: Icon(Icons.stop)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
RotationTransition rotation() =>
|
||||
tester.widget(find.byKey(const Key('chat-stop-rotation')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(rotation().turns.value, 0);
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
reduce.value = false;
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
expect(rotation().turns.value, closeTo(0.125, 0.001));
|
||||
reduce.value = true;
|
||||
await tester.pumpAndSettle();
|
||||
expect(rotation().turns.value, 0);
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
});
|
||||
|
||||
testWidgets('TickerMode silences hidden Stop animation', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: TickerMode(
|
||||
enabled: false,
|
||||
child: ChatStopIcon(child: Icon(Icons.stop)),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'rotating Stop keeps its target and interrupt action; Send stays available',
|
||||
(tester) async {
|
||||
final gateway = ComposerBarGateway();
|
||||
addTearDown(gateway.close);
|
||||
final composer = ChatComposerController(
|
||||
gateway,
|
||||
's',
|
||||
drafts: MemoryChatDraftStore(),
|
||||
);
|
||||
addTearDown(composer.dispose);
|
||||
final running = ValueNotifier<bool>(true);
|
||||
addTearDown(running.dispose);
|
||||
final bar = ValueListenableBuilder<bool>(
|
||||
valueListenable: running,
|
||||
builder: (_, value, _) =>
|
||||
ChatComposerBar(composer: composer, running: value),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(body: Center(child: bar)),
|
||||
),
|
||||
);
|
||||
// The composer pops in first; Stop's target is measured once it has.
|
||||
await tester.pump(Motion.tabEntranceDuration);
|
||||
final stop = find.byKey(const Key('chat-composer-stop'));
|
||||
final target = tester.getRect(stop);
|
||||
await tester.pump(const Duration(seconds: 3));
|
||||
expect(tester.getRect(stop), target);
|
||||
expect(find.byKey(const Key('chat-composer-primary')), findsOneWidget);
|
||||
expect(
|
||||
tester
|
||||
.widget<RotationTransition>(
|
||||
find.byKey(const Key('chat-stop-rotation')),
|
||||
)
|
||||
.turns
|
||||
.value,
|
||||
greaterThan(0),
|
||||
);
|
||||
await tester.tap(stop);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(gateway.interruptBodies, [
|
||||
{'session_id': 's'},
|
||||
]);
|
||||
running.value = false;
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(ChatStopIcon), findsNothing);
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_background_tasks.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_task_spinner.dart';
|
||||
|
||||
RotationTransition _rotation(WidgetTester tester) =>
|
||||
tester.widget<RotationTransition>(
|
||||
find.byKey(const Key('chat-background-tasks-spinner')),
|
||||
);
|
||||
|
||||
Widget _spinner(bool spinning) => MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatTaskSpinner(
|
||||
spinning: spinning,
|
||||
child: const Icon(Icons.layers_outlined, size: 16),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
void _reducedMotion(bool reduced) =>
|
||||
TestWidgetsFlutterBinding.ensureInitialized()
|
||||
.platformDispatcher
|
||||
.accessibilityFeaturesTestValue = FakeAccessibilityFeatures(
|
||||
disableAnimations: reduced,
|
||||
);
|
||||
|
||||
class _TasksGateway implements ApiGateway {
|
||||
final _frames = StreamController<JsonMap>.broadcast();
|
||||
List<JsonMap> running = const [];
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => _frames.stream;
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
if (type == 'chat_shells') return {'chat_shells': running};
|
||||
if (type == 'chat_automations') {
|
||||
return {
|
||||
'chat_automations': {'status': 'unavailable'},
|
||||
};
|
||||
}
|
||||
return <String, dynamic>{};
|
||||
}
|
||||
|
||||
void close() => _frames.close();
|
||||
}
|
||||
|
||||
void main() {
|
||||
tearDown(() => _reducedMotion(false));
|
||||
|
||||
testWidgets('turns once every period while spinning', (tester) async {
|
||||
_reducedMotion(false);
|
||||
await tester.pumpWidget(_spinner(true));
|
||||
expect(_rotation(tester).turns.value, 0);
|
||||
await tester.pump(ChatTaskSpinner.period ~/ 4);
|
||||
expect(_rotation(tester).turns.value, closeTo(0.25, 0.01));
|
||||
// Past one full lap the turn starts again from the top.
|
||||
await tester.pump(
|
||||
ChatTaskSpinner.period ~/ 4 * 3 + const Duration(milliseconds: 100),
|
||||
);
|
||||
expect(_rotation(tester).turns.value, closeTo(0.04, 0.01));
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
});
|
||||
|
||||
testWidgets('stays still when not spinning, and stops when it stops', (
|
||||
tester,
|
||||
) async {
|
||||
_reducedMotion(false);
|
||||
await tester.pumpWidget(_spinner(false));
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(_rotation(tester).turns.value, 0);
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
|
||||
await tester.pumpWidget(_spinner(true));
|
||||
await tester.pump(const Duration(milliseconds: 625));
|
||||
expect(_rotation(tester).turns.value, greaterThan(0));
|
||||
|
||||
await tester.pumpWidget(_spinner(false));
|
||||
await tester.pump();
|
||||
expect(_rotation(tester).turns.value, 0);
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(_rotation(tester).turns.value, 0);
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
});
|
||||
|
||||
testWidgets('reduced motion keeps the icon static even while spinning', (
|
||||
tester,
|
||||
) async {
|
||||
_reducedMotion(true);
|
||||
await tester.pumpWidget(_spinner(true));
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
expect(_rotation(tester).turns.value, 0);
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
});
|
||||
|
||||
testWidgets('the tasks icon rotates only while a task runs', (tester) async {
|
||||
_reducedMotion(false);
|
||||
final gateway = _TasksGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.running = const [
|
||||
{'id': 'sh1', 'status': 'running', 'command': 'go test ./...'},
|
||||
];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatBackgroundTasks(gateway: gateway, sessionId: 's'),
|
||||
),
|
||||
),
|
||||
);
|
||||
// The spinning icon repeats forever, so settle by pumping, never by waiting.
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(find.text('1 task'), findsOneWidget);
|
||||
final before = _rotation(tester).turns.value;
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
expect(_rotation(tester).turns.value, greaterThan(before));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'chat_composer_bar_fixtures.dart';
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
void main() {
|
||||
Future<ComposerBarGateway> pumpThread(WidgetTester tester) async {
|
||||
final gateway = ComposerBarGateway()..page = fixtureTurn();
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(
|
||||
composerThread(gateway, newOperationId: () => 'op/1'),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return gateway;
|
||||
}
|
||||
|
||||
testWidgets('the More menu offers Stop while a turn runs, for touch use', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = await pumpThread(tester);
|
||||
gateway.emitEvent(chatStepFrame('running'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
await tester.tap(find.byTooltip('More actions').hitTestable().first);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Stop'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
expect(gateway.interruptBodies, [
|
||||
{'session_id': 's'},
|
||||
]);
|
||||
expect(gateway.promptBodies, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('the More menu has no Stop once the turn has ended', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = await pumpThread(tester);
|
||||
await tester.tap(find.byTooltip('More actions').hitTestable().first);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Stop'), findsNothing);
|
||||
expect(gateway.interruptBodies, isEmpty);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user