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.
This commit is contained in:
2026-11-12 00:43:03 +00:00
parent b264043eee
commit 4f1b45571f
16 changed files with 147 additions and 37 deletions
+18 -1
View File
@@ -44,7 +44,24 @@ mixin _ChatScreenFloat on State<ChatScreen>, _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) {
+1
View File
@@ -466,6 +466,7 @@ class _ChatScreenState extends State<ChatScreen>
onOpen: _openBySelection,
onOpenBeside: beside ? _openBeside : null,
onOpenBelow: _openBelow,
onFloat: _floatsHere ? _floatSession : null,
onShortcutOpen: _openByShortcut,
onSessions: _adoptRows,
activeSessionId: selected,
@@ -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<JsonMap> onOpen;
final ValueChanged<JsonMap>? onOpenBeside;
final ValueChanged<JsonMap>? onOpenBelow;
final ValueChanged<JsonMap>? onFloat;
final ValueChanged<JsonMap> onRename;
final ValueChanged<JsonMap> onClose;
final ValueChanged<JsonMap> onReopen;
@@ -100,6 +102,7 @@ class ChatSessionsBody extends StatelessWidget {
onOpen: onOpen,
onOpenBeside: onOpenBeside,
onOpenBelow: onOpenBelow,
onFloat: onFloat,
onRename: onRename,
onClose: onClose,
onReopen: onReopen,
@@ -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<JsonMap>? onOpenBeside;
final ValueChanged<JsonMap>? onOpenBelow;
/// Floats the chat in a window over the app; absent when it cannot.
final ValueChanged<JsonMap>? 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<ChatSessionsScreen> {
onOpenBelow: widget.onOpenBelow == null
? null
: _openBelow,
onFloat: widget.onFloat,
onRename: _rename,
onClose: _close,
onReopen: _reopen,
@@ -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<String> 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),
],
@@ -89,6 +89,7 @@ SessionListItem chatSessionRowItem(
required ValueChanged<JsonMap> onOpen,
ValueChanged<JsonMap>? onOpenBeside,
ValueChanged<JsonMap>? onOpenBelow,
ValueChanged<JsonMap>? onFloat,
required ValueChanged<JsonMap> onStar,
required ValueChanged<JsonMap>? onColor,
required ValueChanged<JsonMap> onRename,
@@ -111,6 +112,7 @@ SessionListItem chatSessionRowItem(
onOpen: onOpen,
onOpenBeside: onOpenBeside,
onOpenBelow: onOpenBelow,
onFloat: onFloat,
onStar: onStar,
onColor: onColor,
onRename: onRename,
@@ -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<JsonMap> onOpen;
final ValueChanged<JsonMap>? onOpenBeside;
final ValueChanged<JsonMap>? onOpenBelow;
final ValueChanged<JsonMap>? onFloat;
final ValueChanged<JsonMap> onRename;
final ValueChanged<JsonMap> onClose;
final ValueChanged<JsonMap> onReopen;
@@ -114,6 +116,7 @@ class MaterialSessionList extends StatelessWidget {
onOpen: onOpen,
onOpenBeside: onOpenBeside,
onOpenBelow: onOpenBelow,
onFloat: onFloat,
onStar: onStar,
onColor: onColor,
onRename: onRename,
@@ -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<JsonMap> onOpen;
final ValueChanged<JsonMap>? onOpenBeside;
final ValueChanged<JsonMap>? onOpenBelow;
final ValueChanged<JsonMap>? onFloat;
final VoidCallback? onLongPress;
final ValueChanged<SessionAction> onAction;
final bool selected;
@@ -164,6 +166,7 @@ class ChatSessionRow extends StatelessWidget {
onSelected: onAction,
allowOpenBeside: onOpenBeside != null,
allowOpenBelow: onOpenBelow != null,
allowFloat: onFloat != null,
),
),
);
@@ -22,6 +22,7 @@ Widget memoChatSessionRow({
required ValueChanged<JsonMap> onOpen,
ValueChanged<JsonMap>? onOpenBeside,
ValueChanged<JsonMap>? onOpenBelow,
ValueChanged<JsonMap>? onFloat,
required ValueChanged<JsonMap> onStar,
required ValueChanged<JsonMap>? onColor,
required ValueChanged<JsonMap> 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),
@@ -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;
+4 -2
View File
@@ -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,
@@ -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<void> 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 {
@@ -53,11 +53,8 @@ Future<void> _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),
},
),
),
@@ -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);
@@ -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,
@@ -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', () {