Float several chats and keep them working on every tab
Floating chats were stuck on other destinations: the hidden Chat tab muted the window's hide animation, so the window stayed painted but took no input. The reveal now uses its own ticker, each floating pane's focus scope hangs from a FloatingFocusRoot above the destination stack, and the windows show over every destination like the terminal. Any number of chats can float; the shortcut, a window's X and the menu show or hide them together. Each pane keeps its own frame (also while docked), saved in record version 2; version 1 records still load. Drags read the live frame so fast pointer events no longer lose movement.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -8,6 +9,8 @@ import 'package:pipelines_app/features/chat/screen.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_float_store.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace_store.dart';
|
||||
import 'package:pipelines_app/ui/floating/floating_layer.dart';
|
||||
import 'package:pipelines_app/ui/motion/fade_through_stack.dart';
|
||||
|
||||
import 'conversation/chat_thread_fixtures.dart';
|
||||
|
||||
@@ -41,6 +44,7 @@ ChatWorkspaceController _workspace(WidgetTester tester) =>
|
||||
Future<_Gateway> _mount(
|
||||
WidgetTester tester, {
|
||||
Size size = const Size(1800, 1000),
|
||||
ValueNotifier<int>? destination,
|
||||
}) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
@@ -48,10 +52,26 @@ Future<_Gateway> _mount(
|
||||
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
||||
bindServerIdentity(gateway, 'server-a');
|
||||
addTearDown(gateway.close);
|
||||
final chat = ChatScreen(gateway: gateway, persistWorkspace: true);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatScreen(gateway: gateway, persistWorkspace: true),
|
||||
body: destination == null
|
||||
? chat
|
||||
// As the shell keeps destinations: the hidden one is muted,
|
||||
// unfocusable and takes no input.
|
||||
: FloatingFocusRoot(
|
||||
child: ValueListenableBuilder(
|
||||
valueListenable: destination,
|
||||
builder: (context, index, _) => FadeThroughStack(
|
||||
index: index,
|
||||
children: [
|
||||
chat,
|
||||
const Center(child: Text('Runs page')),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -74,10 +94,11 @@ Future<void> _menu(WidgetTester tester, String session, String label) async {
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> _saved(String a, String b) async {
|
||||
Future<void> _saved(String a, String b, [String? c]) async {
|
||||
final layout = ChatWorkspaceController()
|
||||
..open(a)
|
||||
..splitActive(b, ChatSplitAxis.horizontal);
|
||||
if (c != null) layout.splitActive(c, ChatSplitAxis.horizontal);
|
||||
SharedPreferences.setMockInitialValues({
|
||||
scopedServerKey(chatWorkspacePreferenceKey, 'server-a'): layout
|
||||
.snapshot()!
|
||||
@@ -95,7 +116,7 @@ void main() {
|
||||
await tester.enterText(_input('b'), 'Draft B');
|
||||
await _menu(tester, 'b', 'Float (Ctrl+Y)');
|
||||
final controller = _workspace(tester);
|
||||
expect(controller.floatingPane?.sessionId, 'b');
|
||||
expect(controller.floatingPanes.single.sessionId, 'b');
|
||||
expect(controller.panes.map((p) => p.sessionId), ['a']);
|
||||
expect(find.byKey(const ValueKey('chat-float-title')), findsOneWidget);
|
||||
expect(tester.state(_thread('b')), same(b));
|
||||
@@ -106,7 +127,7 @@ void main() {
|
||||
);
|
||||
expect(window.width, lessThan(1800 / 2));
|
||||
|
||||
// The lone tiled pane can still float, swapping with the floating one.
|
||||
// The lone tiled pane cannot float: the tiling would be empty.
|
||||
await tester.tap(
|
||||
find
|
||||
.descendant(
|
||||
@@ -116,12 +137,12 @@ void main() {
|
||||
.hitTestable(),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Float (Ctrl+Y)'), findsOneWidget);
|
||||
expect(find.text('Float (Ctrl+Y)'), findsNothing);
|
||||
await tester.tapAt(const Offset(5, 995));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await _menu(tester, 'b', 'Dock');
|
||||
expect(controller.floatingPane, isNull);
|
||||
expect(controller.floatingPanes, isEmpty);
|
||||
expect(controller.panes.map((p) => p.sessionId), ['a', 'b']);
|
||||
expect(tester.state(_thread('b')), same(b));
|
||||
expect(tester.widget<EditableText>(_input('b')).controller.text, 'Draft B');
|
||||
@@ -146,7 +167,7 @@ void main() {
|
||||
const Offset(200, 40),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await _menu(tester, 'b', 'Hide floating chat (Ctrl+Y)');
|
||||
await _menu(tester, 'b', 'Hide floating chats (Ctrl+Y)');
|
||||
expect(find.byKey(const ValueKey('chat-float-title')), findsNothing);
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
final preferences = await SharedPreferences.getInstance();
|
||||
@@ -155,14 +176,15 @@ void main() {
|
||||
scopedServerKey(chatFloatPreferenceKey, 'server-a'),
|
||||
)!,
|
||||
)!;
|
||||
expect(record.pane?.sessionId, 'b');
|
||||
final floated = record.panes.single;
|
||||
expect(floated.sessionId, 'b');
|
||||
expect(record.shown, isFalse);
|
||||
expect(record.rect.left, chatFloatDefaultRect.left + 200);
|
||||
expect(record.frames[floated.id]?.left, chatFloatDefaultRect.left + 200);
|
||||
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await _mount(tester);
|
||||
final controller = _workspace(tester);
|
||||
expect(controller.floatingPane?.sessionId, 'b');
|
||||
expect(controller.floatingPanes.single.sessionId, 'b');
|
||||
expect(controller.floatShown, isFalse);
|
||||
expect(controller.panes.map((p) => p.sessionId), ['a']);
|
||||
controller.setFloatShown(true);
|
||||
@@ -174,6 +196,127 @@ void main() {
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
Future<void> chord(WidgetTester tester) async {
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
final titles = find.byKey(const ValueKey('chat-float-title'));
|
||||
|
||||
testWidgets('several chats float; the chord hides and shows them all '
|
||||
'where they were', (tester) async {
|
||||
await _saved('a', 'b', 'c');
|
||||
await _mount(tester);
|
||||
await _menu(tester, 'b', 'Float (Ctrl+Y)');
|
||||
await _menu(tester, 'c', 'Float (Ctrl+Y)');
|
||||
final controller = _workspace(tester);
|
||||
expect(controller.floatingPanes.map((p) => p.sessionId), ['b', 'c']);
|
||||
expect(controller.panes.map((p) => p.sessionId), ['a']);
|
||||
expect(titles, findsNWidgets(2));
|
||||
// The second window opens stepped from the first, so both show.
|
||||
final first = tester.getTopLeft(titles.first);
|
||||
final second = tester.getTopLeft(titles.last);
|
||||
expect(second.dx, greaterThan(first.dx));
|
||||
await tester.drag(titles.first, const Offset(300, 100));
|
||||
await tester.pumpAndSettle();
|
||||
final moved = tester.getTopLeft(titles.first);
|
||||
expect(moved.dx, greaterThan(first.dx + 200));
|
||||
|
||||
await chord(tester);
|
||||
expect(controller.floatShown, isFalse);
|
||||
expect(titles, findsNothing);
|
||||
await chord(tester);
|
||||
expect(controller.floatShown, isTrue);
|
||||
expect(titles, findsNWidgets(2));
|
||||
expect(tester.getTopLeft(titles.first), moved);
|
||||
expect(tester.getTopLeft(titles.last), second);
|
||||
|
||||
// Docking one leaves the other floating.
|
||||
await _menu(tester, 'b', 'Dock');
|
||||
expect(controller.floatingPanes.map((p) => p.sessionId), ['c']);
|
||||
expect(titles, findsOneWidget);
|
||||
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
final preferences = await SharedPreferences.getInstance();
|
||||
final record = ChatFloatRecord.decode(
|
||||
preferences.getString(
|
||||
scopedServerKey(chatFloatPreferenceKey, 'server-a'),
|
||||
)!,
|
||||
)!;
|
||||
expect(record.panes.map((p) => p.sessionId), ['c']);
|
||||
// The docked chat keeps its frame for its next float.
|
||||
expect(record.frames, hasLength(2));
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
testWidgets('a floating chat moves, types, hides and shows over another '
|
||||
'destination', (tester) async {
|
||||
await _saved('a', 'b');
|
||||
final destination = ValueNotifier(0);
|
||||
addTearDown(destination.dispose);
|
||||
await _mount(tester, destination: destination);
|
||||
await _menu(tester, 'b', 'Float (Ctrl+Y)');
|
||||
final controller = _workspace(tester);
|
||||
|
||||
destination.value = 1;
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Runs page'), findsOneWidget);
|
||||
// The chat page is offstage, so finders look past it; the window itself
|
||||
// paints and takes input in the root overlay.
|
||||
final title = find.byKey(
|
||||
const ValueKey('chat-float-title'),
|
||||
skipOffstage: false,
|
||||
);
|
||||
bool hits(Finder finder) {
|
||||
final box = tester.renderObject(finder);
|
||||
return tester
|
||||
.hitTestOnBinding(tester.getCenter(finder))
|
||||
.path
|
||||
.any((entry) => identical(entry.target, box));
|
||||
}
|
||||
|
||||
expect(hits(title), isTrue);
|
||||
final before = tester.getTopLeft(title);
|
||||
await tester.drag(title, const Offset(150, 60));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getTopLeft(title).dx, greaterThan(before.dx + 100));
|
||||
expect(tester.getTopLeft(title).dy, greaterThan(before.dy + 20));
|
||||
|
||||
// The composer takes the keyboard there.
|
||||
final input = _input('b');
|
||||
expect(hits(input), isTrue);
|
||||
await tester.tapAt(tester.getCenter(input));
|
||||
await tester.pump();
|
||||
final field = tester.widget<EditableText>(input);
|
||||
expect(field.focusNode.hasFocus, isTrue);
|
||||
tester.testTextInput.enterText('From runs');
|
||||
await tester.pump();
|
||||
expect(field.controller.text, 'From runs');
|
||||
|
||||
// The chord and the window's own hide button both work there.
|
||||
// The window itself animates away and back, not only the state.
|
||||
await chord(tester);
|
||||
expect(controller.floatShown, isFalse);
|
||||
expect(hits(title), isFalse);
|
||||
await chord(tester);
|
||||
expect(controller.floatShown, isTrue);
|
||||
expect(hits(title), isTrue);
|
||||
final hide = find.byTooltip(
|
||||
'Hide floating chats (Ctrl+Y)',
|
||||
skipOffstage: false,
|
||||
);
|
||||
expect(hits(hide), isTrue);
|
||||
await tester.tapAt(tester.getCenter(hide));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.floatShown, isFalse);
|
||||
expect(hits(title), isFalse);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
testWidgets('narrow layouts offer no Float', (tester) async {
|
||||
await _saved('a', 'b');
|
||||
await _mount(tester, size: const Size(430, 900));
|
||||
|
||||
@@ -82,7 +82,10 @@ Future<void> _openMenu(WidgetTester tester, String session) async {
|
||||
|
||||
MenuItemButton _item(WidgetTester tester, String label) =>
|
||||
tester.widget<MenuItemButton>(
|
||||
find.ancestor(of: find.text(label), matching: find.byType(MenuItemButton)),
|
||||
find.ancestor(
|
||||
of: find.text(label),
|
||||
matching: find.byType(MenuItemButton),
|
||||
),
|
||||
);
|
||||
|
||||
ChatWorkspaceController _controller(WidgetTester tester) =>
|
||||
@@ -205,7 +208,9 @@ void main() {
|
||||
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(home: Scaffold(body: ChatScreen(gateway: gateway))),
|
||||
MaterialApp(
|
||||
home: Scaffold(body: ChatScreen(gateway: gateway)),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Chat a').first);
|
||||
|
||||
@@ -244,9 +244,6 @@ void main() {
|
||||
isSameColorAs(tint.foreground),
|
||||
);
|
||||
// Outside the bar the theme's tint is untouched.
|
||||
expect(
|
||||
CupertinoTheme.of(context).primaryColor,
|
||||
isNot(tint.foreground),
|
||||
);
|
||||
expect(CupertinoTheme.of(context).primaryColor, isNot(tint.foreground));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -271,19 +271,20 @@ void main() {
|
||||
expect(mounted.gateway.listings, 2);
|
||||
});
|
||||
|
||||
testWidgets('A refused move is shown in the server\'s words until dismissed', (
|
||||
tester,
|
||||
) async {
|
||||
final mounted = await pump(tester);
|
||||
const refusal = '$shown/docs/notes.txt already exists';
|
||||
mounted.gateway.refusals['move_path'] = refusal;
|
||||
await dragOnto(tester, 'notes.txt', 'docs');
|
||||
expect(find.text(refusal), findsOneWidget);
|
||||
expect(mounted.gateway.listings, 2, reason: 'reloaded all the same');
|
||||
await tester.tap(find.text('Dismiss'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(refusal), findsNothing);
|
||||
});
|
||||
testWidgets(
|
||||
'A refused move is shown in the server\'s words until dismissed',
|
||||
(tester) async {
|
||||
final mounted = await pump(tester);
|
||||
const refusal = '$shown/docs/notes.txt already exists';
|
||||
mounted.gateway.refusals['move_path'] = refusal;
|
||||
await dragOnto(tester, 'notes.txt', 'docs');
|
||||
expect(find.text(refusal), findsOneWidget);
|
||||
expect(mounted.gateway.listings, 2, reason: 'reloaded all the same');
|
||||
await tester.tap(find.text('Dismiss'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(refusal), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
test('canDropEntryOn refuses files, itself and its own subtree', () {
|
||||
const docs = DirectoryEntry(
|
||||
|
||||
@@ -39,11 +39,10 @@ void main() {
|
||||
});
|
||||
|
||||
test('only visible assistant reply text is unread', () {
|
||||
bool attention(Map<String, Object?> event) =>
|
||||
chatSessionFrameEffect({
|
||||
'type': 'chat_event',
|
||||
'chat_event': {'session_id': 's', ...event},
|
||||
})!.attention;
|
||||
bool attention(Map<String, Object?> event) => chatSessionFrameEffect({
|
||||
'type': 'chat_event',
|
||||
'chat_event': {'session_id': 's', ...event},
|
||||
})!.attention;
|
||||
for (final status in ['running', 'completed', 'error']) {
|
||||
expect(
|
||||
attention({
|
||||
@@ -67,11 +66,7 @@ void main() {
|
||||
expect(attention({'kind': 'text', 'delta': ' \n'}), isFalse);
|
||||
for (final messageKind in ['notice', 'agent_report']) {
|
||||
expect(
|
||||
attention({
|
||||
'kind': 'text',
|
||||
'delta': 'x',
|
||||
'message_kind': messageKind,
|
||||
}),
|
||||
attention({'kind': 'text', 'delta': 'x', 'message_kind': messageKind}),
|
||||
isFalse,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -76,34 +76,36 @@ void main() {
|
||||
expect(_opacity(tester), 1);
|
||||
});
|
||||
|
||||
testWidgets('desktop shows it on hover and focus, and keeps semantics', (
|
||||
tester,
|
||||
) async {
|
||||
final semantics = tester.ensureSemantics();
|
||||
await tester.pumpWidget(_host(48));
|
||||
expect(_opacity(tester), 0);
|
||||
// Hidden, it is still reachable by a screen reader.
|
||||
expect(
|
||||
tester.getSemantics(_copy),
|
||||
isSemantics(tooltip: 'Copy', isButton: true, isFocusable: true),
|
||||
);
|
||||
testWidgets(
|
||||
'desktop shows it on hover and focus, and keeps semantics',
|
||||
(tester) async {
|
||||
final semantics = tester.ensureSemantics();
|
||||
await tester.pumpWidget(_host(48));
|
||||
expect(_opacity(tester), 0);
|
||||
// Hidden, it is still reachable by a screen reader.
|
||||
expect(
|
||||
tester.getSemantics(_copy),
|
||||
isSemantics(tooltip: 'Copy', isButton: true, isFocusable: true),
|
||||
);
|
||||
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
addTearDown(mouse.removePointer);
|
||||
await mouse.addPointer(location: Offset.zero);
|
||||
await mouse.moveTo(tester.getCenter(find.text('The answer text')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_opacity(tester), 1);
|
||||
await mouse.moveTo(const Offset(5, 590));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_opacity(tester), 0);
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
addTearDown(mouse.removePointer);
|
||||
await mouse.addPointer(location: Offset.zero);
|
||||
await mouse.moveTo(tester.getCenter(find.text('The answer text')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_opacity(tester), 1);
|
||||
await mouse.moveTo(const Offset(5, 590));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_opacity(tester), 0);
|
||||
|
||||
// Keyboard focus reveals it too.
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_opacity(tester), 1);
|
||||
semantics.dispose();
|
||||
}, variant: TargetPlatformVariant.only(TargetPlatform.macOS));
|
||||
// Keyboard focus reveals it too.
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_opacity(tester), 1);
|
||||
semantics.dispose();
|
||||
},
|
||||
variant: TargetPlatformVariant.only(TargetPlatform.macOS),
|
||||
);
|
||||
|
||||
for (final (width, inGutter) in [(1400.0, true), (560.0, false)]) {
|
||||
testWidgets('a ${width.toInt()} px conversation puts Copy '
|
||||
|
||||
@@ -237,7 +237,7 @@ void main() {
|
||||
expect(widthOf(tester, 'two'), 1368 - 12 - 950);
|
||||
expect(find.byType(ChatCenterStageStrip), findsNothing);
|
||||
|
||||
workspace.dock();
|
||||
workspace.dock(workspace.floatingPanes.single.id);
|
||||
await tester.pumpAndSettle();
|
||||
expect(workspace.activePane?.sessionId, 'one');
|
||||
expect(widthOf(tester, 'one'), 950);
|
||||
|
||||
@@ -42,7 +42,7 @@ class _Harness {
|
||||
final controller = ChatWorkspaceController()
|
||||
..open('a')
|
||||
..splitActive('b', ChatSplitAxis.horizontal);
|
||||
final frame = ChatFloatFrame();
|
||||
final frames = ChatFloatFrames();
|
||||
final typing = FocusNode(debugLabel: 'terminal');
|
||||
final typed = <LogicalKeyboardKey>[];
|
||||
|
||||
@@ -53,7 +53,7 @@ class _Harness {
|
||||
Expanded(
|
||||
child: ChatWorkspace(
|
||||
controller: controller,
|
||||
floatFrame: frame,
|
||||
floatFrames: frames,
|
||||
singlePane: narrow,
|
||||
onFocusPane: (pane) => _focus(pane.sessionId),
|
||||
paneBuilder: (context, pane, active) => _Pane(pane.sessionId),
|
||||
@@ -83,7 +83,7 @@ class _Harness {
|
||||
|
||||
void dispose() {
|
||||
controller.dispose();
|
||||
frame.dispose();
|
||||
frames.dispose();
|
||||
typing.dispose();
|
||||
}
|
||||
}
|
||||
@@ -128,12 +128,12 @@ void main() {
|
||||
// Plain Y and Shift+Y type; only the chord acts.
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
|
||||
await _chord(tester, LogicalKeyboardKey.shiftLeft);
|
||||
expect(h.controller.floatingPane, isNull);
|
||||
expect(h.controller.floatingPanes, isEmpty);
|
||||
|
||||
tester.state<_PaneState>(_pane('b')).focus.requestFocus();
|
||||
await tester.pump();
|
||||
await _chord(tester, LogicalKeyboardKey.controlLeft);
|
||||
expect(h.controller.floatingPane?.sessionId, 'b');
|
||||
expect(h.controller.floatingPanes.firstOrNull?.sessionId, 'b');
|
||||
expect(h.controller.paneCount, 1);
|
||||
expect(find.byKey(const ValueKey('chat-float-title')), findsOneWidget);
|
||||
// The chat moved: same State, same draft, its field has the keyboard.
|
||||
@@ -157,7 +157,7 @@ void main() {
|
||||
expect(a.focus.hasFocus, isTrue);
|
||||
|
||||
// Docking returns the same chat to the tiling.
|
||||
h.controller.dock();
|
||||
h.controller.dock(h.controller.floatingPanes.single.id);
|
||||
await tester.pumpAndSettle();
|
||||
expect(h.controller.paneCount, 2);
|
||||
expect(tester.state<_PaneState>(_pane('b')), same(b));
|
||||
@@ -174,7 +174,7 @@ void main() {
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
|
||||
await _chord(tester, LogicalKeyboardKey.controlLeft);
|
||||
// Nothing to float from the terminal: the shell gets Ctrl+Y (yank).
|
||||
expect(h.controller.floatingPane, isNull);
|
||||
expect(h.controller.floatingPanes, isEmpty);
|
||||
expect(h.typed, contains(LogicalKeyboardKey.keyY));
|
||||
expect(h.typed.where((k) => k == LogicalKeyboardKey.keyY).length, 2);
|
||||
|
||||
@@ -216,7 +216,7 @@ void main() {
|
||||
tester.state<_PaneState>(_pane('b')).focus.requestFocus();
|
||||
await tester.pump();
|
||||
await _chord(tester, LogicalKeyboardKey.controlLeft);
|
||||
expect(h.controller.floatingPane, isNull);
|
||||
expect(h.controller.floatingPanes, isEmpty);
|
||||
// A float saved on a wide window stays, unpainted, with its state.
|
||||
h.controller.float(h.controller.panes.last.id);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
@@ -125,7 +125,9 @@ void main() {
|
||||
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 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']);
|
||||
|
||||
@@ -13,6 +13,12 @@ ChatWorkspaceController _three() => ChatWorkspaceController()
|
||||
List<String> _sessions(ChatWorkspaceController c) =>
|
||||
c.panes.map((p) => p.sessionId).toList();
|
||||
|
||||
List<String> _floating(ChatWorkspaceController c) =>
|
||||
c.floatingPanes.map((p) => p.sessionId).toList();
|
||||
|
||||
ChatWorkspacePane _pane(ChatWorkspaceController c, String session) =>
|
||||
c.panes.firstWhere((p) => p.sessionId == session);
|
||||
|
||||
class _Store implements ChatFloatStore {
|
||||
_Store([this.record]);
|
||||
ChatFloatRecord? record;
|
||||
@@ -30,10 +36,11 @@ class _Store implements ChatFloatStore {
|
||||
void main() {
|
||||
test('float takes a pane out of the tiling and keeps its id', () {
|
||||
final c = _three();
|
||||
final b = c.panes.firstWhere((p) => p.sessionId == 'b');
|
||||
final b = _pane(c, 'b');
|
||||
c.activate(b.id);
|
||||
c.float(b.id);
|
||||
expect(c.floatingPane?.id, b.id);
|
||||
expect(c.floatingPanes.single.id, b.id);
|
||||
expect(c.isFloating(b.id), isTrue);
|
||||
expect(c.floatShown, isTrue);
|
||||
expect(_sessions(c), ['a', 'c']);
|
||||
expect(c.activePane?.sessionId, isNot('b'));
|
||||
@@ -44,37 +51,47 @@ void main() {
|
||||
final c = ChatWorkspaceController()..open('a');
|
||||
expect(c.canFloat(c.panes.single.id), isFalse);
|
||||
c.float(c.panes.single.id);
|
||||
expect(c.floatingPane, isNull);
|
||||
expect(c.floatingPanes, isEmpty);
|
||||
c.splitActive('b', ChatSplitAxis.horizontal);
|
||||
final b = c.activePane!;
|
||||
c.float(b.id);
|
||||
// Closing the last tiled pane docks the floating chat in its place.
|
||||
// The last tiled chat stays: it cannot float too.
|
||||
expect(c.canFloat(c.panes.single.id), isFalse);
|
||||
// Closing the last tiled pane docks the oldest floating chat in its place.
|
||||
c.close(c.panes.single.id);
|
||||
expect(c.floatingPane, isNull);
|
||||
expect(c.floatingPanes, isEmpty);
|
||||
expect(c.panes.single.id, b.id);
|
||||
expect(c.activePaneId, b.id);
|
||||
});
|
||||
|
||||
test('floating another chat swaps it with the floating one', () {
|
||||
test('several chats float together and show or hide together', () {
|
||||
final c = _three();
|
||||
final a = c.panes.firstWhere((p) => p.sessionId == 'a');
|
||||
final c3 = c.panes.firstWhere((p) => p.sessionId == 'c');
|
||||
c.float(a.id);
|
||||
c.float(_pane(c, 'a').id);
|
||||
c.setFloatShown(false);
|
||||
c.float(c3.id);
|
||||
expect(c.floatingPane?.id, c3.id);
|
||||
c.float(_pane(c, 'c').id);
|
||||
expect(_floating(c), ['a', 'c']);
|
||||
// Floating another one shows them all.
|
||||
expect(c.floatShown, isTrue);
|
||||
expect(_sessions(c), ['b']);
|
||||
c.toggleFloatShown();
|
||||
expect(c.floatShown, isFalse);
|
||||
c.toggleFloatShown();
|
||||
expect(c.floatShown, isTrue);
|
||||
// Docking one leaves the other floating.
|
||||
final a = c.floatingPanes.first;
|
||||
c.dock(a.id);
|
||||
expect(_floating(c), ['c']);
|
||||
expect(c.activePaneId, a.id);
|
||||
expect(_sessions(c), ['b', 'a']);
|
||||
expect(c.panes.last.id, a.id);
|
||||
});
|
||||
|
||||
test('dock puts the chat right of the active pane and activates it', () {
|
||||
final c = _three();
|
||||
final b = c.panes.firstWhere((p) => p.sessionId == 'b');
|
||||
final b = _pane(c, 'b');
|
||||
c.float(b.id);
|
||||
final active = c.activePane!;
|
||||
c.dock();
|
||||
expect(c.floatingPane, isNull);
|
||||
c.dock(b.id);
|
||||
expect(c.floatingPanes, isEmpty);
|
||||
expect(c.activePaneId, b.id);
|
||||
final panes = c.panes.map((p) => p.id).toList();
|
||||
expect(panes.indexOf(b.id), panes.indexOf(active.id) + 1);
|
||||
@@ -83,7 +100,7 @@ void main() {
|
||||
|
||||
test('hide, show, reopen, close and /new follow the floating chat', () {
|
||||
final c = _three();
|
||||
final b = c.panes.firstWhere((p) => p.sessionId == 'b');
|
||||
final b = _pane(c, 'b');
|
||||
c.float(b.id);
|
||||
c.toggleFloatShown();
|
||||
expect(c.floatShown, isFalse);
|
||||
@@ -93,55 +110,101 @@ void main() {
|
||||
c.splitActive('b', ChatSplitAxis.vertical);
|
||||
expect(c.paneCount, 2);
|
||||
c.replaceSession('b', 'b2');
|
||||
expect(c.floatingPane?.id, b.id);
|
||||
expect(c.floatingPane?.sessionId, 'b2');
|
||||
expect(c.floatingPanes.single.id, b.id);
|
||||
expect(c.floatingPanes.single.sessionId, 'b2');
|
||||
c.close(b.id);
|
||||
expect(c.floatingPane, isNull);
|
||||
expect(c.floatingPanes, isEmpty);
|
||||
expect(c.paneCount, 2);
|
||||
});
|
||||
|
||||
test('restoreFloat skips open sessions and taken ids', () {
|
||||
test('/new into a session another float holds closes the duplicate', () {
|
||||
final c = _three();
|
||||
c.float(_pane(c, 'a').id);
|
||||
c.float(_pane(c, 'b').id);
|
||||
c.replaceSession('a', 'b');
|
||||
expect(_floating(c), ['b']);
|
||||
});
|
||||
|
||||
test('restoreFloats skips open sessions and taken ids', () {
|
||||
final c = ChatWorkspaceController()
|
||||
..open('a')
|
||||
..splitActive('b', ChatSplitAxis.horizontal);
|
||||
final taken = c.panes.first.id;
|
||||
expect(
|
||||
c.restoreFloat(const ChatWorkspacePane('x', 'a'), shown: true),
|
||||
isFalse,
|
||||
c.restoreFloats([
|
||||
const ChatWorkspacePane('x', 'a'),
|
||||
ChatWorkspacePane(taken, 'z'),
|
||||
], shown: true),
|
||||
0,
|
||||
);
|
||||
expect(c.restoreFloat(ChatWorkspacePane(taken, 'z'), shown: true), isFalse);
|
||||
expect(
|
||||
c.restoreFloat(const ChatWorkspacePane('x', 'z'), shown: false),
|
||||
isTrue,
|
||||
);
|
||||
expect(c.floatingPane?.sessionId, 'z');
|
||||
expect(c.floatShown, isFalse);
|
||||
// A new split id never collides with the floating pane's.
|
||||
expect(
|
||||
c.restoreFloats([
|
||||
const ChatWorkspacePane('x', 'z'),
|
||||
const ChatWorkspacePane('y', 'w'),
|
||||
const ChatWorkspacePane('x', 'v'),
|
||||
], shown: false),
|
||||
2,
|
||||
);
|
||||
expect(_floating(c), ['z', 'w']);
|
||||
expect(c.floatShown, isFalse);
|
||||
// A new split id never collides with a floating pane's.
|
||||
c.splitActive('d', ChatSplitAxis.vertical);
|
||||
expect(c.panes.map((p) => p.id), isNot(contains('x')));
|
||||
expect(
|
||||
c.panes.map((p) => p.id),
|
||||
isNot(anyOf(contains('x'), contains('y'))),
|
||||
);
|
||||
});
|
||||
|
||||
test('a restored layout drops any floating chat', () {
|
||||
test('a restored layout drops every floating chat', () {
|
||||
final c = _three();
|
||||
c.float(c.panes.first.id);
|
||||
c.float(c.panes.first.id);
|
||||
final snapshot = c.snapshot()!;
|
||||
c.restoreLayout(snapshot);
|
||||
expect(c.floatingPane, isNull);
|
||||
expect(c.floatingPanes, isEmpty);
|
||||
});
|
||||
|
||||
test('records round-trip and reject malformed input', () {
|
||||
test('records round-trip, read version 1 and reject malformed input', () {
|
||||
const record = ChatFloatRecord(
|
||||
pane: ChatWorkspacePane('p1', 'server:abc'),
|
||||
panes: [
|
||||
ChatWorkspacePane('p1', 'server:abc'),
|
||||
ChatWorkspacePane('p2', 'server:def'),
|
||||
],
|
||||
shown: true,
|
||||
rect: Rect.fromLTWH(10, 20, 400, 300),
|
||||
frames: {
|
||||
'p1': Rect.fromLTWH(10, 20, 400, 300),
|
||||
'p3': Rect.fromLTWH(1, 2, 330, 250),
|
||||
},
|
||||
);
|
||||
expect(ChatFloatRecord.decode(record.encode()), record);
|
||||
const none = ChatFloatRecord(rect: chatFloatDefaultRect);
|
||||
const none = ChatFloatRecord();
|
||||
expect(ChatFloatRecord.decode(none.encode()), none);
|
||||
expect(
|
||||
ChatFloatRecord.decode(
|
||||
'{"version":1,"rect":[1,2,400,300],"shown":true,'
|
||||
'"pane":{"id":"p","session_id":"s"}}',
|
||||
),
|
||||
const ChatFloatRecord(
|
||||
panes: [ChatWorkspacePane('p', 's')],
|
||||
shown: true,
|
||||
frames: {'p': Rect.fromLTWH(1, 2, 400, 300)},
|
||||
),
|
||||
);
|
||||
expect(
|
||||
ChatFloatRecord.decode('{"version":1,"rect":[0,0,1,1],"pane":null}'),
|
||||
none,
|
||||
);
|
||||
for (final bad in [
|
||||
'',
|
||||
'[]',
|
||||
'{"version":2,"rect":[0,0,1,1]}',
|
||||
'{"version":3,"panes":[],"frames":{}}',
|
||||
'{"version":2,"panes":[]}',
|
||||
'{"version":2,"panes":[7],"frames":{}}',
|
||||
'{"version":2,"panes":[],"frames":{"p":[0,0,-1,1]}}',
|
||||
'{"version":2,"panes":[],"frames":{" p":[0,0,1,1]}}',
|
||||
'{"version":2,"panes":[{"id":"p","session_id":"a"},'
|
||||
'{"id":"p","session_id":"b"}],"frames":{}}',
|
||||
'{"version":1,"rect":[0,0,-1,1]}',
|
||||
'{"version":1,"rect":[0,0,1]}',
|
||||
'{"version":1,"rect":[0,0,1,1],"pane":{"id":" x","session_id":"a"}}',
|
||||
@@ -151,41 +214,62 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
test('frames are kept per pane, cascade by default and restore', () {
|
||||
final frames = ChatFloatFrames();
|
||||
expect(frames.rectFor('a'), chatFloatDefaultRect);
|
||||
expect(
|
||||
frames.rectFor('b', index: 2),
|
||||
chatFloatDefaultRect.shift(const Offset(64, 64)),
|
||||
);
|
||||
frames.move('a', const Rect.fromLTWH(1, 2, 400, 300));
|
||||
expect(frames.rectFor('a', index: 3), const Rect.fromLTWH(1, 2, 400, 300));
|
||||
frames.restore({'b': const Rect.fromLTWH(9, 9, 400, 300)});
|
||||
expect(frames.rectFor('a'), chatFloatDefaultRect);
|
||||
expect(frames.rectFor('b'), const Rect.fromLTWH(9, 9, 400, 300));
|
||||
});
|
||||
|
||||
test('binding restores after the layout and saves changes', () async {
|
||||
final c = ChatWorkspaceController()
|
||||
..open('a')
|
||||
..splitActive('b', ChatSplitAxis.horizontal);
|
||||
final store = _Store(
|
||||
const ChatFloatRecord(
|
||||
pane: ChatWorkspacePane('f', 'c'),
|
||||
panes: [ChatWorkspacePane('f', 'c'), ChatWorkspacePane('g', 'd')],
|
||||
shown: true,
|
||||
rect: Rect.fromLTWH(5, 6, 400, 300),
|
||||
frames: {
|
||||
'f': Rect.fromLTWH(5, 6, 400, 300),
|
||||
'g': Rect.fromLTWH(50, 60, 400, 300),
|
||||
},
|
||||
),
|
||||
);
|
||||
final frame = ChatFloatFrame();
|
||||
final frames = ChatFloatFrames();
|
||||
final binding = ChatFloatBinding(
|
||||
controller: c,
|
||||
frame: frame,
|
||||
frames: frames,
|
||||
store: store,
|
||||
debounce: Duration.zero,
|
||||
);
|
||||
await binding.start();
|
||||
expect(c.floatingPane?.sessionId, 'c');
|
||||
expect(_floating(c), ['c', 'd']);
|
||||
expect(c.floatShown, isTrue);
|
||||
expect(frame.rect, const Rect.fromLTWH(5, 6, 400, 300));
|
||||
expect(frames.rectFor('f'), const Rect.fromLTWH(5, 6, 400, 300));
|
||||
expect(frames.rectFor('g'), const Rect.fromLTWH(50, 60, 400, 300));
|
||||
expect(store.writes, 0);
|
||||
c.setFloatShown(false);
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
await binding.flush();
|
||||
expect(store.record?.shown, isFalse);
|
||||
frame.move(const Rect.fromLTWH(50, 60, 400, 300));
|
||||
frames.move('f', const Rect.fromLTWH(70, 80, 400, 300));
|
||||
final writes = store.writes;
|
||||
await binding.flush();
|
||||
expect(store.writes, writes + 1);
|
||||
expect(store.record?.rect.left, 50);
|
||||
c.dock();
|
||||
expect(store.record?.frames['f']?.left, 70);
|
||||
// A docked chat keeps its frame for the next float; a closed one drops it.
|
||||
c.dock('f');
|
||||
c.close('g');
|
||||
binding.dispose();
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(store.record?.pane, isNull);
|
||||
expect(store.record?.panes, isEmpty);
|
||||
expect(store.record?.frames.keys, ['f']);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user