Preserve center stage width with file explorer
Report each pane's active explorer width to the center-stage layout so the reading column stays at its preferred width while constrained workspaces still make room for side strips. Restore the allocation when switching panes or closing the explorer.
This commit is contained in:
@@ -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<KeyEvent>? 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 {
|
||||
|
||||
Reference in New Issue
Block a user