diff --git a/app/lib/features/chat/chat_screen_workspace.dart b/app/lib/features/chat/chat_screen_workspace.dart index 45d17bc1..0915a10e 100644 --- a/app/lib/features/chat/chat_screen_workspace.dart +++ b/app/lib/features/chat/chat_screen_workspace.dart @@ -6,6 +6,7 @@ mixin _ChatScreenWorkspace on State { ChatComposerFocusRequests get _composerFocus; JsonMap? _rowFor(String id); void _back(); + bool get _pageOpen; Widget _thread( String selected, VoidCallback onBack, { @@ -193,8 +194,15 @@ mixin _ChatScreenWorkspace on State { if (id.isEmpty) return; _openedSessions[id] = session; _workspaceVisible = true; + if (!_pageOpen && showsListBesideDetail(context)) _usedWorkspace = true; _workspace.splitActive(id, axis); - _composerFocus.request(id); + if (showsListBesideDetail(context) || + chatSelectionFocusesComposer(const {})) { + _composerFocus.request(id); + } else { + _composerFocus.cancel(); + FocusManager.instance.primaryFocus?.unfocus(); + } } void _openBeside(JsonMap session) => @@ -225,11 +233,34 @@ mixin _ChatScreenWorkspace on State { }, ); + void _addPane(BuildContext context) { + final opened = _workspace.panes.map((pane) => pane.sessionId).toSet(); + final available = _sessionsForSidebar.sessions + .where((row) => !opened.contains('${row['id'] ?? ''}')) + .toList(); + showChatPanePicker( + context, + title: available.isEmpty + ? 'All available chats are already open' + : 'Add chat pane', + panes: [ + for (final row in available) + (id: '${row['id']}', title: chatSessionTitle(row)), + ], + activeId: null, + onSelected: (id) => + _openBelow(available.firstWhere((row) => row['id'] == id)), + ); + } + Widget _workspaceView() => ChatWorkspace( key: _workspaceKey, controller: _workspace, shortcutsEnabled: _workspaceVisible, singlePane: !showsListBesideDetail(context), + mobilePeeks: !showsListBesideDetail(context), + paneTitle: (pane) => + '${_rowFor(pane.sessionId)?['title'] ?? pane.sessionId}', onFocusPane: (pane) => _composerFocus.request(pane.sessionId), paneBuilder: (context, pane, active) => Semantics( selected: active, diff --git a/app/lib/features/chat/conversation/chat_pane_picker.dart b/app/lib/features/chat/conversation/chat_pane_picker.dart index 07986a85..03eec591 100644 --- a/app/lib/features/chat/conversation/chat_pane_picker.dart +++ b/app/lib/features/chat/conversation/chat_pane_picker.dart @@ -9,13 +9,14 @@ Future showChatPanePicker( required List<({String id, String title})> panes, required String? activeId, required ValueChanged onSelected, + String title = 'Open chats', }) async { final String? selected; if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) { selected = await showCupertinoModalPopup( context: context, builder: (context) => CupertinoActionSheet( - title: const Text('Open chats'), + title: Text(title), actions: [ for (final pane in panes) CupertinoActionSheetAction( @@ -34,7 +35,7 @@ Future showChatPanePicker( selected = await showDialog( context: context, builder: (context) => SimpleDialog( - title: const Text('Open chats'), + title: Text(title), children: [ for (final pane in panes) SimpleDialogOption( diff --git a/app/lib/features/chat/screen.dart b/app/lib/features/chat/screen.dart index 0d7f895e..8ac22f00 100644 --- a/app/lib/features/chat/screen.dart +++ b/app/lib/features/chat/screen.dart @@ -30,6 +30,7 @@ import 'conversation/composer_selection_focus.dart'; import 'data/chat_repository.dart'; import 'domain/chat_commands.dart'; import 'domain/chat_cycle.dart'; +import 'domain/chat_sessions.dart'; import 'ui/sessions/chat_sessions_body.dart'; import 'ui/sessions/chat_sessions_controller.dart'; import 'ui/sessions/chat_sessions_screen.dart'; @@ -364,6 +365,8 @@ class _ChatScreenState extends State with _ChatScreenWorkspace { /// On a phone the open chat is a real page above the main screen. final DetailPageHost _page = DetailPageHost(); + @override + bool get _pageOpen => _page.open; @override void didUpdateWidget(covariant ChatScreen oldWidget) { @@ -429,13 +432,22 @@ class _ChatScreenState extends State with _ChatScreenWorkspace { onNextChat: _nextAfter(selected) != null ? () => _openNext(selected) : null, - showBackButton: pane == null ? null : !showsListBesideDetail(context), - sidebarControl: pane == null || !showsListBesideDetail(context) + showBackButton: pane == null + ? null + : _page.open || !showsListBesideDetail(context), + sidebarControl: + pane == null || _page.open || !showsListBesideDetail(context) ? null : ChatSidebarButton(mode: _sidebarMode, onChanged: _setSidebarMode), paneControls: pane == null ? const [] : [ + ChatBarAction( + label: 'Add chat pane', + onPressed: () => _addPane(paneContext ?? context), + materialIcon: Icons.add_box_outlined, + cupertinoIcon: CupertinoIcons.plus_square, + ), if (_workspace.paneCount > 1) ChatBarAction( label: 'Open chats (${_workspace.paneCount})', @@ -471,7 +483,7 @@ class _ChatScreenState extends State with _ChatScreenWorkspace { // A phone opens a chat as a real Navigator page with stock Back. A wide // window keeps the destination rail and the chat list beside the open // chat, which has no Back: another row, `/close` or a route change swaps it. - final beside = showsListBesideDetail(context); + final beside = !_page.open && showsListBesideDetail(context); if (beside && selected != null) _usedWorkspace = true; _page.sync( context, @@ -480,7 +492,7 @@ class _ChatScreenState extends State with _ChatScreenWorkspace { onClosed: _back, builder: (context) => selected == null ? const SizedBox.shrink() - : _thread(selected, () => Navigator.of(context).maybePop()), + : ShellBar(barless: true, child: _workspaceView()), ); // The session list pads its first row by the bar's height itself, so it // scrolls behind the shell's floating bar like the other lists. @@ -492,7 +504,7 @@ class _ChatScreenState extends State with _ChatScreenWorkspace { folds: _folds, onOpen: _openBySelection, onOpenBeside: beside ? _openBeside : null, - onOpenBelow: beside ? _openBelow : null, + onOpenBelow: _openBelow, onShortcutOpen: _openByShortcut, onSessions: _adoptRows, activeSessionId: selected, @@ -515,6 +527,7 @@ class _ChatScreenState extends State with _ChatScreenWorkspace { child: ShellBar( active: selected != null, barless: true, + hideNavigation: true, child: Stack( fit: StackFit.expand, children: [ diff --git a/app/lib/features/chat/workspace/chat_mobile_panes.dart b/app/lib/features/chat/workspace/chat_mobile_panes.dart new file mode 100644 index 00000000..82abfb17 --- /dev/null +++ b/app/lib/features/chat/workspace/chat_mobile_panes.dart @@ -0,0 +1,100 @@ +import 'dart:math' as math; +import 'package:flutter/widgets.dart'; +import 'chat_workspace_controller.dart'; + +/// A phone presentation only: saved split axes and ratios are left untouched. +class ChatMobilePanes { + ChatMobilePanes({ + required List panes, + required String activeId, + required String? peekId, + required Size size, + }) { + final active = panes.firstWhere((pane) => pane.id == activeId); + final peek = + panes + .where((pane) => pane.id == peekId && pane.id != activeId) + .firstOrNull ?? + panes.where((pane) => pane.id != activeId).firstOrNull; + if (peek == null) { + rects[active.id] = Offset.zero & size; + return; + } + this.peekId = peek.id; + const gap = 6.0; + final available = math.max(0.0, size.height - gap); + final peekHeight = available * .2; + final activeHeight = available - peekHeight; + final activeFirst = panes.indexOf(active) < panes.indexOf(peek); + rects[activeFirst ? active.id : peek.id] = Rect.fromLTWH( + 0, + 0, + size.width, + activeFirst ? activeHeight : peekHeight, + ); + final topHeight = activeFirst ? activeHeight : peekHeight; + rects[activeFirst ? peek.id : active.id] = Rect.fromLTWH( + 0, + topHeight + gap, + size.width, + activeFirst ? peekHeight : activeHeight, + ); + } + final rects = {}; + String? peekId; +} + +/// Keep a peek's full header/transcript layout available without squeezing its +/// composer into a tiny viewport. The clipped preview cannot take input focus. +class ChatMobilePaneViewport extends StatelessWidget { + const ChatMobilePaneViewport({ + super.key, + required this.peek, + required this.child, + required this.height, + required this.onActivate, + required this.label, + required this.paneId, + }); + final bool peek; + final double height; + final Widget child; + final VoidCallback onActivate; + final String label; + final String paneId; + @override + Widget build(BuildContext context) => ClipRect( + child: Stack( + fit: StackFit.expand, + children: [ + OverflowBox( + alignment: Alignment.topCenter, + minHeight: height, + maxHeight: peek ? math.max(height, 300) : height, + child: SizedBox( + height: peek ? math.max(height, 300) : height, + child: ExcludeFocus( + excluding: peek, + child: ExcludeSemantics( + excluding: peek, + child: IgnorePointer(ignoring: peek, child: child), + ), + ), + ), + ), + if (peek) + Semantics( + key: ValueKey('chat-peek-$paneId'), + identifier: 'chat-peek-$paneId', + container: true, + label: 'Expand $label', + button: true, + child: GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: onActivate, + ), + ), + ], + ), + ); +} diff --git a/app/lib/features/chat/workspace/chat_workspace.dart b/app/lib/features/chat/workspace/chat_workspace.dart index f8ff621b..81f52ce6 100644 --- a/app/lib/features/chat/workspace/chat_workspace.dart +++ b/app/lib/features/chat/workspace/chat_workspace.dart @@ -5,6 +5,7 @@ import 'package:flutter/services.dart'; import 'chat_workspace_controller.dart'; import 'chat_workspace_divider.dart'; import 'chat_workspace_geometry.dart'; +import 'chat_mobile_panes.dart'; export 'chat_workspace_controller.dart'; export 'chat_workspace_geometry.dart' show ChatPaneDirection; @@ -22,6 +23,8 @@ class ChatWorkspace extends StatefulWidget { this.onFocusPane, this.shortcutsEnabled = true, this.singlePane = false, + this.mobilePeeks = false, + this.paneTitle, }); final ChatWorkspaceController controller; final ChatWorkspacePaneBuilder paneBuilder; @@ -29,6 +32,8 @@ class ChatWorkspace extends StatefulWidget { /// Keeps the retained layout while presenting only the active chat. final bool singlePane; + final bool mobilePeeks; + final String Function(ChatWorkspacePane)? paneTitle; /// Keyboard navigation only: the owner can focus the target composer. /// Pointer activation leaves text-selection and pointer focus alone. @@ -42,6 +47,8 @@ class _ChatWorkspaceState extends State { final _focus = FocusNode(debugLabel: 'Chat workspace'); final Map _panes = {}; ChatWorkspaceGeometry? _geometry; + String? _lastActiveId; + String? _peekId; @override void initState() { @@ -115,6 +122,23 @@ class _ChatWorkspaceState extends State { _geometry = geometry; final collapsed = widget.singlePane || geometry.collapsed; final panes = widget.controller.panes; + final activeId = widget.controller.activePaneId; + if (_lastActiveId != activeId) { + _peekId = _lastActiveId; + _lastActiveId = activeId; + } + final mobile = widget.mobilePeeks && activeId != null + ? ChatMobilePanes( + panes: panes, + activeId: activeId, + peekId: _peekId, + size: constraints.biggest, + ) + : null; + final duration = + mobile != null && !MediaQuery.disableAnimationsOf(context) + ? const Duration(milliseconds: 220) + : Duration.zero; final existing = panes.map((p) => p.id).toSet(); for (final id in _panes.keys.where((id) => !existing.contains(id)).toList()) { @@ -126,37 +150,60 @@ class _ChatWorkspaceState extends State { clipBehavior: Clip.hardEdge, children: [ for (final pane in panes) - Positioned.fromRect( + AnimatedPositioned.fromRect( + duration: duration, + curve: Curves.easeInOutCubic, key: ValueKey('chat-workspace-${pane.id}'), - rect: collapsed - ? Offset.zero & constraints.biggest - : geometry.panes[pane.id]!, + rect: + mobile?.rects[pane.id] ?? + (collapsed + ? Offset.zero & constraints.biggest + : geometry.panes[pane.id]!), child: Offstage( - offstage: - collapsed && pane.id != widget.controller.activePaneId, + offstage: mobile != null + ? !mobile.rects.containsKey(pane.id) + : collapsed && + pane.id != widget.controller.activePaneId, child: ExcludeFocus( excluding: collapsed && pane.id != widget.controller.activePaneId, - child: FocusScope( - node: _panes.putIfAbsent( - pane.id, - () => FocusScopeNode(debugLabel: pane.id), - ), - onFocusChange: (focused) { - if (focused) widget.controller.activate(pane.id); + child: ChatMobilePaneViewport( + peek: mobile?.peekId == pane.id, + label: widget.paneTitle?.call(pane) ?? pane.sessionId, + paneId: pane.id, + height: + (mobile?.rects[pane.id] ?? + (collapsed + ? Offset.zero & constraints.biggest + : geometry.panes[pane.id]!)) + .height, + onActivate: () { + FocusManager.instance.primaryFocus?.unfocus(); + widget.controller.activate(pane.id); }, - child: Listener( - behavior: HitTestBehavior.translucent, - onPointerDown: (_) => - widget.controller.activate(pane.id), - child: Semantics( - identifier: 'chat-pane-${pane.id}', - container: true, - child: widget.paneBuilder( - context, - pane, - pane.id == widget.controller.activePaneId, + child: FocusScope( + node: _panes.putIfAbsent( + pane.id, + () => FocusScopeNode(debugLabel: pane.id), + ), + onFocusChange: (focused) { + if (focused && !widget.mobilePeeks) { + widget.controller.activate(pane.id); + } + }, + child: Listener( + behavior: HitTestBehavior.translucent, + onPointerDown: (_) => + widget.controller.activate(pane.id), + child: Semantics( + identifier: 'chat-pane-${pane.id}', + container: true, + child: widget.paneBuilder( + context, + pane, + pane.id == widget.controller.activePaneId, + ), ), ), ), @@ -164,7 +211,7 @@ class _ChatWorkspaceState extends State { ), ), ), - if (!collapsed) + if (!collapsed && mobile == null) for (final divider in geometry.dividers) Positioned.fromRect( key: ValueKey('chat-workspace-${divider.split.id}'), diff --git a/app/notes/mobile-chat-peeks.md b/app/notes/mobile-chat-peeks.md new file mode 100644 index 00000000..c5f38523 --- /dev/null +++ b/app/notes/mobile-chat-peeks.md @@ -0,0 +1,13 @@ +# Mobile chat panes + +Phones can add a chat with the header's **Add chat pane** action (in More if space is tight). The session list also offers **Open below** on narrow windows. The native picker lists chats not already open. + +Narrow windows show two retained conversations stacked: the active pane gets80% of the available height and one inactive preview gets20%, separated by6 logical pixels. Tapping a preview animates their heights over220ms. Reduced-motion settings switch immediately. An accessible preview names the chat it will expand. Pointer switching unfocuses inputs and does not request the new composer's keyboard. + +With more than two retained chats, the active pane and previous active pane are visible; **Open chats** accesses every retained pane. The presentation never rewrites stored desktop split ratios. Every thread remains a stable keyed sibling, preserving drafts and transcript state. A small preview clips a full-height layout instead of squeezing its composer into a tiny viewport. + +A chat first opened on a phone stays in its native full-screen detail route while adding panes or unfolding. It already uses the full width; Back returns to the list. The sidebar control is absent on this full-screen route. A chat first opened in the wide list/detail workspace keeps the existing sidebar expanded/compact/hidden control and changes to mobile previews when folded. The destination bar stays hidden while this narrow chat workspace is open, so it cannot overlap either composer or preview. + +Checks: bounded analysis clean;7 real-screen split tests passed, including first-phone-split draft/state identity, exactly one initial Back control, large text with300px keyboard inset and desktop/narrow restoration;23 workspace/controller/persistence tests passed, including intermediate animation geometry, reduced motion and three retained panes;10 list-shortcut tests passed. Tests use the memory watchdog. + +Rendered browser evidence: `/private/tmp/mobile-panes-phone-final/` (Material/light560x1000, Add pane, draft retention, real peek taps, no native input focus after a peek switch, unfold880); `/private/tmp/mobile-panes-unfolded-final/` (Cupertino/dark880x1100 hidden sidebar, fold560x1000, switch). All8 final screenshots/contact sheet were inspected; reports have no errors. The phone film contact sheet and10 frame files show the actual220ms transition, including intermediate frames. Test browsers/servers exited. No physical Fold testing, backend change or deployment was performed in this lane. diff --git a/app/test/features/chat/chat_split_integration_test.dart b/app/test/features/chat/chat_split_integration_test.dart index 7e2fc5f0..f2ecd5cc 100644 --- a/app/test/features/chat/chat_split_integration_test.dart +++ b/app/test/features/chat/chat_split_integration_test.dart @@ -79,6 +79,90 @@ Future _split(WidgetTester tester, String id, String action) async { } void main() { + testWidgets('phone peeks fit a small keyboard viewport at large text', ( + tester, + ) async { + SharedPreferences.setMockInitialValues({}); + tester.view.physicalSize = const Size(560, 700); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + final gateway = _Gateway()..history = (_) async => chatPage([]); + addTearDown(gateway.close); + await tester.pumpWidget( + MaterialApp( + builder: (context, child) => MediaQuery( + data: MediaQuery.of( + context, + ).copyWith(textScaler: TextScaler.linear(2)), + child: child!, + ), + home: Scaffold(body: ChatScreen(gateway: gateway)), + ), + ); + await tester.pumpAndSettle(); + await tester.tap(find.text('Chat a').first); + await tester.pumpAndSettle(); + final controller = tester + .widget(find.byType(ChatWorkspace)) + .controller; + controller.splitActive('b', ChatSplitAxis.vertical); + await tester.pumpAndSettle(); + tester.view.viewInsets = const FakeViewPadding(bottom: 300); + await tester.pumpAndSettle(); + expect(_thread('a'), findsOneWidget); + expect(_thread('b'), findsOneWidget); + expect(tester.takeException(), isNull); + }); + testWidgets('phone can add a second chat without losing its first draft', ( + tester, + ) async { + SharedPreferences.setMockInitialValues({}); + tester.view.physicalSize = const Size(560, 1000); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + final gateway = _Gateway()..history = (_) async => chatPage([]); + addTearDown(gateway.close); + await tester.pumpWidget(_app(gateway)); + await tester.pumpAndSettle(); + await tester.tap(find.text('Chat a').first); + await tester.pumpAndSettle(); + expect(find.byTooltip('Back').hitTestable(), findsOneWidget); + final stateA = tester.state(_thread('a')); + await tester.enterText(_input('a'), 'Phone draft A'); + await tester.pumpAndSettle(); + final add = find.byTooltip('Add chat pane').hitTestable(); + if (add.evaluate().isEmpty) { + await tester.tap(find.byTooltip('More actions').first); + await tester.pumpAndSettle(); + await tester.tap(find.text('Add chat pane')); + } else { + await tester.tap(add); + } + await tester.pumpAndSettle(); + await tester.tap(find.text('Chat b')); + await tester.pumpAndSettle(); + expect(_thread('a'), findsOneWidget); + expect(_thread('b'), findsOneWidget); + expect(tester.state(_thread('a')), same(stateA)); + expect( + tester.widget(_input('a')).controller.text, + 'Phone draft A', + ); + final workspace = tester.widget(find.byType(ChatWorkspace)); + expect(workspace.controller.paneCount, 2); + expect(workspace.controller.activePane?.sessionId, 'b'); + final first = workspace.controller.panes.first.id; + await tester.tap(find.byKey(ValueKey('chat-peek-$first'))); + await tester.pumpAndSettle(); + expect(workspace.controller.activePane?.sessionId, 'a'); + expect( + tester.widget(_input('b')).focusNode.hasFocus, + isFalse, + ); + expect(tester.state(_thread('a')), same(stateA)); + expect(tester.takeException(), isNull); + }); + testWidgets('compact and hidden sidebar preserve panes and drafts', ( tester, ) async { @@ -147,12 +231,11 @@ void main() { tester.view.physicalSize = const Size(560, 1000); await tester.pumpAndSettle(); expect(_thread('c'), findsOneWidget); - expect(_thread('a'), findsNothing); - expect(_thread('b'), findsNothing); + expect(find.byType(ChatThreadView), findsNWidgets(2)); tester.view.physicalSize = const Size(390, 844); await tester.pumpAndSettle(); expect(_thread('c'), findsOneWidget); - expect(_thread('a'), findsNothing); + expect(find.byType(ChatThreadView), findsNWidgets(2)); expect(tester.state(_thread('a', offstage: true)), same(stateA)); tester.view.physicalSize = const Size(1800, 1000); await tester.pumpAndSettle(); diff --git a/app/test/features/chat/workspace/chat_mobile_panes_test.dart b/app/test/features/chat/workspace/chat_mobile_panes_test.dart new file mode 100644 index 00000000..a73a2997 --- /dev/null +++ b/app/test/features/chat/workspace/chat_mobile_panes_test.dart @@ -0,0 +1,154 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart'; + +Widget _host( + ChatWorkspaceController controller, { + bool mobile = true, + bool reduced = false, +}) => MaterialApp( + home: MediaQuery( + data: MediaQueryData(disableAnimations: reduced), + child: SizedBox( + width: 560, + height: 800, + child: ChatWorkspace( + controller: controller, + singlePane: mobile, + mobilePeeks: mobile, + paneBuilder: (_, pane, active) => _Draft(key: ValueKey(pane.sessionId)), + ), + ), + ), +); + +class _Draft extends StatefulWidget { + const _Draft({super.key}); + @override + State<_Draft> createState() => _DraftState(); +} + +class _DraftState extends State<_Draft> { + final controller = TextEditingController(); + @override + void dispose() { + controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) => + Material(child: TextField(controller: controller)); +} + +Finder _rect(String pane) => find.byKey(ValueKey('chat-workspace-$pane')); +void main() { + testWidgets( + 'mobile peeks animate80/20 and retain drafts and saved geometry', + (tester) async { + tester.view.physicalSize = const Size(560, 800); + tester.view.devicePixelRatio = 1; + tester.platformDispatcher.accessibilityFeaturesTestValue = + const FakeAccessibilityFeatures(disableAnimations: false); + addTearDown( + tester.platformDispatcher.clearAccessibilityFeaturesTestValue, + ); + addTearDown(tester.view.reset); + final controller = ChatWorkspaceController()..open('a'); + final first = controller.activePaneId!; + controller.splitActive('b', ChatSplitAxis.horizontal); + final second = controller.activePaneId!; + controller.resize(controller.root!.id, .31); + final saved = controller.snapshot()!.encode(); + await tester.pumpWidget(_host(controller)); + await tester.pumpAndSettle(); + final aState = tester.state(find.byKey(const ValueKey('a'))); + final bState = tester.state(find.byKey(const ValueKey('b'))); + await tester.enterText( + find.descendant( + of: find.byKey(const ValueKey('b')), + matching: find.byType(EditableText), + ), + 'Draft b', + ); + final oldHeight = tester.getSize(_rect(first)).height; + expect(oldHeight, closeTo((800 - 6) * .2, 1)); + expect(tester.getSize(_rect(second)).height, closeTo((800 - 6) * .8, 1)); + await tester.pumpAndSettle(); + final positionState = tester.state(_rect(first)); + await tester.tap(find.byKey(ValueKey('chat-peek-$first'))); + expect( + controller.activePane?.sessionId, + 'a', + reason: 'tap activates peek immediately', + ); + await tester.pump(); + expect(tester.state(_rect(first)), same(positionState)); + await tester.pump(const Duration(milliseconds: 100)); + expect( + tester.widget(_rect(first)).duration, + const Duration(milliseconds: 220), + ); + final intermediate = tester.getSize(_rect(first)).height; + expect(intermediate, greaterThan(oldHeight)); + expect(intermediate, lessThan((800 - 6) * .8)); + await tester.pumpAndSettle(); + expect(controller.activePane?.sessionId, 'a'); + expect(tester.getSize(_rect(first)).height, closeTo((800 - 6) * .8, 1)); + expect(tester.state(find.byKey(const ValueKey('a'))), same(aState)); + expect(tester.state(find.byKey(const ValueKey('b'))), same(bState)); + expect((bState as _DraftState).controller.text, 'Draft b'); + expect( + tester + .widget( + find.descendant( + of: find.byKey(const ValueKey('b')), + matching: find.byType(EditableText), + ), + ) + .focusNode + .hasFocus, + isFalse, + ); + controller.activate(second); + await tester.pumpAndSettle(); + expect(controller.snapshot()!.encode(), saved); + await tester.pumpWidget(_host(controller, mobile: false)); + await tester.pumpAndSettle(); + expect(tester.state(find.byKey(const ValueKey('a'))), same(aState)); + expect( + tester.getSize(_rect(first)).width, + lessThan(tester.getSize(_rect(second)).width), + ); + await tester.pumpWidget(const SizedBox()); + controller.dispose(); + }, + ); + testWidgets( + 'three retained panes expose active+previous and honor reduced motion', + (tester) async { + tester.view.physicalSize = const Size(560, 800); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + final controller = ChatWorkspaceController()..open('a'); + final first = controller.activePaneId!; + controller.splitActive('b', ChatSplitAxis.horizontal); + controller.splitActive('c', ChatSplitAxis.vertical); + await tester.pumpWidget(_host(controller, reduced: true)); + await tester.pumpAndSettle(); + expect(find.byType(_Draft), findsNWidgets(2)); + final third = controller.activePaneId!; + controller.activate(first); + await tester.pump(); + expect(tester.getSize(_rect(first)).height, closeTo((800 - 6) * .8, 1)); + expect(find.byType(_Draft), findsNWidgets(2)); + expect(find.byType(_Draft, skipOffstage: false), findsNWidgets(3)); + controller.activate(third); + await tester.pump(); + expect(tester.getSize(_rect(third)).height, closeTo((800 - 6) * .8, 1)); + expect(tester.takeException(), isNull); + await tester.pumpWidget(const SizedBox()); + controller.dispose(); + }, + ); +}