Merge main: keep pane moves and the floating chat; Float sits beside the move items

This commit is contained in:
2026-11-10 13:09:31 +00:00
16 changed files with 824 additions and 51 deletions
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -0,0 +1,236 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/workspace/chat_pane_move_shortcuts.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace_geometry.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace_snapshot.dart';
/// a | (b over (c | d)): a on the left, b top right, c and d below b.
ChatWorkspaceController _nested() {
final controller = ChatWorkspaceController()..open('a');
controller.splitActive('b', ChatSplitAxis.horizontal);
controller.splitActive('c', ChatSplitAxis.vertical);
controller.splitActive('d', ChatSplitAxis.horizontal);
return controller;
}
String _id(ChatWorkspaceController controller, String session) =>
controller.panes.firstWhere((pane) => pane.sessionId == session).id;
Map<ChatPaneDirection, String?> _targets(
ChatWorkspaceController controller,
String session,
) {
final geometry = ChatWorkspaceGeometry(
controller.root!,
const Size(1200, 800),
);
final names = {for (final p in controller.panes) p.id: p.sessionId};
return {
for (final direction in ChatPaneDirection.values)
direction: names[geometry.adjacent(_id(controller, session), direction)],
};
}
class _Draft extends StatefulWidget {
const _Draft({super.key, required this.name});
final String name;
@override
State<_Draft> createState() => _DraftState();
}
class _DraftState extends State<_Draft> {
final text = TextEditingController();
@override
void dispose() {
text.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) =>
TextField(key: ValueKey('input-${widget.name}'), controller: text);
}
Widget _host(ChatWorkspaceController controller, {bool reduce = false}) =>
MaterialApp(
home: MediaQuery(
data: MediaQueryData(
size: const Size(1200, 800),
disableAnimations: reduce,
),
child: Scaffold(
body: SizedBox(
width: 1200,
height: 800,
child: ChatWorkspace(
controller: controller,
paneBuilder: (_, pane, _) =>
_Draft(key: ValueKey(pane.sessionId), name: pane.sessionId),
),
),
),
),
);
Future<void> _chord(WidgetTester tester, LogicalKeyboardKey arrow) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyEvent(arrow);
await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
}
void main() {
test('adjacency follows nested splits and stops at outer edges', () {
final controller = _nested();
addTearDown(controller.dispose);
expect(_targets(controller, 'a'), {
ChatPaneDirection.up: null,
ChatPaneDirection.down: null,
ChatPaneDirection.left: null,
// b and c share a's right edge equally and a's centre line falls in
// their divider: the tie goes to the first in reading order.
ChatPaneDirection.right: 'b',
});
expect(_targets(controller, 'b'), {
ChatPaneDirection.up: null,
ChatPaneDirection.down: 'c',
ChatPaneDirection.left: 'a',
ChatPaneDirection.right: null,
});
// Once d is wider it spans b's centre line, so b's move down takes d.
final bottom =
((controller.root as ChatWorkspaceSplit).second as ChatWorkspaceSplit)
.second
as ChatWorkspaceSplit;
controller.resize(bottom.id, .3);
expect(_targets(controller, 'b')[ChatPaneDirection.down], 'd');
controller.resize(bottom.id, .5);
expect(_targets(controller, 'c'), {
ChatPaneDirection.up: 'b',
ChatPaneDirection.down: null,
ChatPaneDirection.left: 'a',
ChatPaneDirection.right: 'd',
});
expect(_targets(controller, 'd')[ChatPaneDirection.left], 'c');
expect(_targets(controller, 'd')[ChatPaneDirection.up], 'b');
});
test('swap trades places both ways, keeping ids, ratios and focus', () {
final controller = _nested();
addTearDown(controller.dispose);
final outer = controller.root as ChatWorkspaceSplit;
controller.resize(outer.id, .3);
final ids = {for (final s in ['a', 'b', 'c', 'd']) s: _id(controller, s)};
final serial = controller.moveSerial;
controller.swap(ids['a']!, ids['c']!);
expect(controller.panes.map((p) => p.sessionId), ['c', 'b', 'a', 'd']);
expect({for (final p in controller.panes) p.sessionId: p.id}, ids);
expect(controller.activePaneId, ids['a']);
expect(controller.moveSerial, serial + 1);
expect(controller.movedPaneIds, {ids['a'], ids['c']});
expect((controller.root as ChatWorkspaceSplit).ratio, .3);
expect((controller.root as ChatWorkspaceSplit).id, outer.id);
controller.swap(ids['a']!, ids['c']!);
expect(controller.panes.map((p) => p.sessionId), ['a', 'b', 'c', 'd']);
controller.swap(ids['a']!, 'missing');
controller.swap(ids['a']!, ids['a']!);
expect(controller.moveSerial, serial + 2);
});
test('a moved layout survives an encode/decode round trip', () {
final controller = _nested();
addTearDown(controller.dispose);
controller.swap(_id(controller, 'b'), _id(controller, 'd'));
final source = controller.snapshot(sidebarMode: 'compact')!.encode();
final restored = ChatWorkspaceController();
addTearDown(restored.dispose);
expect(restored.restoreLayout(ChatWorkspaceSnapshot.decode(source)!), true);
expect(restored.panes.map((p) => p.sessionId), ['a', 'd', 'c', 'b']);
expect(restored.activePane?.sessionId, 'b');
});
test('the move chord adds Alt to the focus chord, Command on macOS', () {
expect(
chatPaneMoveActivator(
ChatPaneDirection.up,
platform: TargetPlatform.macOS,
).debugDescribeKeys(),
'Alt + Meta + Shift + Arrow Up',
);
expect(
chatPaneMoveActivator(
ChatPaneDirection.down,
platform: TargetPlatform.windows,
).debugDescribeKeys(),
'Control + Alt + Shift + Arrow Down',
);
});
test('the chord family: Alt turns focusing into moving', () {
// Only real key events reach the handler; the parse is checked through
// the widget tests below. Here, the menu's chord and the handler agree.
final activator = chatPaneMoveActivator(
ChatPaneDirection.left,
platform: TargetPlatform.linux,
);
expect(activator.trigger, LogicalKeyboardKey.arrowLeft);
expect(
[activator.control, activator.alt, activator.shift, activator.meta],
[true, true, true, false],
);
});
testWidgets(
'the chord moves the focused pane, keeps its draft, and is inert at edges',
(tester) async {
final controller = ChatWorkspaceController()
..open('one')
..splitActive('two', ChatSplitAxis.horizontal);
addTearDown(controller.dispose);
await tester.pumpWidget(_host(controller));
final input = find.byKey(const ValueKey('input-one'));
await tester.enterText(input, 'draft one');
final state = tester.state(find.byKey(const ValueKey('one')));
final before = tester.getRect(input);
await _chord(tester, LogicalKeyboardKey.arrowRight);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
// Mid-glide: the retained view is between its old and new tiles.
final middle = tester.getRect(input);
await tester.pumpAndSettle();
final after = tester.getRect(input);
expect(middle.left, greaterThan(before.left));
expect(after.left, greaterThan(middle.left));
expect(tester.state(find.byKey(const ValueKey('one'))), same(state));
expect(tester.widget<TextField>(input).controller!.text, 'draft one');
expect(controller.activePane?.sessionId, 'one');
expect(controller.panes.map((p) => p.sessionId), ['two', 'one']);
final serial = controller.moveSerial;
await _chord(tester, LogicalKeyboardKey.arrowRight);
await _chord(tester, LogicalKeyboardKey.arrowUp);
await tester.pumpAndSettle();
expect(controller.moveSerial, serial);
expect(tester.widget<TextField>(input).controller!.text, 'draft one');
},
variant: TargetPlatformVariant.only(TargetPlatform.linux),
);
testWidgets('reduced motion swaps the panes instantly', (tester) async {
final controller = ChatWorkspaceController()
..open('one')
..splitActive('two', ChatSplitAxis.horizontal);
addTearDown(controller.dispose);
await tester.pumpWidget(_host(controller, reduce: true));
final input = find.byKey(const ValueKey('input-one'));
final twoBefore = tester.getRect(find.byKey(const ValueKey('input-two')));
controller.swap(_id(controller, 'one'), _id(controller, 'two'));
await tester.pump();
expect(tester.getRect(input).left, twoBefore.left);
expect(tester.hasRunningAnimations, isFalse);
});
}