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
@@ -80,6 +80,25 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
ChatSectionFolds get _foldsForSidebar;
void _openSidebarSession(JsonMap session);
void _dropSession(
ChatWorkspacePane target,
Object data,
ChatWorkspaceDropZone zone,
) {
if (data is! JsonMap) return;
final sessionId = '${data['id'] ?? ''}';
if (sessionId.isEmpty) return;
final windows = widget.windows;
final floating = windows?.windows
.where((window) => window.contentId == sessionId)
.firstOrNull;
if (floating != null) windows!.manager.close(floating.id);
_openedSessions[sessionId] = data;
_workspaceVisible = true;
_workspace.dropSession(sessionId, target.id, zone);
_composerFocus.request(sessionId);
}
final ChatWorkspaceController _workspace = ChatWorkspaceController();
ChatOpenWorkspaceController? _openWorkspace;
bool _applyingServerWorkspace = false;
@@ -467,6 +486,7 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
paneTitle: (pane) =>
'${_rowFor(pane.sessionId)?['title'] ?? pane.sessionId}',
onFocusPane: (pane) => _composerFocus.request(pane.sessionId),
onDrop: _dropSession,
paneBuilder: (context, pane, active) {
final scope = ChatWorkspacePaneScope.maybeOf(context);
final topShared = scope?.topEdgeShared ?? false;
+1
View File
@@ -491,6 +491,7 @@ class _ChatScreenState extends State<ChatScreen>
controller: _sessions,
folds: _folds,
onOpen: _openBySelection,
draggable: beside,
onOpenBeside: beside ? _openBeside : null,
onOpenBelow: _openBelow,
onFloat: _floatsHere ? _floatSession : null,
@@ -82,6 +82,38 @@ class ChatCompactSidebar extends StatelessWidget {
final color =
chatColorShade(context, chatSessionColor(row)) ??
Theme.of(context).colorScheme.primary;
final button = _button(
context,
details,
ExcludeSemantics(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ChatCompactAvatar(
title: title,
color: color,
active: selected,
visible: visible,
running: running,
backgroundTasks: backgroundTasks,
unread: unread,
),
if (machineName case final name?)
Text(
name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.labelSmall,
),
],
),
),
() {
unawaited(controller.markOpened(row));
onOpen(row);
},
selected: selected,
);
return ChatVisibilityMarker(
sessionId: id,
color: color,
@@ -92,37 +124,26 @@ class ChatCompactSidebar extends StatelessWidget {
? Duration.zero
: const Duration(milliseconds: 200),
color: selected ? Colors.transparent : color.withValues(alpha: .07),
child: _button(
context,
details,
ExcludeSemantics(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ChatCompactAvatar(
title: title,
color: color,
active: selected,
visible: visible,
running: running,
backgroundTasks: backgroundTasks,
unread: unread,
),
if (machineName case final name?)
Text(
name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.labelSmall,
),
],
child: LongPressDraggable<JsonMap>(
data: row,
feedback: Material(
elevation: 4,
borderRadius: BorderRadius.circular(20),
child: Chip(
avatar: ChatCompactAvatar(
title: title,
color: color,
active: false,
visible: false,
running: running,
backgroundTasks: backgroundTasks,
unread: unread,
),
label: Text(title),
),
),
() {
unawaited(controller.markOpened(row));
onOpen(row);
},
selected: selected,
childWhenDragging: Opacity(opacity: .35, child: button),
child: button,
),
),
);
@@ -33,6 +33,7 @@ class ChatSessionsBody extends StatelessWidget {
required this.error,
required this.onOpen,
this.onOpenBeside,
this.draggable = false,
this.onOpenBelow,
this.onFloat,
this.paneMenu,
@@ -65,6 +66,7 @@ class ChatSessionsBody extends StatelessWidget {
final String? error;
final ValueChanged<JsonMap> onOpen;
final ValueChanged<JsonMap>? onOpenBeside;
final bool draggable;
final ValueChanged<JsonMap>? onOpenBelow;
final ValueChanged<JsonMap>? onFloat;
final SessionPaneMenu? paneMenu;
@@ -104,6 +106,7 @@ class ChatSessionsBody extends StatelessWidget {
duplicateTitles: duplicateTitles,
onOpen: onOpen,
onOpenBeside: onOpenBeside,
draggable: draggable,
onOpenBelow: onOpenBelow,
onFloat: onFloat,
paneMenu: paneMenu,
@@ -33,6 +33,7 @@ class ChatSessionsScreen extends StatefulWidget {
required this.gateway,
required this.onOpen,
this.onOpenBeside,
this.draggable = false,
this.onOpenBelow,
this.onFloat,
this.paneMenu,
@@ -52,6 +53,7 @@ class ChatSessionsScreen extends StatefulWidget {
/// Optional split-pane actions; absent when the host cannot offer a split.
final ValueChanged<JsonMap>? onOpenBeside;
final bool draggable;
final ValueChanged<JsonMap>? onOpenBelow;
/// Floats the chat in a window over the app; absent when it cannot.
@@ -333,6 +335,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
onOpenBeside: widget.onOpenBeside == null
? null
: _openBeside,
draggable: widget.draggable,
onOpenBelow: widget.onOpenBelow == null
? null
: _openBelow,
@@ -88,6 +88,7 @@ SessionListItem chatSessionRowItem(
required Set<String> duplicateTitles,
required bool Function(JsonMap) isUnseen,
required ValueChanged<JsonMap> onOpen,
bool draggable = false,
ValueChanged<JsonMap>? onOpenBeside,
ValueChanged<JsonMap>? onOpenBelow,
ValueChanged<JsonMap>? onFloat,
@@ -112,6 +113,7 @@ SessionListItem chatSessionRowItem(
unseen: isUnseen(session),
divider: divider,
onOpen: onOpen,
draggable: draggable,
onOpenBeside: onOpenBeside,
onOpenBelow: onOpenBelow,
onFloat: onFloat,
@@ -14,6 +14,7 @@ class MaterialSessionList extends StatelessWidget {
required this.emptyMessage,
required this.duplicateTitles,
required this.onOpen,
this.draggable = false,
this.onOpenBeside,
this.onOpenBelow,
this.onFloat,
@@ -42,6 +43,7 @@ class MaterialSessionList extends StatelessWidget {
final String? emptyMessage;
final Set<String> duplicateTitles;
final ValueChanged<JsonMap> onOpen;
final bool draggable;
final ValueChanged<JsonMap>? onOpenBeside;
final ValueChanged<JsonMap>? onOpenBelow;
final ValueChanged<JsonMap>? onFloat;
@@ -117,6 +119,7 @@ class MaterialSessionList extends StatelessWidget {
duplicateTitles: duplicateTitles,
isUnseen: isUnseen,
onOpen: onOpen,
draggable: draggable,
onOpenBeside: onOpenBeside,
onOpenBelow: onOpenBelow,
onFloat: onFloat,
@@ -44,12 +44,14 @@ class ChatSessionRow extends StatelessWidget {
this.duplicateTitles = const {},
this.onLongPress,
this.selectionOnly = false,
this.draggable = false,
});
final JsonMap session;
/// A choosing surface keeps the normal row content but offers only opening.
final bool selectionOnly;
final bool draggable;
final ValueChanged<JsonMap> onOpen;
final ValueChanged<JsonMap>? onOpenBeside;
final ValueChanged<JsonMap>? onOpenBelow;
@@ -78,7 +80,24 @@ class ChatSessionRow extends StatelessWidget {
color: tint == null ? background : Color.alphaBlend(tint, background),
marker: marker,
markerWidth: visible ? (selected ? 10 : 3) : 0,
child: _marked(context, id, marker, accent),
child: draggable
? LongPressDraggable<JsonMap>(
data: session,
feedback: Material(
elevation: 4,
borderRadius: BorderRadius.circular(20),
child: Chip(
avatar: ChatSessionAvatar(session: session),
label: Text(chatSessionTitle(session)),
),
),
childWhenDragging: Opacity(
opacity: .35,
child: _marked(context, id, marker, accent),
),
child: _marked(context, id, marker, accent),
)
: _marked(context, id, marker, accent),
);
}
@@ -21,6 +21,7 @@ Widget memoChatSessionRow({
required bool unseen,
required bool divider,
required ValueChanged<JsonMap> onOpen,
bool draggable = false,
ValueChanged<JsonMap>? onOpenBeside,
ValueChanged<JsonMap>? onOpenBelow,
ValueChanged<JsonMap>? onFloat,
@@ -43,6 +44,7 @@ Widget memoChatSessionRow({
unseen,
divider,
onOpen,
draggable,
onOpenBeside,
onOpenBelow,
onFloat,
@@ -63,6 +65,7 @@ Widget memoChatSessionRow({
unseen: unseen,
divider: divider,
onOpen: onOpen,
draggable: draggable,
onOpenBeside: onOpenBeside,
onOpenBelow: onOpenBelow,
onFloat: onFloat,
@@ -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,
+13
View File
@@ -0,0 +1,13 @@
# Drag chats onto panes
Implemented desktop chat dragging from expanded rows and compact avatars. A
drop in a pane replaces it; the right and bottom edge zones split horizontally
or vertically. Existing open chats move without duplicates, and floating chat
windows close before docking into the selected pane.
Focused regression: `tool/memwatch/full.sh
'test/features/chat/workspace/chat_workspace_test.dart'` — 11 passed.
`tool/analyze.sh` — clean.
Browser captures and full UI-review fixture coverage were not run in this
implementation stage.
@@ -84,6 +84,37 @@ void main() {
expect(controller.panes.last.sessionId, 'new-two');
});
test('drop replaces, splits and moves without duplicating a chat', () {
final controller = ChatWorkspaceController()
..open('one')
..splitActive('two', ChatSplitAxis.horizontal);
addTearDown(controller.dispose);
final first = controller.panes.first;
final second = controller.panes.last;
controller.dropSession('three', first.id, ChatWorkspaceDropZone.replace);
expect(controller.panes.map((pane) => pane.sessionId), ['three', 'two']);
controller.dropSession('four', second.id, ChatWorkspaceDropZone.right);
expect(controller.panes.map((pane) => pane.sessionId), [
'three',
'two',
'four',
]);
expect(
controller.panes.where((pane) => pane.sessionId == 'three'),
hasLength(1),
);
final four = controller.panes.last;
controller.dropSession('three', four.id, ChatWorkspaceDropZone.bottom);
expect(
controller.panes.where((pane) => pane.sessionId == 'three'),
hasLength(1),
);
expect(controller.activePane?.sessionId, 'three');
});
test(
'geometry clamps visible sizes but retains ratios and spatial neighbors',
() {