Files
pipelines/app/lib/features/chat/chat_screen_stack.dart
T
alan fba3b924f1 Chat stack: hold and drag to reorder the open chats, or onto x to remove
A 300 ms hold lifts a chat in the open column; dragging opens a gap and
dropping commits through ChatWorkspaceController.movePane, the pane order
the server syncs. An x comes in at the bottom while dragging; dropping on
it removes the chat with Undo, which restores its place. Escape, a
cancelled pointer or a drop away from the column put it back. Move up,
Move down and Remove are semantic actions. Repaint-only motion; reduced
motion swaps at once. Also keep floating-layout tracking out of
initState, and let the capture kit hold a press before a drag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 21:17:51 +00:00

106 lines
3.7 KiB
Dart

part of 'screen.dart';
/// The phone's chat stack (Settings → Chat navigation → Chat stack): one
/// floating pile of the open chats above the workspace, following the spot
/// the chat on screen marks above its composer. Its chats are the
/// workspace's panes, the same open chats the server syncs; choosing one
/// opens it as a tap on its list row does, Add chat is the pane menu's Add
/// chat pane, and removing one closes its pane.
mixin _ChatScreenStack on State<ChatScreen>, _ChatScreenWorkspace {
final LayerLink _stackLink = LayerLink();
void _openBySelection(JsonMap session);
@override
MobileChatNavigationController get _navigation =>
MobileChatNavigationController.instance;
/// Whether this layout navigates with the stack rather than the peek.
@override
bool _stacked(BuildContext context) =>
_navigation.stack && !showsListBesideDetail(context);
/// Gives the active pane the stack's spot.
@override
Widget _stackScope(BuildContext context, bool active, Widget child) =>
ChatStackAnchorScope(
link: active && _stacked(context) ? _stackLink : null,
child: child,
);
List<ChatStackEntry> _stackEntries() {
final live = {
for (final row in _sessionsForSidebar.sessions) '${row['id'] ?? ''}': row,
};
final active = _workspace.activePaneId;
return [
for (final pane in _workspace.panes)
ChatStackEntry(
paneId: pane.id,
session:
live[pane.sessionId] ??
_rowFor(pane.sessionId) ??
{'id': pane.sessionId},
current: pane.id == active,
),
];
}
/// The pile over the workspace; it draws only while linked to the chat on
/// screen.
@override
Widget _stackOverlay() => ListenableBuilder(
listenable: Listenable.merge([_workspace, _sessionsForSidebar]),
builder: (context, _) => CompositedTransformFollower(
link: _stackLink,
showWhenUnlinked: false,
child: ChatStackFab(
entries: _stackEntries(),
onOpen: (entry) => _openBySelection(entry.session),
onAdd: (context) => _addPane(context, title: ChatStackColumn.addLabel),
onRemove: _removeFromStack,
onReorder: (entry, index) => _workspace.movePane(entry.paneId, index),
),
),
);
void _removeFromStack(ChatStackEntry entry) {
final messenger = ScaffoldMessenger.maybeOf(context);
final wasActive = _workspace.activePaneId;
final index = _workspace.panes.indexWhere((p) => p.id == entry.paneId);
_closePane(entry.paneId);
if (messenger == null) return;
messenger
..hideCurrentSnackBar()
..showSnackBar(
SnackBar(
content: Text('Removed ${entry.title} from open chats'),
action: SnackBarAction(
label: 'Undo',
onPressed: () => _restoreToStack(entry, wasActive, index),
),
),
);
}
/// Undo: the chat comes back at its old place in the open-chat order.
void _restoreToStack(ChatStackEntry entry, String? wasActive, int index) {
if (!mounted || _workspace.holdsSession(entry.sessionId)) return;
_openedSessions[entry.sessionId] = entry.session;
_workspace.splitActive(entry.sessionId, ChatSplitAxis.horizontal);
final restored = _workspace.panes
.where((pane) => pane.sessionId == entry.sessionId)
.firstOrNull;
if (restored != null && index >= 0) {
_workspace.movePane(restored.id, index);
}
// The chat on screen stays on screen unless it was the one removed.
if (wasActive != null && wasActive != entry.paneId) {
final kept = _workspace.panes
.where((pane) => pane.id == wasActive)
.firstOrNull;
if (kept != null) _workspace.activate(kept.id);
}
}
}