Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Phone: a thread message's Copy shows when tapped at the thread's foot (#2468)

0xken151e1f692ee635
diff --git a/mobile/lib/swarm/swarm_thread_page.dart b/mobile/lib/swarm/swarm_thread_page.dart
index e787adba3..86eb37fca 100644
--- a/mobile/lib/swarm/swarm_thread_page.dart
+++ b/mobile/lib/swarm/swarm_thread_page.dart
@@ -79,6 +79,29 @@ class _SwarmThreadPageState extends State<SwarmThreadPage> {
/// The message whose actions are open (Copy), by a tap on it.
String? _acting;
+ /// The row of [_acting], to bring its actions into view.
+ final _actingKey = GlobalKey();
+
+ /// Opens [id]'s actions, or closes them on a second tap. Opened under the
+ /// last reply of a thread read to its foot they would be drawn under the
+ /// box, so the row is scrolled just enough to show them (the chat, newest
+ /// at its foot, grows upward and never hides them).
+ void _toggleActions(String id) {
+ setState(() => _acting = _acting == id ? null : id);
+ if (_acting == null) return;
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ final row = _actingKey.currentContext;
+ if (!mounted || _acting != id || row == null) return;
+ unawaited(
+ Scrollable.ensureVisible(
+ row,
+ alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtEnd,
+ duration: const Duration(milliseconds: 150),
+ ),
+ );
+ });
+ }
+
/// What the last pick left out, or why it could not pick, under the box.
final _attachNote = ValueNotifier<String?>(null);
bool _picking = false;
@@ -332,13 +355,19 @@ class _SwarmThreadPageState extends State<SwarmThreadPage> {
final replies = t.replies;
final count = t.count;
final pending = t.pending;
- Widget row(SuperTabMessage m, {required bool grouped}) => widget.row(
- t,
- m,
- grouped: grouped,
- acting: _acting == m.id,
- onTap: () => setState(() => _acting = _acting == m.id ? null : m.id),
- );
+ Widget row(SuperTabMessage m, {required bool grouped}) {
+ final built = widget.row(
+ t,
+ m,
+ grouped: grouped,
+ acting: _acting == m.id,
+ onTap: () => _toggleActions(m.id),
+ );
+ return _acting == m.id
+ ? KeyedSubtree(key: _actingKey, child: built)
+ : built;
+ }
+
return ListView(
key: const ValueKey('swarm-thread-messages'),
controller: _scroll,
diff --git a/mobile/test/swarm/swarm_chat_test.dart b/mobile/test/swarm/swarm_chat_test.dart
index 420f9f243..2051464ca 100644
--- a/mobile/test/swarm/swarm_chat_test.dart
+++ b/mobile/test/swarm/swarm_chat_test.dart
@@ -2132,6 +2132,80 @@ void main() {
expect(key('swarm-reply-bar'), findsNothing);
});
+ testWidgets('in a thread, a tap on a message offers Copy, as in the chat, '
+ 'and Copy copies its text (Dee, 11-01)', (tester) async {
+ String? copied;
+ TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
+ .setMockMethodCallHandler(SystemChannels.platform, (call) async {
+ if (call.method == 'Clipboard.setData') {
+ copied = (call.arguments as Map)['text'] as String?;
+ }
+ return null;
+ });
+ addTearDown(
+ () => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
+ .setMockMethodCallHandler(SystemChannels.platform, null),
+ );
+ await pump(tester, threaded());
+ await tester.tap(key('swarm-thread-line-m1'));
+ await tester.pumpAndSettle();
+
+ for (final (id, text) in [('m2', onlyThere), ('m1', root)]) {
+ await tester.tap(inThread(text));
+ await tester.pumpAndSettle();
+ final copy = find.descendant(
+ of: key('swarm-thread-message-$id'),
+ matching: find.text('Copy'),
+ );
+ expect(copy, findsOneWidget, reason: '$id offers Copy');
+ await tester.tap(copy);
+ await tester.pumpAndSettle();
+ expect(copied, text);
+ }
+ });
+
+ testWidgets('in a long thread read to its foot, a tap on the last reply '
+ 'brings its Copy into view, above the box', (tester) async {
+ final page = [
+ message('m1', 1, author: 'agent-lead', text: root, thread: 'm1'),
+ for (var i = 2; i <= 21; i++)
+ message(
+ 'r$i',
+ i,
+ text: 'Reply $i\nwith a second line',
+ thread: 'm1',
+ replyTo: 'm1',
+ minute: i,
+ ),
+ ];
+ final fake = backend(page, threads: [line('m1', 20, 21)]);
+ fake.routes['$messages?thread=m1'] = (_) => {
+ 'messages': page.reversed.toList(),
+ 'next': null,
+ 'threads': [line('m1', 20, 21)],
+ };
+ await pump(tester, fake);
+ await tester.tap(key('swarm-thread-line-m1'));
+ await tester.pumpAndSettle();
+ for (var i = 0; i < 10; i++) {
+ await tester.drag(key('swarm-thread-messages'), const Offset(0, -2000));
+ await tester.pumpAndSettle();
+ }
+
+ await tester.tap(inThread('Reply 21\nwith a second line'));
+ await tester.pumpAndSettle();
+ final copy = find.descendant(
+ of: key('swarm-thread-message-r21'),
+ matching: find.text('Copy'),
+ );
+ expect(copy, findsOneWidget);
+ expect(
+ tester.getRect(copy).bottom,
+ lessThanOrEqualTo(tester.getRect(key('swarm-thread-messages')).bottom),
+ reason: 'Copy shows, not under the box',
+ );
+ });
+
testWidgets('a message that is only a code block still opens its thread: '
'a tap on the code shows Reply, Copy only copies', (tester) async {
const code = '```\nflutter test\n```';