Put the active chat on center stage with Ctrl/Cmd+E

This commit is contained in:
2026-11-10 12:57:39 +00:00
parent 19aa726e7f
commit e033d4e176
10 changed files with 653 additions and 83 deletions
@@ -4,6 +4,9 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../../../ui/motion/quick_switch_animation.dart';
import 'chat_center_stage_layout.dart';
import 'chat_center_stage_motion.dart';
import 'chat_center_stage_strip.dart';
import 'chat_workspace_controller.dart';
import 'chat_workspace_geometry.dart';
import 'chat_mobile_panes.dart';
@@ -59,6 +62,8 @@ class ChatWorkspace extends StatefulWidget {
this.animationStyle,
this.paneTitle,
this.onVisibleSessionIdsChanged,
this.centerStage,
this.paneColor,
});
final ChatWorkspaceController controller;
final ChatWorkspacePaneBuilder paneBuilder;
@@ -71,6 +76,13 @@ class ChatWorkspace extends StatefulWidget {
final String Function(ChatWorkspacePane)? paneTitle;
final ValueChanged<Set<String>>? onVisibleSessionIdsChanged;
/// While true on a wide window, the active chat takes center stage and the
/// others line up beside it (see [ChatCenterStageLayout]).
final ValueListenable<bool>? centerStage;
/// A pane's chat colour, for its strip beside the stage.
final Color? Function(ChatWorkspacePane)? paneColor;
/// Keyboard navigation only: the owner can focus the target composer.
/// Pointer activation leaves text-selection and pointer focus alone.
final ValueChanged<ChatWorkspacePane>? onFocusPane;
@@ -80,10 +92,11 @@ class ChatWorkspace extends StatefulWidget {
}
class _ChatWorkspaceState extends State<ChatWorkspace>
with SingleTickerProviderStateMixin {
with TickerProviderStateMixin {
final _focus = FocusNode(debugLabel: 'Chat workspace');
final Map<String, FocusScopeNode> _panes = {};
late final ChatPaneSwitchMotion _motion;
late final ChatCenterStageMotion _stage = ChatCenterStageMotion(vsync: this);
ChatWorkspaceGeometry? _geometry;
String? _lastActiveId;
Set<String> _visibleSessionIds = const {};
@@ -145,7 +158,12 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
};
if (direction == null) return false;
final id = widget.controller.activePaneId;
final target = id == null ? null : _geometry?.neighbor(id, direction);
final stage = _stage.stage;
final target = id == null
? null
: stage != null
? stage.neighbor(id, direction)
: _geometry?.neighbor(id, direction);
if (target != null) {
widget.controller.activate(target);
final pane = widget.controller.activePane!;
@@ -169,6 +187,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
_backdrop.dispose();
_motion.animation.removeStatusListener(_motionSettled);
_motion.dispose();
_stage.dispose();
_focus.dispose();
for (final node in _panes.values) {
node.dispose();
@@ -183,6 +202,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
listenable: Listenable.merge([
widget.controller,
QuickSwitchAnimationController.instance,
?widget.centerStage,
]),
builder: (context, _) => LayoutBuilder(
builder: (context, constraints) {
@@ -239,6 +259,17 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
QuickSwitchAnimationController.instance.value,
);
}
final engaged = !collapsed && mobile == null;
_stage.layout(
engaged: engaged,
split: geometry.panes,
stage: engaged && widget.centerStage?.value == true
? ChatCenterStageLayout.of(constraints.biggest, [
for (final pane in panes) pane.id,
], activeId)
: null,
animate: !MediaQuery.disableAnimationsOf(context),
);
_reportVisible({
for (final pane in panes)
if (mobile != null
@@ -281,6 +312,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
for (final edge in const ['top', 'bottom', 'left', 'right'])
if (!collapsed &&
mobile == null &&
_stage.stage == null &&
sharesEdge(entry.value, edge))
edge,
},
@@ -289,6 +321,8 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
context: context,
backdrop: _backdrop,
motion: _motion,
stage: _stage,
stageStrip: _strip,
controller: widget.controller,
geometry: geometry,
mobile: mobile,
@@ -303,6 +337,22 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
),
);
Widget _strip(ChatWorkspacePane pane) => ChatCenterStageStrip(
paneId: pane.id,
title: widget.paneTitle?.call(pane) ?? pane.sessionId,
color: widget.paneColor?.call(pane),
onSelected: () {
FocusManager.instance.primaryFocus?.unfocus();
widget.controller.activate(pane.id);
// Choosing a strip is choosing that chat: its composer takes the
// keyboard once it is on stage.
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted || widget.controller.activePaneId != pane.id) return;
widget.onFocusPane?.call(pane);
});
},
);
Widget _paneView(
ChatWorkspacePane pane,
ChatMobilePanes? mobile,