From f7f2504a304069f0c75f218c2ab79a91fa6b1aa0 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 13 Nov 2026 13:00:57 +0000 Subject: [PATCH] Drag chats at once with a mouse and mark only the receiving zone The list rows used a long-press drag, which a mouse rarely triggers; they now drag immediately with the chip at the pointer. The drop indicator outlines just the area that will receive the chat (the pane, or the right or bottom half) with a label saying what happens. --- .../ui/sessions/chat_compact_sidebar.dart | 5 +- .../chat/ui/sessions/session_row_content.dart | 5 +- .../chat/workspace/chat_workspace_drop.dart | 93 +++++++++++++------ .../workspace/chat_workspace_drop_test.dart | 78 ++++++++++++++++ 4 files changed, 152 insertions(+), 29 deletions(-) create mode 100644 app/test/features/chat/workspace/chat_workspace_drop_test.dart diff --git a/app/lib/features/chat/ui/sessions/chat_compact_sidebar.dart b/app/lib/features/chat/ui/sessions/chat_compact_sidebar.dart index 7482610f..015b3548 100644 --- a/app/lib/features/chat/ui/sessions/chat_compact_sidebar.dart +++ b/app/lib/features/chat/ui/sessions/chat_compact_sidebar.dart @@ -126,7 +126,10 @@ class ChatCompactSidebar extends StatelessWidget { ? Duration.zero : const Duration(milliseconds: 200), color: selected ? Colors.transparent : color.withValues(alpha: .07), - child: LongPressDraggable( + child: Draggable( + // A mouse drags at once (a click still opens the chat); the chip + // follows the pointer. + dragAnchorStrategy: pointerDragAnchorStrategy, data: row, feedback: Material( elevation: 4, diff --git a/app/lib/features/chat/ui/sessions/session_row_content.dart b/app/lib/features/chat/ui/sessions/session_row_content.dart index b9369a34..b61e91b5 100644 --- a/app/lib/features/chat/ui/sessions/session_row_content.dart +++ b/app/lib/features/chat/ui/sessions/session_row_content.dart @@ -81,7 +81,10 @@ class ChatSessionRow extends StatelessWidget { marker: marker, markerWidth: visible ? (selected ? 10 : 3) : 0, child: draggable - ? LongPressDraggable( + ? Draggable( + // A mouse drags at once (a click still opens the chat); the chip + // follows the pointer. + dragAnchorStrategy: pointerDragAnchorStrategy, data: session, feedback: Material( elevation: 4, diff --git a/app/lib/features/chat/workspace/chat_workspace_drop.dart b/app/lib/features/chat/workspace/chat_workspace_drop.dart index 357df303..b19e00b5 100644 --- a/app/lib/features/chat/workspace/chat_workspace_drop.dart +++ b/app/lib/features/chat/workspace/chat_workspace_drop.dart @@ -57,38 +57,77 @@ class _ChatWorkspaceDropTargetState extends State { builder: (context, candidates, rejected) { final zone = _zone; if (zone == null) return const SizedBox.expand(); - final color = Theme.of(context).colorScheme.primary; - final indicator = switch (zone) { - ChatWorkspaceDropZone.replace => const SizedBox.expand(), - ChatWorkspaceDropZone.right => const Align( - alignment: Alignment.centerRight, - child: FractionallySizedBox(widthFactor: .5, heightFactor: 1), + final scheme = Theme.of(context).colorScheme; + final (alignment, width, height, icon, label) = switch (zone) { + ChatWorkspaceDropZone.replace => ( + Alignment.center, + 1.0, + 1.0, + Icons.swap_horiz, + 'Show here', ), - ChatWorkspaceDropZone.bottom => const Align( - alignment: Alignment.bottomCenter, - child: FractionallySizedBox(widthFactor: 1, heightFactor: .5), + ChatWorkspaceDropZone.right => ( + Alignment.centerRight, + .5, + 1.0, + Icons.vertical_split_outlined, + 'Open to the right', + ), + ChatWorkspaceDropZone.bottom => ( + Alignment.bottomCenter, + 1.0, + .5, + Icons.horizontal_split_outlined, + 'Open below', ), }; - return Stack( - fit: StackFit.expand, - children: [ - DecoratedBox( - decoration: BoxDecoration(color: color.withValues(alpha: .18)), - child: indicator, - ), - if (zone != ChatWorkspaceDropZone.replace) - Align( - alignment: zone == ChatWorkspaceDropZone.right - ? Alignment.centerRight - : Alignment.bottomCenter, - child: Icon( - zone == ChatWorkspaceDropZone.right - ? Icons.vertical_split - : Icons.horizontal_split, - color: color, + // Only the area that will receive the chat is marked: the whole pane + // to replace its chat, or the half a new split will take. + return IgnorePointer( + child: Align( + alignment: alignment, + child: FractionallySizedBox( + widthFactor: width, + heightFactor: height, + child: Padding( + padding: const EdgeInsets.all(8), + child: DecoratedBox( + key: ValueKey('chat-drop-zone-${zone.name}'), + decoration: BoxDecoration( + color: scheme.primary.withValues(alpha: .14), + border: Border.all(color: scheme.primary, width: 2), + borderRadius: BorderRadius.circular(16), + ), + child: Center( + child: DecoratedBox( + decoration: BoxDecoration( + color: scheme.primaryContainer, + borderRadius: BorderRadius.circular(24), + ), + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 16, + vertical: 10, + ), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon(icon, color: scheme.onPrimaryContainer), + const SizedBox(width: 8), + Text( + label, + style: Theme.of(context).textTheme.labelLarge + ?.copyWith(color: scheme.onPrimaryContainer), + ), + ], + ), + ), + ), + ), ), ), - ], + ), + ), ); }, ); diff --git a/app/test/features/chat/workspace/chat_workspace_drop_test.dart b/app/test/features/chat/workspace/chat_workspace_drop_test.dart new file mode 100644 index 00000000..f8d22cf0 --- /dev/null +++ b/app/test/features/chat/workspace/chat_workspace_drop_test.dart @@ -0,0 +1,78 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/workspace/chat_workspace_drop.dart'; +import 'package:pipelines_app/features/chat/workspace/chat_workspace_nodes.dart'; + +void main() { + Future> pumpPane(WidgetTester tester) async { + tester.view.physicalSize = const Size(1200, 800); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + final drops = []; + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: Row( + children: [ + const SizedBox( + width: 200, + child: Draggable( + data: 'b', + // As the chat list does: the feedback sits at the pointer. + dragAnchorStrategy: pointerDragAnchorStrategy, + feedback: Text('chat b'), + child: Text('source'), + ), + ), + SizedBox( + width: 800, + height: 600, + child: ChatWorkspaceDropTarget( + pane: const ChatWorkspacePane('pane-a', 'a'), + rect: const Rect.fromLTWH(0, 0, 800, 600), + onDrop: (_, _, zone) => drops.add(zone), + ), + ), + ], + ), + ), + ), + ); + return drops; + } + + // The pane occupies x 200..1000, y 0..600. + for (final (name, point, zone) in [ + ('centre', const Offset(500, 250), ChatWorkspaceDropZone.replace), + ('right edge', const Offset(950, 250), ChatWorkspaceDropZone.right), + ('bottom edge', const Offset(500, 560), ChatWorkspaceDropZone.bottom), + ]) { + testWidgets('a mouse drag over the $name marks only that zone and drops ' + 'there', (tester) async { + final drops = await pumpPane(tester); + final gesture = await tester.startGesture( + tester.getCenter(find.text('source')), + ); + // No long press: a plain drag starts at once. + await gesture.moveBy(const Offset(20, 0)); + await gesture.moveTo(point); + await tester.pump(); + await tester.pump(); + expect( + find.byKey(ValueKey('chat-drop-zone-${zone.name}')), + findsOneWidget, + ); + for (final other in ChatWorkspaceDropZone.values) { + if (other == zone) continue; + expect( + find.byKey(ValueKey('chat-drop-zone-${other.name}')), + findsNothing, + ); + } + await gesture.up(); + await tester.pump(); + expect(drops, [zone]); + expect(find.byKey(ValueKey('chat-drop-zone-${zone.name}')), findsNothing); + }); + } +}