From 55ef6558e03fce166e0796c5cb02bbdfdbc4890e Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Mon, 9 Nov 2026 20:46:22 +0000 Subject: [PATCH] Hug the turn activity row's hover on desktop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On macOS, Linux, Windows and desktop browsers the "Thought · tool calls · background tasks" row is as wide as its label, so its hover and click area no longer span the transcript. Phones keep the full-width touch row. The check uses the device platform because web themes are pinned to Android. The scroll fixture gains ?turnactivity=1 for captures. --- .../transcript/chat_turn_activity_view.dart | 4 ++ app/lib/ui/adaptive/platform.dart | 17 ++++++ .../chat_turn_activity_hit_target_test.dart | 52 +++++++++++++++++++ app/tool/perf/chat_scroll_fixture.dart | 14 +++++ 4 files changed, 87 insertions(+) create mode 100644 app/test/features/chat/ui/transcript/chat_turn_activity_hit_target_test.dart diff --git a/app/lib/features/chat/ui/transcript/chat_turn_activity_view.dart b/app/lib/features/chat/ui/transcript/chat_turn_activity_view.dart index e77bde8a..27e4209b 100644 --- a/app/lib/features/chat/ui/transcript/chat_turn_activity_view.dart +++ b/app/lib/features/chat/ui/transcript/chat_turn_activity_view.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import '../../../../core/api_gateway.dart'; import '../../domain/chat_turn_activity.dart'; +import '../../../../ui/adaptive/platform.dart'; import '../sessions/chat_adaptive.dart'; import 'chat_response_pending.dart'; import 'chat_turn_activity_details.dart'; @@ -149,9 +150,12 @@ class _ChatTurnActivityViewState extends State { : DateTime.now().difference(started); final seconds = duration.inSeconds.clamp(0, 2147483647); final label = '${data.label}${widget.streaming ? ' ${seconds}s' : ''}'; + // Desktop hover hugs the label; phones keep the full-width touch row. + final compact = prefersCompactHitTargets(context); final content = ConstrainedBox( constraints: BoxConstraints(minHeight: cupertino ? 28 : 32), child: Row( + mainAxisSize: compact ? MainAxisSize.min : MainAxisSize.max, children: [ if (widget.streaming) ...[ ExcludeSemantics( diff --git a/app/lib/ui/adaptive/platform.dart b/app/lib/ui/adaptive/platform.dart index 82dda1e2..5ef017a5 100644 --- a/app/lib/ui/adaptive/platform.dart +++ b/app/lib/ui/adaptive/platform.dart @@ -1,3 +1,6 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; + /// The app renders the same Material layout and design on every platform: /// web, Android, iOS and macOS. The Cupertino host and controls remain /// available only when a caller asks for them explicitly (`cupertino: true`); @@ -6,3 +9,17 @@ /// Flutter's automatic platform behaviours (scroll physics, text selection, /// page transitions and back-swipe) still follow the target platform. bool prefersCupertino() => false; + +/// Whether this runs on a desktop platform (macOS, Linux, Windows), +/// including a desktop browser. Hover and click targets there hug their +/// content; phones and tablets keep full-width touch rows. Uses the device's +/// platform, not the theme's: web themes are pinned to Android. +bool prefersCompactHitTargets(BuildContext context) => + switch (defaultTargetPlatform) { + TargetPlatform.macOS || + TargetPlatform.linux || + TargetPlatform.windows => true, + TargetPlatform.android || + TargetPlatform.iOS || + TargetPlatform.fuchsia => false, + }; diff --git a/app/test/features/chat/ui/transcript/chat_turn_activity_hit_target_test.dart b/app/test/features/chat/ui/transcript/chat_turn_activity_hit_target_test.dart new file mode 100644 index 00000000..06ac44a2 --- /dev/null +++ b/app/test/features/chat/ui/transcript/chat_turn_activity_hit_target_test.dart @@ -0,0 +1,52 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/ui/transcript/chat_turn_activity_view.dart'; + +Future _activityWidth( + WidgetTester tester, + TargetPlatform platform, +) async { + debugDefaultTargetPlatformOverride = platform; + tester.view.physicalSize = const Size(1200, 800); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + await tester.pumpWidget( + MaterialApp( + // Web pins the theme to Android; the device platform decides. + theme: ThemeData(platform: TargetPlatform.android), + home: const Scaffold( + body: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + ChatTurnActivityView( + parts: [ + {'type': 'reasoning', 'text': 'Considering the files.'}, + ], + streaming: false, + ), + ], + ), + ), + ), + ); + final width = tester + .getSize(find.byKey(const Key('chat-turn-activity'))) + .width; + debugDefaultTargetPlatformOverride = null; + return width; +} + +void main() { + testWidgets('desktop hover hugs the activity label', (tester) async { + for (final platform in [TargetPlatform.macOS, TargetPlatform.linux]) { + expect(await _activityWidth(tester, platform), lessThan(400)); + } + }); + + testWidgets('phones keep the full-width touch row', (tester) async { + for (final platform in [TargetPlatform.android, TargetPlatform.iOS]) { + expect(await _activityWidth(tester, platform), 1200); + } + }); +} diff --git a/app/tool/perf/chat_scroll_fixture.dart b/app/tool/perf/chat_scroll_fixture.dart index dc90a7ee..a49829c7 100644 --- a/app/tool/perf/chat_scroll_fixture.dart +++ b/app/tool/perf/chat_scroll_fixture.dart @@ -23,6 +23,10 @@ Map _params = const {}; void configureChatScrollFixture(Map params) => _params = params; bool get _rich => _params['rich'] == '1'; + +/// `?turnactivity=1`: replies carry thinking and a tool call, so the turn +/// activity row ("Thought … · 1 tool call") is shown. +bool get _activity => _params['turnactivity'] == '1'; bool get _links => _params['links'] == '1'; bool get _older => _params['older'] == '1'; int get _live => int.tryParse(_params['live'] ?? '') ?? 0; @@ -135,6 +139,16 @@ JsonMap _message(String chat, int i) { 'id': id, 'role': 'assistant', 'parts': [ + if (_activity) ...[ + {'type': 'reasoning', 'text': 'Checking the files for step $i.'}, + { + 'type': 'tool', + 'id': 'tool-$i', + 'name': 'read', + 'state': 'completed', + 'input': {'path': 'lib/main.dart'}, + }, + ], {'type': 'text', 'text': _answer(i)}, ], };