Merge main: keep pane moves and the floating chat; Float sits beside the move items

This commit is contained in:
2026-11-10 13:09:31 +00:00
16 changed files with 824 additions and 51 deletions
@@ -3,50 +3,28 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../../../ui/motion/motion.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';
import 'chat_pane_move_motion.dart';
import 'chat_pane_move_shortcuts.dart';
import 'chat_pane_switch_motion.dart';
import 'chat_pane_backdrop.dart';
import 'chat_workspace_pane_scope.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';
typedef ChatWorkspacePaneBuilder =
Widget Function(BuildContext context, ChatWorkspacePane pane, bool active);
/// Describes the edge ownership of the pane currently being built.
class ChatWorkspacePaneScope extends InheritedWidget {
const ChatWorkspacePaneScope({
super.key,
required this.topEdgeShared,
required this.bottomEdgeShared,
required this.leftEdgeShared,
required this.rightEdgeShared,
required super.child,
});
final bool topEdgeShared;
final bool bottomEdgeShared;
final bool leftEdgeShared;
final bool rightEdgeShared;
static ChatWorkspacePaneScope? maybeOf(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<ChatWorkspacePaneScope>();
@override
bool updateShouldNotify(ChatWorkspacePaneScope oldWidget) =>
topEdgeShared != oldWidget.topEdgeShared ||
bottomEdgeShared != oldWidget.bottomEdgeShared ||
leftEdgeShared != oldWidget.leftEdgeShared ||
rightEdgeShared != oldWidget.rightEdgeShared;
}
/// All chat views are stable siblings, independent of the split tree. Moving a
/// divider or adding/removing a neighbouring split never reparents a chat view.
class ChatWorkspace extends StatefulWidget {
@@ -87,7 +65,7 @@ class ChatWorkspace extends StatefulWidget {
}
class _ChatWorkspaceState extends State<ChatWorkspace>
with SingleTickerProviderStateMixin {
with TickerProviderStateMixin {
final _focus = FocusNode(debugLabel: 'Chat workspace');
final Map<String, FocusScopeNode> _panes = {};
@@ -95,6 +73,9 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
/// floating window.
final Map<String, GlobalKey> _views = {};
late final ChatPaneSwitchMotion _motion;
late final ChatPaneMoveMotion _move = ChatPaneMoveMotion(vsync: this);
int _moveSerial = 0;
bool _tiled = false;
ChatWorkspaceGeometry? _geometry;
String? _lastActiveId;
Set<String> _visibleSessionIds = const {};
@@ -138,24 +119,18 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
primaryFocusIsTypingSurface()) {
return false;
}
final keyboard = HardwareKeyboard.instance;
final modifier =
keyboard.isControlPressed && !keyboard.isMetaPressed ||
defaultTargetPlatform == TargetPlatform.macOS &&
keyboard.isMetaPressed &&
!keyboard.isControlPressed;
if (!modifier || !keyboard.isShiftPressed || keyboard.isAltPressed) {
return false;
}
final direction = switch (event.logicalKey) {
LogicalKeyboardKey.arrowLeft => ChatPaneDirection.left,
LogicalKeyboardKey.arrowRight => ChatPaneDirection.right,
LogicalKeyboardKey.arrowUp => ChatPaneDirection.up,
LogicalKeyboardKey.arrowDown => ChatPaneDirection.down,
_ => null,
};
if (direction == null) return false;
final chord = chatPaneChord(event, HardwareKeyboard.instance);
if (chord == null) return false;
final (kind, direction) = chord;
final id = widget.controller.activePaneId;
if (kind == ChatPaneChord.move) {
// Only tiled panes move; the phone's one-at-a-time layout keeps the keys.
if (!_tiled) return false;
final target = id == null ? null : _geometry?.adjacent(id, direction);
if (target != null) widget.controller.swap(id!, target);
// Consumed at an outer edge too, like focusing.
return true;
}
final target = id == null ? null : _geometry?.neighbor(id, direction);
if (target != null) {
widget.controller.activate(target);
@@ -180,6 +155,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
_backdrop.dispose();
_motion.animation.removeStatusListener(_motionSettled);
_motion.dispose();
_move.dispose();
_focus.dispose();
for (final node in _panes.values) {
node.dispose();
@@ -203,9 +179,33 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
return const SizedBox.shrink();
}
final geometry = ChatWorkspaceGeometry(root, constraints.biggest);
final previous = _geometry;
_geometry = geometry;
final collapsed = widget.singlePane || geometry.collapsed;
final panes = widget.controller.panes;
final tiled = !collapsed && panes.length > 1;
if (_moveSerial != widget.controller.moveSerial) {
_moveSerial = widget.controller.moveSerial;
// Glide the swapped pair from their previous tiles.
_move.start(
tiled && _tiled && previous != null
? {
for (final id in widget.controller.movedPaneIds)
id: ?previous.panes[id],
}
: const {},
Motion.of(context, Motion.standard),
);
}
_tiled = tiled;
final moveTargets = <String, Map<ChatPaneDirection, String>>{
if (tiled)
for (final pane in panes)
pane.id: {
for (final direction in ChatPaneDirection.values)
direction: ?geometry.adjacent(pane.id, direction),
},
};
// Finish one joined loop before taking the latest requested role.
// Repeated taps/chords never tear the tape or duplicate a live chat.
final activeId =
@@ -304,14 +304,21 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
context: context,
backdrop: _backdrop,
motion: _motion,
move: _move,
controller: widget.controller,
geometry: geometry,
mobile: mobile,
collapsed: collapsed,
size: constraints.biggest,
panes: panes,
paneView: (pane) =>
_paneView(pane, mobile, collapsed, activeId, sharedEdges),
paneView: (pane) => _paneView(
pane,
mobile,
collapsed,
activeId,
sharedEdges,
moveTargets[pane.id],
),
);
final frame = widget.floatFrame;
if (frame == null) return surface;
@@ -341,6 +348,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
bool collapsed,
String? activeId,
Map<String, Set<String>> sharedEdges,
Map<ChatPaneDirection, String>? moveTargets,
) {
final outgoing = _motion.isRetainedOutgoing(pane.id);
final peek = mobile?.peekId == pane.id || outgoing;
@@ -368,6 +376,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
peek: peek,
mobile: mobile != null,
edges: sharedEdges[pane.id] ?? const {},
moveTargets: moveTargets,
),
),
),
@@ -385,6 +394,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
required bool peek,
required bool mobile,
required Set<String> edges,
Map<ChatPaneDirection, String>? moveTargets,
}) => KeyedSubtree(
key: _views.putIfAbsent(pane.id, () => GlobalKey(debugLabel: pane.id)),
child: FocusScope(
@@ -408,6 +418,8 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
bottomEdgeShared: edges.contains('bottom'),
leftEdgeShared: edges.contains('left'),
rightEdgeShared: edges.contains('right'),
movable: moveTargets != null,
moveTargets: moveTargets ?? const {},
child: Builder(
builder: (paneContext) =>
widget.paneBuilder(paneContext, pane, active),