Float one chat pane over the app and toggle it with Ctrl+Y / Cmd+Y

This commit is contained in:
2026-11-10 12:56:39 +00:00
parent 19aa726e7f
commit bb669aface
18 changed files with 1957 additions and 56 deletions
@@ -4,6 +4,8 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../../../ui/motion/quick_switch_animation.dart';
import 'chat_float_binding.dart';
import 'chat_float_host.dart';
import 'chat_workspace_controller.dart';
import 'chat_workspace_geometry.dart';
import 'chat_mobile_panes.dart';
@@ -59,6 +61,7 @@ class ChatWorkspace extends StatefulWidget {
this.animationStyle,
this.paneTitle,
this.onVisibleSessionIdsChanged,
this.floatFrame,
});
final ChatWorkspaceController controller;
final ChatWorkspacePaneBuilder paneBuilder;
@@ -71,6 +74,10 @@ class ChatWorkspace extends StatefulWidget {
final String Function(ChatWorkspacePane)? paneTitle;
final ValueChanged<Set<String>>? onVisibleSessionIdsChanged;
/// Offers the floating chat (see [ChatFloatHost]) in this frame; null for a
/// workspace without one. It shows only while the panes are not collapsed.
final ChatFloatFrame? floatFrame;
/// Keyboard navigation only: the owner can focus the target composer.
/// Pointer activation leaves text-selection and pointer focus alone.
final ValueChanged<ChatWorkspacePane>? onFocusPane;
@@ -83,6 +90,10 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
with SingleTickerProviderStateMixin {
final _focus = FocusNode(debugLabel: 'Chat workspace');
final Map<String, FocusScopeNode> _panes = {};
/// Each pane's view keeps its State when it moves into or out of the
/// floating window.
final Map<String, GlobalKey> _views = {};
late final ChatPaneSwitchMotion _motion;
ChatWorkspaceGeometry? _geometry;
String? _lastActiveId;
@@ -246,7 +257,11 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
: !collapsed || pane.id == activeId)
pane.sessionId,
});
final existing = panes.map((p) => p.id).toSet();
final floating = widget.floatFrame == null
? null
: widget.controller.floatingPane;
final existing = {...panes.map((p) => p.id), ?floating?.id};
_views.removeWhere((id, _) => !existing.contains(id));
for (final id
in _panes.keys.where((id) => !existing.contains(id)).toList()) {
final node = _panes.remove(id)!;
@@ -285,7 +300,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
edge,
},
};
return chatWorkspaceSurface(
final surface = chatWorkspaceSurface(
context: context,
backdrop: _backdrop,
motion: _motion,
@@ -298,6 +313,23 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
paneView: (pane) =>
_paneView(pane, mobile, collapsed, activeId, sharedEdges),
);
final frame = widget.floatFrame;
if (frame == null) return surface;
return ChatFloatHost(
controller: widget.controller,
frame: frame,
enabled: !widget.singlePane,
title: floating == null
? ''
: widget.paneTitle?.call(floating) ?? floating.sessionId,
content: floating == null ? null : _floatView(floating),
scope: floating == null ? null : _panes[floating.id],
focusedPane: () => widget.controller.panes
.where((pane) => _panes[pane.id]?.hasFocus ?? false)
.firstOrNull,
onFocusPane: widget.onFocusPane,
child: surface,
);
},
),
),
@@ -330,44 +362,59 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
FocusManager.instance.primaryFocus?.unfocus();
widget.controller.activate(pane.id);
},
child: FocusScope(
node: _panes.putIfAbsent(
pane.id,
() => FocusScopeNode(debugLabel: pane.id),
),
onFocusChange: (focused) {
if (focused && mobile == null) {
widget.controller.activate(pane.id);
}
},
child: Listener(
behavior: HitTestBehavior.translucent,
// A press in the peek scrolls or taps; the tap alone activates.
onPointerDown: peek
? null
: (_) => widget.controller.activate(pane.id),
child: Semantics(
identifier: 'chat-pane-${pane.id}',
container: true,
sortKey: mobile == null ? null : const OrdinalSortKey(0),
child: ChatWorkspacePaneScope(
topEdgeShared: sharedEdges[pane.id]?.contains('top') ?? false,
bottomEdgeShared:
sharedEdges[pane.id]?.contains('bottom') ?? false,
leftEdgeShared:
sharedEdges[pane.id]?.contains('left') ?? false,
rightEdgeShared:
sharedEdges[pane.id]?.contains('right') ?? false,
child: Builder(
builder: (paneContext) =>
widget.paneBuilder(paneContext, pane, active),
),
),
),
),
child: _paneContent(
pane,
active: active,
peek: peek,
mobile: mobile != null,
edges: sharedEdges[pane.id] ?? const {},
),
),
),
);
}
/// The floating chat's view: the same keyed content as in the tiling, so
/// floating and docking move it without rebuilding the chat.
Widget _floatView(ChatWorkspacePane pane) =>
_paneContent(pane, active: true, peek: false, mobile: false, edges: {});
Widget _paneContent(
ChatWorkspacePane pane, {
required bool active,
required bool peek,
required bool mobile,
required Set<String> edges,
}) => KeyedSubtree(
key: _views.putIfAbsent(pane.id, () => GlobalKey(debugLabel: pane.id)),
child: FocusScope(
node: _panes.putIfAbsent(
pane.id,
() => FocusScopeNode(debugLabel: pane.id),
),
onFocusChange: (focused) {
if (focused && !mobile) widget.controller.activate(pane.id);
},
child: Listener(
behavior: HitTestBehavior.translucent,
// A press in the peek scrolls or taps; the tap alone activates.
onPointerDown: peek ? null : (_) => widget.controller.activate(pane.id),
child: Semantics(
identifier: 'chat-pane-${pane.id}',
container: true,
sortKey: mobile ? const OrdinalSortKey(0) : null,
child: ChatWorkspacePaneScope(
topEdgeShared: edges.contains('top'),
bottomEdgeShared: edges.contains('bottom'),
leftEdgeShared: edges.contains('left'),
rightEdgeShared: edges.contains('right'),
child: Builder(
builder: (paneContext) =>
widget.paneBuilder(paneContext, pane, active),
),
),
),
),
),
);
}