diff --git a/app/lib/features/chat/workspace/chat_workspace_controller.dart b/app/lib/features/chat/workspace/chat_workspace_controller.dart index 59e5a202..f15c296a 100644 --- a/app/lib/features/chat/workspace/chat_workspace_controller.dart +++ b/app/lib/features/chat/workspace/chat_workspace_controller.dart @@ -138,6 +138,28 @@ class ChatWorkspaceController extends ChangeNotifier { _changed(); } + /// Flips one split between side by side and stacked, keeping its ratio. + void toggleAxis(String splitId) { + if (_root == null) return; + _root = _toggle(_root!, splitId); + _changed(); + } + + ChatWorkspaceNode _toggle(ChatWorkspaceNode node, String id) { + if (node is! ChatWorkspaceSplit) return node; + return ChatWorkspaceSplit( + node.id, + node.id == id + ? (node.axis == ChatSplitAxis.horizontal + ? ChatSplitAxis.vertical + : ChatSplitAxis.horizontal) + : node.axis, + _toggle(node.first, id), + _toggle(node.second, id), + ratio: node.ratio, + ); + } + void close(String paneId) { final before = panes; final index = before.indexWhere((p) => p.id == paneId); diff --git a/app/lib/features/chat/workspace/chat_workspace_divider.dart b/app/lib/features/chat/workspace/chat_workspace_divider.dart index 74eb6e90..18c8ad66 100644 --- a/app/lib/features/chat/workspace/chat_workspace_divider.dart +++ b/app/lib/features/chat/workspace/chat_workspace_divider.dart @@ -1,5 +1,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/semantics.dart'; import 'package:flutter/services.dart'; import '../../../ui/adaptive/host.dart'; @@ -13,10 +14,15 @@ class ChatWorkspaceDivider extends StatefulWidget { super.key, required this.geometry, required this.onChanged, + this.onToggleAxis, }); final ChatWorkspaceDividerGeometry geometry; final ValueChanged onChanged; + /// Double-clicking the divider flips the split between side by side and + /// stacked. + final VoidCallback? onToggleAxis; + @override State createState() => _ChatWorkspaceDividerState(); } @@ -56,6 +62,13 @@ class _ChatWorkspaceDividerState extends State { decreasedValue: '${((_actual - 16 / _available).clamp(widget.geometry.minimum, widget.geometry.maximum) * 100).round()} percent', onIncrease: () => _step(16), + customSemanticsActions: widget.onToggleAxis == null + ? null + : { + CustomSemanticsAction( + label: _horizontal ? 'Stack panes' : 'Place panes side by side', + ): widget.onToggleAxis!, + }, onDecrease: () => _step(-16), child: Focus( onFocusChange: (value) => setState(() => _focused = value), @@ -83,7 +96,7 @@ class _ChatWorkspaceDividerState extends State { onExit: (_) => setState(() => _hovered = false), child: GestureDetector( behavior: HitTestBehavior.opaque, - onDoubleTap: () => _change(.5), + onDoubleTap: widget.onToggleAxis, onPanStart: (_) => setState(() => _drag = _actual), onPanUpdate: (details) { _drag = @@ -96,7 +109,9 @@ class _ChatWorkspaceDividerState extends State { onPanCancel: () => setState(() => _drag = null), child: Tooltip( excludeFromSemantics: true, - message: 'Drag to resize chat panes', + message: widget.onToggleAxis == null + ? 'Drag to resize chat panes' + : 'Drag to resize ยท double-click to switch layout', child: Stack( fit: StackFit.expand, children: [ diff --git a/app/lib/features/chat/workspace/chat_workspace_surface.dart b/app/lib/features/chat/workspace/chat_workspace_surface.dart index 3670d137..578c20d4 100644 --- a/app/lib/features/chat/workspace/chat_workspace_surface.dart +++ b/app/lib/features/chat/workspace/chat_workspace_surface.dart @@ -144,6 +144,7 @@ Widget chatWorkspaceSurface({ geometry: divider, onChanged: (ratio) => controller.resize(divider.split.id, ratio), + onToggleAxis: () => controller.toggleAxis(divider.split.id), ), ), ], diff --git a/app/test/features/chat/workspace/chat_workspace_test.dart b/app/test/features/chat/workspace/chat_workspace_test.dart index 17af6415..6614e88f 100644 --- a/app/test/features/chat/workspace/chat_workspace_test.dart +++ b/app/test/features/chat/workspace/chat_workspace_test.dart @@ -176,7 +176,7 @@ void main() { ); testWidgets( - 'divider keyboard resizing and double-click reset use the same limits', + 'divider keyboard resizing; double-click switches the split layout', (tester) async { final controller = ChatWorkspaceController() ..open('one') @@ -193,11 +193,29 @@ void main() { await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); await tester.pump(); expect((controller.root! as ChatWorkspaceSplit).ratio, greaterThan(.5)); + final resized = (controller.root! as ChatWorkspaceSplit).ratio; await tester.tap(divider); await tester.pump(const Duration(milliseconds: 50)); await tester.tap(divider); await tester.pump(const Duration(milliseconds: 500)); - expect((controller.root! as ChatWorkspaceSplit).ratio, .5); + // Side by side becomes stacked, keeping the chosen proportion. + final stacked = controller.root! as ChatWorkspaceSplit; + expect(stacked.axis, ChatSplitAxis.vertical); + expect(stacked.ratio, resized); + final flipped = find.byType(ChatWorkspaceDivider); + expect( + tester.widget(flipped).geometry.split.axis, + ChatSplitAxis.vertical, + ); + await tester.tap(flipped); + await tester.pump(const Duration(milliseconds: 50)); + await tester.tap(flipped); + await tester.pump(const Duration(milliseconds: 500)); + expect( + (controller.root! as ChatWorkspaceSplit).axis, + ChatSplitAxis.horizontal, + ); + expect(tester.takeException(), isNull); }, ); @@ -339,4 +357,27 @@ void main() { }, variant: TargetPlatformVariant.only(TargetPlatform.macOS), ); + + test('toggleAxis flips only the named split and keeps every ratio', () { + final controller = ChatWorkspaceController() + ..open('one') + ..splitActive('two', ChatSplitAxis.horizontal); + addTearDown(controller.dispose); + controller.activate(controller.panes.last.id); + controller.splitActive('three', ChatSplitAxis.vertical); + final root = controller.root! as ChatWorkspaceSplit; + final nested = root.second as ChatWorkspaceSplit; + controller.resize(nested.id, .3); + var notified = 0; + controller.addListener(() => notified++); + controller.toggleAxis(nested.id); + final after = controller.root! as ChatWorkspaceSplit; + expect(after.axis, ChatSplitAxis.horizontal); + final inner = after.second as ChatWorkspaceSplit; + expect(inner.axis, ChatSplitAxis.horizontal); + expect(inner.ratio, .3); + expect(after.ratio, root.ratio); + expect(controller.panes.map((p) => p.sessionId), ['one', 'two', 'three']); + expect(notified, 1); + }); }