Drag chats from the list onto panes

On desktop a chat dragged from the list or compact rail onto a tiled
pane replaces that pane's chat when dropped in its centre, or opens in a
split right of or below it when dropped on that edge; an open chat moves
without duplicating and a floating chat docks.
This commit is contained in:
2026-11-13 12:45:42 +00:00
parent df0614e2f7
commit cb49aeef34
15 changed files with 313 additions and 30 deletions
@@ -17,12 +17,14 @@ import 'chat_pane_switch_motion.dart';
import 'chat_pane_backdrop.dart';
import 'chat_pane_dim.dart';
import 'chat_workspace_pane_scope.dart';
import 'chat_workspace_drop.dart';
import 'chat_workspace_surface.dart';
import '../../../ui/input/keyboard_owner.dart';
export 'chat_workspace_controller.dart';
export 'chat_workspace_geometry.dart' show ChatPaneDirection;
export 'chat_workspace_pane_scope.dart';
export 'chat_workspace_drop.dart';
typedef ChatWorkspacePaneBuilder =
Widget Function(BuildContext context, ChatWorkspacePane pane, bool active);
@@ -35,6 +37,7 @@ class ChatWorkspace extends StatefulWidget {
required this.controller,
required this.paneBuilder,
this.onFocusPane,
this.onDrop,
this.shortcutsEnabled = true,
this.singlePane = false,
this.mobilePeeks = false,
@@ -71,6 +74,7 @@ class ChatWorkspace extends StatefulWidget {
/// Keyboard navigation only: the owner can focus the target composer.
/// Pointer activation leaves text-selection and pointer focus alone.
final ValueChanged<ChatWorkspacePane>? onFocusPane;
final void Function(ChatWorkspacePane, Object, ChatWorkspaceDropZone)? onDrop;
@override
State<ChatWorkspace> createState() => _ChatWorkspaceState();
@@ -393,6 +397,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
sharedEdges,
moveTargets[pane.id],
),
onDrop: widget.onDrop,
);
},
),
@@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart';
import 'chat_workspace_nodes.dart';
import 'chat_workspace_reconcile.dart';
import 'chat_workspace_snapshot.dart';
import 'chat_workspace_drop.dart';
export 'chat_workspace_nodes.dart';
@@ -237,6 +238,56 @@ class ChatWorkspaceController extends ChangeNotifier {
_changed();
}
/// Places a dragged chat into a pane without ever creating a duplicate.
void dropSession(
String sessionId,
String targetPaneId,
ChatWorkspaceDropZone zone,
) {
if (sessionId.isEmpty || _root == null) return;
final target = panes.where((pane) => pane.id == targetPaneId).firstOrNull;
if (target == null) return;
final source = panes
.where((pane) => pane.sessionId == sessionId)
.firstOrNull;
if (source?.id == target.id) {
activate(target.id);
return;
}
if (zone == ChatWorkspaceDropZone.replace) {
if (source == null) {
_root = _replace(
_root!,
target.id,
ChatWorkspacePane(target.id, sessionId),
);
} else {
_root = swapChatWorkspacePanes(_root!, source, target);
}
_active = target.id;
_changed();
return;
}
if (source != null) close(source.id);
final axis = zone == ChatWorkspaceDropZone.right
? ChatSplitAxis.horizontal
: ChatSplitAxis.vertical;
final current = panes.where((pane) => pane.id == target.id).firstOrNull;
if (current == null) return;
_root = _replace(
_root!,
current.id,
ChatWorkspaceSplit(
_id('split'),
axis,
current,
ChatWorkspacePane(_id('pane'), sessionId),
),
);
_active = panes.last.id;
_changed();
}
ChatWorkspaceNode _replace(
ChatWorkspaceNode node,
String id,
@@ -0,0 +1,95 @@
import 'package:flutter/material.dart';
import 'chat_workspace_nodes.dart';
enum ChatWorkspaceDropZone { replace, right, bottom }
class ChatWorkspaceDropTarget extends StatefulWidget {
const ChatWorkspaceDropTarget({
super.key,
required this.pane,
required this.rect,
required this.onDrop,
});
final ChatWorkspacePane pane;
final Rect rect;
final void Function(ChatWorkspacePane, Object, ChatWorkspaceDropZone) onDrop;
@override
State<ChatWorkspaceDropTarget> createState() =>
_ChatWorkspaceDropTargetState();
}
class _ChatWorkspaceDropTargetState extends State<ChatWorkspaceDropTarget> {
ChatWorkspaceDropZone? _zone;
ChatWorkspaceDropZone _zoneAt(Offset local) {
if (local.dx >= widget.rect.width * .75) {
return ChatWorkspaceDropZone.right;
}
if (local.dy >= widget.rect.height * .75) {
return ChatWorkspaceDropZone.bottom;
}
return ChatWorkspaceDropZone.replace;
}
@override
Widget build(BuildContext context) => DragTarget<Object>(
onWillAcceptWithDetails: (_) => true,
onMove: (details) {
final box = context.findRenderObject() as RenderBox?;
if (box == null) return;
final zone = _zoneAt(box.globalToLocal(details.offset));
if (_zone != zone) setState(() => _zone = zone);
},
onLeave: (_) {
if (mounted) setState(() => _zone = null);
},
onAcceptWithDetails: (details) {
final box = context.findRenderObject() as RenderBox?;
final zone = box == null
? ChatWorkspaceDropZone.replace
: _zoneAt(box.globalToLocal(details.offset));
setState(() => _zone = null);
widget.onDrop(widget.pane, details.data, zone);
},
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),
),
ChatWorkspaceDropZone.bottom => const Align(
alignment: Alignment.bottomCenter,
child: FractionallySizedBox(widthFactor: 1, heightFactor: .5),
),
};
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,
),
),
],
);
},
);
}
@@ -13,6 +13,7 @@ import 'chat_motion_viewport.dart';
import 'chat_workspace_controller.dart';
import 'chat_workspace_divider.dart';
import 'chat_workspace_geometry.dart';
import 'chat_workspace_drop.dart';
/// Rendering only: retained live panes stay stable siblings, while the outgoing
/// picture and mobile drag target sit alongside them in the same clipped stack.
@@ -30,6 +31,7 @@ Widget chatWorkspaceSurface({
required List<ChatWorkspacePane> panes,
required Widget Function(ChatWorkspacePane) paneView,
Widget Function(ChatWorkspacePane)? stageStrip,
void Function(ChatWorkspacePane, Object, ChatWorkspaceDropZone)? onDrop,
}) {
final moving = Listenable.merge([
motion.animation,
@@ -145,6 +147,17 @@ Widget chatWorkspaceSurface({
rect: stage.rectFor(layout.stageId)!,
size: size,
),
if (!collapsed && mobile == null && onDrop != null)
for (final pane in panes)
if (geometry.panes[pane.id] case final rect?)
Positioned.fromRect(
rect: rect,
child: ChatWorkspaceDropTarget(
pane: pane,
rect: rect,
onDrop: onDrop,
),
),
if (mobile?.peekId != null && !motion.isAnimating)
Positioned(
top: mobile!.contentHeight - 12,