diff --git a/app/lib/features/chat/conversation/chat_thread_view.dart b/app/lib/features/chat/conversation/chat_thread_view.dart index fd27edb7..35abf0e4 100644 --- a/app/lib/features/chat/conversation/chat_thread_view.dart +++ b/app/lib/features/chat/conversation/chat_thread_view.dart @@ -82,6 +82,7 @@ import 'chat_permission_card_model.dart'; import 'chat_permission_group.dart'; import 'chat_question_group.dart'; import 'chat_transcript_card.dart'; +import '../workspace/chat_workspace_pane_scope.dart'; /// One read-only conversation: the controller's transcript in the order the /// server reports it, rendered by the existing [ChatMessageView]. @@ -256,6 +257,7 @@ class _ChatThreadViewState extends State { bool _filesVisible = false; bool _filesPrefsLoaded = false; bool _filesSheetOpen = false; + double? _reportedCenterStageFilesWidth; FilesController _newFilesController() => FilesController( gateway: widget.gateway, @@ -277,6 +279,7 @@ class _ChatThreadViewState extends State { _filesVisible = visible; _filesPrefsLoaded = true; }); + _reportCenterStageFilesWidth(); if (visible && MediaQuery.sizeOf(context).width < 700) { WidgetsBinding.instance.addPostFrameCallback((_) { if (mounted) _openFilesSheet(); @@ -288,10 +291,26 @@ class _ChatThreadViewState extends State { final next = !_filesVisible; if (!mounted) return; setState(() => _filesVisible = next); + _reportCenterStageFilesWidth(); unawaited(_filesPreferences.setVisible(next)); if (next && MediaQuery.sizeOf(context).width < 700) _openFilesSheet(); } + void _reportCenterStageFilesWidth() { + final scope = ChatWorkspacePaneScope.maybeOf(context); + final width = _filesVisible && MediaQuery.sizeOf(context).width >= 700 + ? filesPanelWidth(MediaQuery.sizeOf(context).width) + : 0.0; + if (scope?.onPreferredWidthChanged == null || + _reportedCenterStageFilesWidth == width) { + return; + } + _reportedCenterStageFilesWidth = width; + WidgetsBinding.instance.addPostFrameCallback((_) { + if (mounted) scope?.onPreferredWidthChanged?.call(width); + }); + } + void _openFilesSheet() { if (!mounted || _filesSheetOpen || @@ -590,6 +609,7 @@ class _ChatThreadViewState extends State { _files.dispose(); _files = _newFilesController()..addListener(_persistFilesPreferences); _filesVisible = false; + _reportedCenterStageFilesWidth = null; unawaited(_loadFilesPreferences()); _closed = false; _controller = _attach(); @@ -1299,6 +1319,7 @@ class _ChatThreadViewState extends State { final column = VerticalWheelForwarder(controller: _scroll, child: page); final wideFiles = _filesVisible && MediaQuery.sizeOf(context).width >= 700; + _reportCenterStageFilesWidth(); final content = wideFiles ? Row( children: [ diff --git a/app/lib/features/chat/workspace/chat_center_stage_layout.dart b/app/lib/features/chat/workspace/chat_center_stage_layout.dart index 64b22d36..07eaa984 100644 --- a/app/lib/features/chat/workspace/chat_center_stage_layout.dart +++ b/app/lib/features/chat/workspace/chat_center_stage_layout.dart @@ -38,6 +38,7 @@ class ChatCenterStageLayout { Size size, List order, String? activeId, + Map? paneExtraWidths, ) { if (order.length < 2 || activeId == null || !order.contains(activeId)) { return null; @@ -45,7 +46,7 @@ class ChatCenterStageLayout { final others = order.length - 1; final available = size.width - chatCenterStageGap * others; final stage = math.min( - chatCenterStageWidth, + chatCenterStageWidth + (paneExtraWidths?[activeId] ?? 0), available - others * chatCenterStageStripMinimumWidth, ); if (stage < chatPaneMinimumWidth) return null; diff --git a/app/lib/features/chat/workspace/chat_workspace.dart b/app/lib/features/chat/workspace/chat_workspace.dart index 6b195f95..b87e8e63 100644 --- a/app/lib/features/chat/workspace/chat_workspace.dart +++ b/app/lib/features/chat/workspace/chat_workspace.dart @@ -84,6 +84,7 @@ class _ChatWorkspaceState extends State ChatWorkspaceGeometry? _geometry; String? _lastActiveId; Set _visibleSessionIds = const {}; + final Map _paneExtraWidths = {}; late final ChatPaneBackdrop _backdrop; void _backdropChanged() { if (mounted) setState(() {}); @@ -109,6 +110,16 @@ class _ChatWorkspaceState extends State }); } + void _reportPaneExtraWidth(String paneId, double width) { + if ((_paneExtraWidths[paneId] ?? 0) == width) return; + if (width == 0) { + _paneExtraWidths.remove(paneId); + } else { + _paneExtraWidths[paneId] = width; + } + if (mounted) setState(() {}); + } + void _motionSettled(AnimationStatus status) { if (status != AnimationStatus.completed) return; WidgetsBinding.instance.addPostFrameCallback((_) { @@ -272,9 +283,12 @@ class _ChatWorkspaceState extends State engaged: engaged, split: geometry.panes, stage: engaged && widget.centerStage?.value == true - ? ChatCenterStageLayout.of(constraints.biggest, [ - for (final pane in panes) pane.id, - ], activeId) + ? ChatCenterStageLayout.of( + constraints.biggest, + [for (final pane in panes) pane.id], + activeId, + _paneExtraWidths, + ) : null, animate: !MediaQuery.disableAnimationsOf(context), ); @@ -461,6 +475,8 @@ class _ChatWorkspaceState extends State moveTargets: moveTargets ?? const {}, onActionBarPointerDown: () => actionBarPointerDown = true, onActionBarPointerUp: () => actionBarPointerDown = false, + onPreferredWidthChanged: (width) => + _reportPaneExtraWidth(pane.id, width), child: Builder( builder: (paneContext) => widget.paneBuilder(paneContext, pane, active), diff --git a/app/lib/features/chat/workspace/chat_workspace_pane_scope.dart b/app/lib/features/chat/workspace/chat_workspace_pane_scope.dart index 0d8879f9..76ea7e79 100644 --- a/app/lib/features/chat/workspace/chat_workspace_pane_scope.dart +++ b/app/lib/features/chat/workspace/chat_workspace_pane_scope.dart @@ -16,6 +16,7 @@ class ChatWorkspacePaneScope extends InheritedWidget { this.moveTargets = const {}, this.onActionBarPointerDown, this.onActionBarPointerUp, + this.onPreferredWidthChanged, required super.child, }); @@ -35,6 +36,9 @@ class ChatWorkspacePaneScope extends InheritedWidget { final VoidCallback? onActionBarPointerDown; final VoidCallback? onActionBarPointerUp; + /// Reports width needed by content that sits beside its reading column. + final ValueChanged? onPreferredWidthChanged; + static ChatWorkspacePaneScope? maybeOf(BuildContext context) => context.dependOnInheritedWidgetOfExactType(); @@ -47,7 +51,8 @@ class ChatWorkspacePaneScope extends InheritedWidget { movable != oldWidget.movable || !mapEquals(moveTargets, oldWidget.moveTargets) || onActionBarPointerDown != oldWidget.onActionBarPointerDown || - onActionBarPointerUp != oldWidget.onActionBarPointerUp; + onActionBarPointerUp != oldWidget.onActionBarPointerUp || + onPreferredWidthChanged != oldWidget.onPreferredWidthChanged; } /// Marks a pane header/toolbar. Its controls remain interactive, but focusing diff --git a/app/notes/center-stage-files-width.md b/app/notes/center-stage-files-width.md new file mode 100644 index 00000000..3d52468f --- /dev/null +++ b/app/notes/center-stage-files-width.md @@ -0,0 +1,10 @@ +# Center-stage explorer width + +- The active chat now reports its wide file explorer width through the pane + scope; center stage adds that width to the preferred reading-stage width. +- Closing the explorer or switching chats recomputes the active pane allocation; + constrained workspaces still cap the stage to available strips. +- Focused check: `tool/memwatch/full.sh + 'test/features/chat/workspace/chat_center_stage_test.dart'` — 15 passed. +- `tool/analyze.sh` — clean. +- Browser capture was not run in this implementation stage; UI review owns it. diff --git a/app/test/features/chat/workspace/chat_center_stage_test.dart b/app/test/features/chat/workspace/chat_center_stage_test.dart index 9f915f09..d9867f9e 100644 --- a/app/test/features/chat/workspace/chat_center_stage_test.dart +++ b/app/test/features/chat/workspace/chat_center_stage_test.dart @@ -42,6 +42,37 @@ class _DraftState extends State<_Draft> { TextField(key: ValueKey('input-${widget.name}'), controller: text); } +class _FilesWidthProbe extends StatefulWidget { + const _FilesWidthProbe({required this.name}); + final String name; + + @override + State<_FilesWidthProbe> createState() => _FilesWidthProbeState(); +} + +class _FilesWidthProbeState extends State<_FilesWidthProbe> { + bool visible = false; + + void _toggle() { + final next = !visible; + setState(() => visible = next); + WidgetsBinding.instance.addPostFrameCallback((_) { + if (mounted) { + ChatWorkspacePaneScope.maybeOf( + context, + )?.onPreferredWidthChanged?.call(next ? 300 : 0); + } + }); + } + + @override + Widget build(BuildContext context) => TextButton( + key: ValueKey('files-${widget.name}'), + onPressed: _toggle, + child: Text(visible ? 'Close files' : 'Open files'), + ); +} + Widget host( ChatWorkspaceController workspace, ChatCenterStageController stage, { @@ -50,6 +81,7 @@ Widget host( bool reduceMotion = false, List? fieldKeys, bool actionBars = false, + bool filesProbe = false, }) => MaterialApp( home: MediaQuery( data: MediaQueryData(disableAnimations: reduceMotion), @@ -75,6 +107,7 @@ Widget host( child: Column( children: [ _Draft(key: ValueKey(pane.sessionId), name: pane.sessionId), + if (filesProbe) _FilesWidthProbe(name: pane.sessionId), if (actionBars) ChatWorkspacePaneActionBar( child: TextButton( @@ -114,11 +147,12 @@ void main() { test( 'stage is the reading width plus a quarter, others share the rest', () { - final layout = ChatCenterStageLayout.of(const Size(1368, 800), [ - 'a', + final layout = ChatCenterStageLayout.of( + const Size(1368, 800), + ['a', 'b', 'c'], 'b', - 'c', - ], 'b')!; + null, + )!; expect(chatCenterStageWidth, 950); expect(layout.rects['b'], const Rect.fromLTWH(209, 0, 950, 800)); expect(layout.rects['a'], const Rect.fromLTWH(0, 0, 197, 800)); @@ -131,31 +165,64 @@ void main() { ); test('a narrow workspace caps the stage to leave every strip', () { - final layout = ChatCenterStageLayout.of(const Size(700, 800), [ + final layout = ChatCenterStageLayout.of( + const Size(700, 800), + ['a', 'b', 'c'], 'a', - 'b', - 'c', - ], 'a')!; + null, + )!; expect(layout.rects['a']!.width, 700 - 24 - 2 * 56); expect(layout.rects['c']!.right, 700); expect( - ChatCenterStageLayout.of(const Size(300, 800), ['a', 'b'], 'a'), + ChatCenterStageLayout.of(const Size(300, 800), ['a', 'b'], 'a', null), isNull, ); }); test('a very wide workspace keeps the stage and shows live columns', () { - final layout = ChatCenterStageLayout.of(const Size(2560, 800), [ + final layout = ChatCenterStageLayout.of( + const Size(2560, 800), + ['a', 'b'], 'a', - 'b', - ], 'a')!; + null, + )!; expect(layout.rects['a']!.width, 950); expect(layout.strips, isEmpty); expect( - ChatCenterStageLayout.of(const Size(2560, 800), ['a'], 'a'), + ChatCenterStageLayout.of(const Size(2560, 800), ['a'], 'a', null), isNull, ); }); + + test( + 'an active pane adds its side panel without shrinking its reading width', + () { + final layout = ChatCenterStageLayout.of( + const Size(1600, 800), + ['a', 'b'], + 'b', + {'b': 300}, + )!; + expect(layout.rects['b']!.width, 1250); + expect(layout.rects['a']!.width, 1600 - 12 - 1250); + + final switched = ChatCenterStageLayout.of( + const Size(1600, 800), + ['a', 'b'], + 'a', + {'b': 300}, + )!; + expect(switched.rects['a']!.width, chatCenterStageWidth); + + final closed = ChatCenterStageLayout.of( + const Size(1600, 800), + ['a', 'b'], + 'b', + null, + )!; + expect(closed.rects['b']!.width, chatCenterStageWidth); + }, + ); }); testWidgets('toggling stages the active chat, keeps drafts and split sizes', ( @@ -236,6 +303,45 @@ void main() { expect(find.text('kept'), findsOneWidget); }); + testWidgets( + 'pane explorer width keeps the active transcript wide across open, close, and switch', + (tester) async { + wide(tester); + final workspace = threePanes(); + final stage = ChatCenterStageController(store: _MemoryStore()) + ..value = true; + addTearDown(workspace.dispose); + addTearDown(stage.dispose); + await tester.pumpWidget( + host(workspace, stage, width: 1600, filesProbe: true), + ); + await tester.pumpAndSettle(); + + expect(widthOf(tester, 'three'), chatCenterStageWidth); + + await tester.tap(find.byKey(const ValueKey('files-three'))); + await tester.pumpAndSettle(); + expect(widthOf(tester, 'three'), 1250); + + workspace.activate(workspace.panes.first.id); + await tester.pumpAndSettle(); + expect(widthOf(tester, 'one'), chatCenterStageWidth); + expect(widthOf(tester, 'three'), lessThan(chatCenterStageWidth)); + + await tester.tap(find.byKey(const ValueKey('files-one'))); + await tester.pumpAndSettle(); + expect(widthOf(tester, 'one'), 1250); + + await tester.tap(find.byKey(const ValueKey('files-one'))); + await tester.pumpAndSettle(); + expect(widthOf(tester, 'one'), chatCenterStageWidth); + + workspace.activate(workspace.panes.last.id); + await tester.pumpAndSettle(); + expect(widthOf(tester, 'three'), 1250); + }, + ); + testWidgets('a live side action bar does not move center stage', ( tester, ) async {