Double-click a chat divider to switch the split layout
Double-clicking the divider between two chat panes flips that split between side by side and stacked, keeping its proportion, instead of resetting it to 50/50. Screen readers get the same action.
This commit is contained in:
@@ -138,6 +138,28 @@ class ChatWorkspaceController extends ChangeNotifier {
|
|||||||
_changed();
|
_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) {
|
void close(String paneId) {
|
||||||
final before = panes;
|
final before = panes;
|
||||||
final index = before.indexWhere((p) => p.id == paneId);
|
final index = before.indexWhere((p) => p.id == paneId);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/semantics.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
import '../../../ui/adaptive/host.dart';
|
import '../../../ui/adaptive/host.dart';
|
||||||
@@ -13,10 +14,15 @@ class ChatWorkspaceDivider extends StatefulWidget {
|
|||||||
super.key,
|
super.key,
|
||||||
required this.geometry,
|
required this.geometry,
|
||||||
required this.onChanged,
|
required this.onChanged,
|
||||||
|
this.onToggleAxis,
|
||||||
});
|
});
|
||||||
final ChatWorkspaceDividerGeometry geometry;
|
final ChatWorkspaceDividerGeometry geometry;
|
||||||
final ValueChanged<double> onChanged;
|
final ValueChanged<double> onChanged;
|
||||||
|
|
||||||
|
/// Double-clicking the divider flips the split between side by side and
|
||||||
|
/// stacked.
|
||||||
|
final VoidCallback? onToggleAxis;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<ChatWorkspaceDivider> createState() => _ChatWorkspaceDividerState();
|
State<ChatWorkspaceDivider> createState() => _ChatWorkspaceDividerState();
|
||||||
}
|
}
|
||||||
@@ -56,6 +62,13 @@ class _ChatWorkspaceDividerState extends State<ChatWorkspaceDivider> {
|
|||||||
decreasedValue:
|
decreasedValue:
|
||||||
'${((_actual - 16 / _available).clamp(widget.geometry.minimum, widget.geometry.maximum) * 100).round()} percent',
|
'${((_actual - 16 / _available).clamp(widget.geometry.minimum, widget.geometry.maximum) * 100).round()} percent',
|
||||||
onIncrease: () => _step(16),
|
onIncrease: () => _step(16),
|
||||||
|
customSemanticsActions: widget.onToggleAxis == null
|
||||||
|
? null
|
||||||
|
: {
|
||||||
|
CustomSemanticsAction(
|
||||||
|
label: _horizontal ? 'Stack panes' : 'Place panes side by side',
|
||||||
|
): widget.onToggleAxis!,
|
||||||
|
},
|
||||||
onDecrease: () => _step(-16),
|
onDecrease: () => _step(-16),
|
||||||
child: Focus(
|
child: Focus(
|
||||||
onFocusChange: (value) => setState(() => _focused = value),
|
onFocusChange: (value) => setState(() => _focused = value),
|
||||||
@@ -83,7 +96,7 @@ class _ChatWorkspaceDividerState extends State<ChatWorkspaceDivider> {
|
|||||||
onExit: (_) => setState(() => _hovered = false),
|
onExit: (_) => setState(() => _hovered = false),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
behavior: HitTestBehavior.opaque,
|
behavior: HitTestBehavior.opaque,
|
||||||
onDoubleTap: () => _change(.5),
|
onDoubleTap: widget.onToggleAxis,
|
||||||
onPanStart: (_) => setState(() => _drag = _actual),
|
onPanStart: (_) => setState(() => _drag = _actual),
|
||||||
onPanUpdate: (details) {
|
onPanUpdate: (details) {
|
||||||
_drag =
|
_drag =
|
||||||
@@ -96,7 +109,9 @@ class _ChatWorkspaceDividerState extends State<ChatWorkspaceDivider> {
|
|||||||
onPanCancel: () => setState(() => _drag = null),
|
onPanCancel: () => setState(() => _drag = null),
|
||||||
child: Tooltip(
|
child: Tooltip(
|
||||||
excludeFromSemantics: true,
|
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(
|
child: Stack(
|
||||||
fit: StackFit.expand,
|
fit: StackFit.expand,
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ Widget chatWorkspaceSurface({
|
|||||||
geometry: divider,
|
geometry: divider,
|
||||||
onChanged: (ratio) =>
|
onChanged: (ratio) =>
|
||||||
controller.resize(divider.split.id, ratio),
|
controller.resize(divider.split.id, ratio),
|
||||||
|
onToggleAxis: () => controller.toggleAxis(divider.split.id),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
testWidgets(
|
testWidgets(
|
||||||
'divider keyboard resizing and double-click reset use the same limits',
|
'divider keyboard resizing; double-click switches the split layout',
|
||||||
(tester) async {
|
(tester) async {
|
||||||
final controller = ChatWorkspaceController()
|
final controller = ChatWorkspaceController()
|
||||||
..open('one')
|
..open('one')
|
||||||
@@ -193,11 +193,29 @@ void main() {
|
|||||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect((controller.root! as ChatWorkspaceSplit).ratio, greaterThan(.5));
|
expect((controller.root! as ChatWorkspaceSplit).ratio, greaterThan(.5));
|
||||||
|
final resized = (controller.root! as ChatWorkspaceSplit).ratio;
|
||||||
await tester.tap(divider);
|
await tester.tap(divider);
|
||||||
await tester.pump(const Duration(milliseconds: 50));
|
await tester.pump(const Duration(milliseconds: 50));
|
||||||
await tester.tap(divider);
|
await tester.tap(divider);
|
||||||
await tester.pump(const Duration(milliseconds: 500));
|
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<ChatWorkspaceDivider>(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),
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user