From 4f1b45571f5440a6981b487bfcabc8f70966cda5 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Thu, 12 Nov 2026 00:43:03 +0000 Subject: [PATCH] Float the last chat and float from the chat list Any tiled chat can float now, including the only one; the tiling is left empty. A chat list row's More menu offers Float too: a tiled chat leaves the tiling, a chat with a window shows it, any other opens a new window. --- app/lib/features/chat/chat_screen_float.dart | 19 +++++- app/lib/features/chat/screen.dart | 1 + .../chat/ui/sessions/chat_sessions_body.dart | 3 + .../ui/sessions/chat_sessions_screen.dart | 5 ++ .../chat/ui/sessions/session_actions.dart | 9 +++ .../chat/ui/sessions/session_list_items.dart | 2 + .../ui/sessions/session_list_material.dart | 3 + .../chat/ui/sessions/session_row_content.dart | 3 + .../chat/ui/sessions/session_row_memo.dart | 4 ++ .../chat/workspace/chat_workspace_float.dart | 9 +-- app/notes/chat-floating-pane.md | 6 +- .../chat/chat_floating_pane_test.dart | 60 ++++++++++++++++++- .../chat/chat_keyboard_focus_test.dart | 7 +-- .../chat_add_pane_picker_test.dart | 2 +- .../workspace/chat_center_stage_test.dart | 41 +++++++------ .../workspace/chat_workspace_float_test.dart | 10 +++- 16 files changed, 147 insertions(+), 37 deletions(-) diff --git a/app/lib/features/chat/chat_screen_float.dart b/app/lib/features/chat/chat_screen_float.dart index 49b6564d..a138957b 100644 --- a/app/lib/features/chat/chat_screen_float.dart +++ b/app/lib/features/chat/chat_screen_float.dart @@ -44,7 +44,24 @@ mixin _ChatScreenFloat on State, _ChatScreenWorkspace { /// the same frame. void _floatPane(String paneId) { final pane = _workspace.detach(paneId); - if (pane != null) widget.windows?.float(pane.sessionId); + if (pane == null) return; + widget.windows?.float(pane.sessionId); + // Floating the last tiled chat leaves the list, as closing it does. + if (_workspace.paneCount == 0) _back(); + } + + /// The chat list's Float choice: a tiled chat leaves the tiling, a chat + /// already in a window comes to the top, any other opens in a new window. + void _floatSession(JsonMap session) { + final id = '${session['id'] ?? ''}'; + final windows = widget.windows; + if (id.isEmpty || windows == null || windows.show(id)) return; + final pane = _workspace.panes.where((p) => p.sessionId == id).firstOrNull; + if (pane != null) { + _floatPane(pane.id); + } else { + windows.float(id); + } } void _dockSession(String sessionId) { diff --git a/app/lib/features/chat/screen.dart b/app/lib/features/chat/screen.dart index 00f08340..77b66fd5 100644 --- a/app/lib/features/chat/screen.dart +++ b/app/lib/features/chat/screen.dart @@ -466,6 +466,7 @@ class _ChatScreenState extends State onOpen: _openBySelection, onOpenBeside: beside ? _openBeside : null, onOpenBelow: _openBelow, + onFloat: _floatsHere ? _floatSession : null, onShortcutOpen: _openByShortcut, onSessions: _adoptRows, activeSessionId: selected, diff --git a/app/lib/features/chat/ui/sessions/chat_sessions_body.dart b/app/lib/features/chat/ui/sessions/chat_sessions_body.dart index ed73e5e5..c0195db6 100644 --- a/app/lib/features/chat/ui/sessions/chat_sessions_body.dart +++ b/app/lib/features/chat/ui/sessions/chat_sessions_body.dart @@ -33,6 +33,7 @@ class ChatSessionsBody extends StatelessWidget { required this.onOpen, this.onOpenBeside, this.onOpenBelow, + this.onFloat, required this.onRename, required this.onClose, required this.onReopen, @@ -63,6 +64,7 @@ class ChatSessionsBody extends StatelessWidget { final ValueChanged onOpen; final ValueChanged? onOpenBeside; final ValueChanged? onOpenBelow; + final ValueChanged? onFloat; final ValueChanged onRename; final ValueChanged onClose; final ValueChanged onReopen; @@ -100,6 +102,7 @@ class ChatSessionsBody extends StatelessWidget { onOpen: onOpen, onOpenBeside: onOpenBeside, onOpenBelow: onOpenBelow, + onFloat: onFloat, onRename: onRename, onClose: onClose, onReopen: onReopen, diff --git a/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart b/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart index 0cdb7c5c..9328c990 100644 --- a/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart +++ b/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart @@ -32,6 +32,7 @@ class ChatSessionsScreen extends StatefulWidget { required this.onOpen, this.onOpenBeside, this.onOpenBelow, + this.onFloat, this.onShortcutOpen, this.embedded = false, this.syncToken = 0, @@ -50,6 +51,9 @@ class ChatSessionsScreen extends StatefulWidget { final ValueChanged? onOpenBeside; final ValueChanged? onOpenBelow; + /// Floats the chat in a window over the app; absent when it cannot. + final ValueChanged? onFloat; + /// Opens a row the shell's Ctrl+1…Ctrl+9 named, so the destination can put /// the keyboard in its composer; null opens it like a tap ([onOpen]). final void Function(JsonMap session)? onShortcutOpen; @@ -348,6 +352,7 @@ class _ChatSessionsScreenState extends State { onOpenBelow: widget.onOpenBelow == null ? null : _openBelow, + onFloat: widget.onFloat, onRename: _rename, onClose: _close, onReopen: _reopen, diff --git a/app/lib/features/chat/ui/sessions/session_actions.dart b/app/lib/features/chat/ui/sessions/session_actions.dart index 7668c6a9..8043740a 100644 --- a/app/lib/features/chat/ui/sessions/session_actions.dart +++ b/app/lib/features/chat/ui/sessions/session_actions.dart @@ -2,12 +2,14 @@ import 'package:flutter/material.dart'; import '../../../../core/api_gateway.dart'; import '../../domain/chat_sessions.dart'; +import '../../workspace/chat_float_shortcut.dart'; import 'session_row_style.dart'; import '../../../../ui/layout/app_overflow_menu.dart'; enum SessionAction { openBeside, openBelow, + float, star, color, rename, @@ -31,6 +33,7 @@ class SessionActionsButton extends StatelessWidget { this.duplicateTitles = const {}, this.allowOpenBeside = false, this.allowOpenBelow = false, + this.allowFloat = false, }); final JsonMap session; @@ -38,6 +41,7 @@ class SessionActionsButton extends StatelessWidget { final Set duplicateTitles; final bool allowOpenBeside; final bool allowOpenBelow; + final bool allowFloat; @override Widget build(BuildContext context) { @@ -55,6 +59,11 @@ class SessionActionsButton extends StatelessWidget { value: SessionAction.openBelow, label: 'Open below', ), + if (allowFloat) + AppMenuAction( + value: SessionAction.float, + label: 'Float (${chatFloatShortcutLabel()})', + ), for (final item in _items(session)) AppMenuAction(value: item.action, label: item.label), ], diff --git a/app/lib/features/chat/ui/sessions/session_list_items.dart b/app/lib/features/chat/ui/sessions/session_list_items.dart index b698567e..e3d09e70 100644 --- a/app/lib/features/chat/ui/sessions/session_list_items.dart +++ b/app/lib/features/chat/ui/sessions/session_list_items.dart @@ -89,6 +89,7 @@ SessionListItem chatSessionRowItem( required ValueChanged onOpen, ValueChanged? onOpenBeside, ValueChanged? onOpenBelow, + ValueChanged? onFloat, required ValueChanged onStar, required ValueChanged? onColor, required ValueChanged onRename, @@ -111,6 +112,7 @@ SessionListItem chatSessionRowItem( onOpen: onOpen, onOpenBeside: onOpenBeside, onOpenBelow: onOpenBelow, + onFloat: onFloat, onStar: onStar, onColor: onColor, onRename: onRename, diff --git a/app/lib/features/chat/ui/sessions/session_list_material.dart b/app/lib/features/chat/ui/sessions/session_list_material.dart index f86fd746..72079023 100644 --- a/app/lib/features/chat/ui/sessions/session_list_material.dart +++ b/app/lib/features/chat/ui/sessions/session_list_material.dart @@ -15,6 +15,7 @@ class MaterialSessionList extends StatelessWidget { required this.onOpen, this.onOpenBeside, this.onOpenBelow, + this.onFloat, required this.onRename, required this.onClose, required this.onReopen, @@ -41,6 +42,7 @@ class MaterialSessionList extends StatelessWidget { final ValueChanged onOpen; final ValueChanged? onOpenBeside; final ValueChanged? onOpenBelow; + final ValueChanged? onFloat; final ValueChanged onRename; final ValueChanged onClose; final ValueChanged onReopen; @@ -114,6 +116,7 @@ class MaterialSessionList extends StatelessWidget { onOpen: onOpen, onOpenBeside: onOpenBeside, onOpenBelow: onOpenBelow, + onFloat: onFloat, onStar: onStar, onColor: onColor, onRename: onRename, diff --git a/app/lib/features/chat/ui/sessions/session_row_content.dart b/app/lib/features/chat/ui/sessions/session_row_content.dart index 21eca855..f16125be 100644 --- a/app/lib/features/chat/ui/sessions/session_row_content.dart +++ b/app/lib/features/chat/ui/sessions/session_row_content.dart @@ -33,6 +33,7 @@ class ChatSessionRow extends StatelessWidget { required this.onOpen, this.onOpenBeside, this.onOpenBelow, + this.onFloat, required this.onAction, this.selected = false, this.visible = false, @@ -50,6 +51,7 @@ class ChatSessionRow extends StatelessWidget { final ValueChanged onOpen; final ValueChanged? onOpenBeside; final ValueChanged? onOpenBelow; + final ValueChanged? onFloat; final VoidCallback? onLongPress; final ValueChanged onAction; final bool selected; @@ -164,6 +166,7 @@ class ChatSessionRow extends StatelessWidget { onSelected: onAction, allowOpenBeside: onOpenBeside != null, allowOpenBelow: onOpenBelow != null, + allowFloat: onFloat != null, ), ), ); diff --git a/app/lib/features/chat/ui/sessions/session_row_memo.dart b/app/lib/features/chat/ui/sessions/session_row_memo.dart index 5db549af..4753179a 100644 --- a/app/lib/features/chat/ui/sessions/session_row_memo.dart +++ b/app/lib/features/chat/ui/sessions/session_row_memo.dart @@ -22,6 +22,7 @@ Widget memoChatSessionRow({ required ValueChanged onOpen, ValueChanged? onOpenBeside, ValueChanged? onOpenBelow, + ValueChanged? onFloat, required ValueChanged onStar, required ValueChanged? onColor, required ValueChanged onRename, @@ -42,6 +43,7 @@ Widget memoChatSessionRow({ onOpen, onOpenBeside, onOpenBelow, + onFloat, onStar, onColor, onRename, @@ -60,6 +62,7 @@ Widget memoChatSessionRow({ onOpen: onOpen, onOpenBeside: onOpenBeside, onOpenBelow: onOpenBelow, + onFloat: onFloat, // A long-press is the touch way to the colour, the row's quick mark. onLongPress: selectionOnly || onColor == null ? null @@ -67,6 +70,7 @@ Widget memoChatSessionRow({ onAction: (action) => switch (action) { SessionAction.openBeside => onOpenBeside?.call(session), SessionAction.openBelow => onOpenBelow?.call(session), + SessionAction.float => onFloat?.call(session), SessionAction.star => onStar(session), SessionAction.color => onColor?.call(session), SessionAction.rename => onRename(session), diff --git a/app/lib/features/chat/workspace/chat_workspace_float.dart b/app/lib/features/chat/workspace/chat_workspace_float.dart index 841a0477..45a256df 100644 --- a/app/lib/features/chat/workspace/chat_workspace_float.dart +++ b/app/lib/features/chat/workspace/chat_workspace_float.dart @@ -8,9 +8,8 @@ extension ChatWorkspaceFloat on ChatWorkspaceController { bool holdsSession(String sessionId) => panes.any((pane) => pane.sessionId == sessionId); - /// A tiled pane can float while another chat stays in the tiling. - bool canFloat(String paneId) => - paneCount > 1 && panes.any((pane) => pane.id == paneId); + /// Any tiled pane can float, the last one too; the tiling is then empty. + bool canFloat(String paneId) => panes.any((pane) => pane.id == paneId); /// Takes the tiled pane [paneId] out of the tiling for a window; the pane /// beside it becomes active. Null when it cannot float. @@ -21,7 +20,9 @@ extension ChatWorkspaceFloat on ChatWorkspaceController { _root = _remove(_root!, paneId); if (_active == paneId) { final after = panes; - _active = after[index.clamp(0, after.length - 1)].id; + _active = after.isEmpty + ? null + : after[index.clamp(0, after.length - 1)].id; } _changed(); return pane; diff --git a/app/notes/chat-floating-pane.md b/app/notes/chat-floating-pane.md index 55fa714b..54407bbc 100644 --- a/app/notes/chat-floating-pane.md +++ b/app/notes/chat-floating-pane.md @@ -8,8 +8,10 @@ every destination and come back at app start without Chat being opened. ## Behaviour - **Float**: a tiled pane's More menu offers `Float (Alt+Y)` (`Option+Y` on - Apple platforms) when another chat stays in the tiling; the last tiled chat - cannot float. Any number of chats can float. A new window opens where that + Apple platforms), the last tiled chat too; floating it leaves the tiling + empty and returns to the list. A chat list row's More menu offers the same + Float: a tiled chat leaves the tiling, a chat with a window shows it, any + other chat opens in a new window. Any number of chats can float. A new window opens where that chat's window last was, else at the default frame stepped 32 px per chat window already open. - **Window**: drag the title bar to move, the lower right corner to resize, diff --git a/app/test/features/chat/chat_floating_pane_test.dart b/app/test/features/chat/chat_floating_pane_test.dart index d8d1fa15..d5b13fea 100644 --- a/app/test/features/chat/chat_floating_pane_test.dart +++ b/app/test/features/chat/chat_floating_pane_test.dart @@ -247,7 +247,7 @@ void main() { findsOneWidget, ); - // The lone tiled pane cannot float: the tiling would be empty. + // The lone tiled pane can float too. await tester.tap( find .descendant( @@ -257,7 +257,7 @@ void main() { .hitTestable(), ); await tester.pumpAndSettle(); - expect(find.textContaining('Float'), findsNothing); + expect(find.text('Float (Alt+Y)'), findsOneWidget); await tester.tapAt(const Offset(5, 995)); await tester.pumpAndSettle(); @@ -277,6 +277,62 @@ void main() { await app.stop(tester); }); + testWidgets('the last tiled chat floats and leaves the tiling empty', ( + tester, + ) async { + await _saved('a', 'b'); + final app = _App(_Store()); + await app.start(tester); + await _menu(tester, 'b', 'Float (Alt+Y)'); + final controller = _workspace(tester); + final a = tester.state(_thread('a')); + await _menu(tester, 'a', 'Float (Alt+Y)'); + expect(app.floating, ['b', 'a']); + expect(controller.paneCount, 0); + expect(tester.state(_thread('a')), same(a)); + await tester.tap( + find.descendant(of: _window('Chat a'), matching: find.byTooltip('Dock')), + ); + await tester.pumpAndSettle(); + expect(app.floating, ['b']); + expect(_workspace(tester).panes.map((p) => p.sessionId), ['a']); + expect(tester.state(_thread('a')), same(a)); + expect(tester.takeException(), isNull); + await app.stop(tester); + }); + + testWidgets('the chat list More menu floats a chat', (tester) async { + await _saved('a', 'b'); + final app = _App(_Store()); + await app.start(tester); + // Windows sit over the list, so each choice is made with them hidden. + Future listFloat(String id) async { + app.manager.setGroupShown(chatWindowKind, false); + await tester.pumpAndSettle(); + await tester.tap(find.byTooltip('Chat actions for Chat $id').first); + await tester.pumpAndSettle(); + await tester.tap(find.text('Float (Alt+Y)').last); + await tester.pumpAndSettle(); + } + + // A tiled chat leaves the tiling for its window, keeping its view. + final b = tester.state(_thread('b')); + await listFloat('b'); + expect(app.floating, ['b']); + expect(_workspace(tester).panes.map((p) => p.sessionId), ['a']); + expect(tester.state(_thread('b')), same(b)); + // A chat that is not open gets a window of its own. + await listFloat('c'); + expect(app.floating, ['b', 'c']); + expect(_workspace(tester).panes.map((p) => p.sessionId), ['a']); + // A chat that already has a window shows it instead of opening another. + await listFloat('b'); + expect(app.floating, unorderedEquals(['b', 'c'])); + expect(_shown('Chat b'), findsOneWidget); + expect(tester.takeException(), isNull); + await app.stop(tester); + }); + testWidgets('X closes the window and returns nothing to the tiling', ( tester, ) async { diff --git a/app/test/features/chat/chat_keyboard_focus_test.dart b/app/test/features/chat/chat_keyboard_focus_test.dart index 7532bb0f..ce38721e 100644 --- a/app/test/features/chat/chat_keyboard_focus_test.dart +++ b/app/test/features/chat/chat_keyboard_focus_test.dart @@ -53,11 +53,8 @@ Future _setup(WidgetTester tester) async { destination: AppDestination.chat, destinationBodies: { AppDestination.chat: (_) => ChatScreen(gateway: gateway), - AppDestination.search: (_) => SearchScreen( - gateway: gateway, - onOpen: (_) {}, - embedded: true, - ), + AppDestination.search: (_) => + SearchScreen(gateway: gateway, onOpen: (_) {}, embedded: true), }, ), ), diff --git a/app/test/features/chat/conversation/chat_add_pane_picker_test.dart b/app/test/features/chat/conversation/chat_add_pane_picker_test.dart index f5b52e33..2de2a6a3 100644 --- a/app/test/features/chat/conversation/chat_add_pane_picker_test.dart +++ b/app/test/features/chat/conversation/chat_add_pane_picker_test.dart @@ -148,7 +148,7 @@ void main() { addTearDown(gateway.pushed.close); await controller.refresh(); await mountPicker(tester, controller, folds); - await controller.hide('b'); + await controller.hide('b'); await tester.pumpAndSettle(); expect(find.byKey(const Key('chat-row-b')), findsNothing); folds.set('Closed', false); diff --git a/app/test/features/chat/workspace/chat_center_stage_test.dart b/app/test/features/chat/workspace/chat_center_stage_test.dart index 8de34cc5..52bc959f 100644 --- a/app/test/features/chat/workspace/chat_center_stage_test.dart +++ b/app/test/features/chat/workspace/chat_center_stage_test.dart @@ -491,26 +491,29 @@ void main() { ); } - test('Alt+E toggles by physical key position, including Option dead keys', () { - const event = KeyDownEvent( - physicalKey: PhysicalKeyboardKey.keyE, - logicalKey: LogicalKeyboardKey(0x00B4), - character: '´', - timeStamp: Duration.zero, - ); - expect(chatCenterStageShortcut(event, _AltHeld()), isTrue); - expect( - chatCenterStageShortcut( - const KeyUpEvent( - physicalKey: PhysicalKeyboardKey.keyE, - logicalKey: LogicalKeyboardKey(0x00B4), - timeStamp: Duration.zero, + test( + 'Alt+E toggles by physical key position, including Option dead keys', + () { + const event = KeyDownEvent( + physicalKey: PhysicalKeyboardKey.keyE, + logicalKey: LogicalKeyboardKey(0x00B4), + character: '´', + timeStamp: Duration.zero, + ); + expect(chatCenterStageShortcut(event, _AltHeld()), isTrue); + expect( + chatCenterStageShortcut( + const KeyUpEvent( + physicalKey: PhysicalKeyboardKey.keyE, + logicalKey: LogicalKeyboardKey(0x00B4), + timeStamp: Duration.zero, + ), + _AltHeld(), ), - _AltHeld(), - ), - isFalse, - ); - }); + isFalse, + ); + }, + ); testWidgets('Alt+E toggles from a focused composer without typing', ( tester, diff --git a/app/test/features/chat/workspace/chat_workspace_float_test.dart b/app/test/features/chat/workspace/chat_workspace_float_test.dart index 0448216b..90da3f3e 100644 --- a/app/test/features/chat/workspace/chat_workspace_float_test.dart +++ b/app/test/features/chat/workspace/chat_workspace_float_test.dart @@ -27,13 +27,17 @@ void main() { expect(c.holdsSession('b'), isFalse); }); - test('a lone pane cannot leave: the tiling never empties by floating', () { + test('the lone pane floats too and leaves the tiling empty', () { final c = ChatWorkspaceController()..open('a'); final only = c.panes.single; - expect(c.canFloat(only.id), isFalse); - expect(c.detach(only.id), isNull); + expect(c.canFloat(only.id), isTrue); expect(c.detach('nope'), isNull); + expect(c.detach(only.id)?.sessionId, 'a'); + expect(c.paneCount, 0); + expect(c.activePane, isNull); + c.dock('a'); expect(_sessions(c), ['a']); + expect(c.activePane?.sessionId, 'a'); }); test('dock puts the chat right of the active pane and activates it', () {