diff --git a/app/lib/features/chat/screen.dart b/app/lib/features/chat/screen.dart index 4f5420c6..7286deab 100644 --- a/app/lib/features/chat/screen.dart +++ b/app/lib/features/chat/screen.dart @@ -256,6 +256,10 @@ class _ChatScreenState extends State _openedSessions[id] = session; _workspaceVisible = true; _workspace.open(id); + // A docked chat chosen while chat windows float over the workspace would + // open behind them: hide the windows so the chosen chat is seen. + final windows = widget.windows; + if (windows != null && !windows.holds(id)) windows.hideAll(); if (_runtime.startNotice?.id != id) _runtime.startNotice = null; final select = widget.onSessionSelected; if (select != null) { diff --git a/app/lib/features/chat/windows/chat_windows.dart b/app/lib/features/chat/windows/chat_windows.dart index 0a57fa51..14f68a5e 100644 --- a/app/lib/features/chat/windows/chat_windows.dart +++ b/app/lib/features/chat/windows/chat_windows.dart @@ -132,6 +132,13 @@ class ChatWindows { return true; } + /// Whether [sessionId] is in a chat window. + bool holds(String sessionId) => + manager.find(chatWindowKind, sessionId) != null; + + /// Hides every chat window (the group stays, to be shown again later). + void hideAll() => manager.setGroupShown(chatWindowKind, false); + /// Opens [sessionId] in a window (the caller took it out of the tiling). void float(String sessionId) => manager.open(chatWindowKind, sessionId); diff --git a/app/test/features/chat/chat_floating_pane_test.dart b/app/test/features/chat/chat_floating_pane_test.dart index 971465fc..2ee3af77 100644 --- a/app/test/features/chat/chat_floating_pane_test.dart +++ b/app/test/features/chat/chat_floating_pane_test.dart @@ -425,6 +425,35 @@ void main() { await app.stop(tester); }); + testWidgets('choosing a docked chat hides the floating windows; choosing ' + 'a floating one shows it', (tester) async { + await _saved('a', 'b', 'c'); + final app = _App(_Store()); + await app.start(tester); + await _menu(tester, 'c', 'Float (Alt+Y)'); + expect(app.floating, ['c']); + expect(_shown('Chat c'), findsOneWidget); + + // Ctrl+Tab to the other docked chat hides the window over the tiling. + await tester.tapAt(tester.getCenter(_input('a'))); + await tester.pump(); + await _tab(tester); + expect(_workspace(tester).activePane?.sessionId, 'b'); + expect(_shown('Chat c'), findsNothing); + expect(app.floating, ['c']); + + // Choosing the floating chat from the list brings its window back. + await tester.tap(find.byTooltip('Chat actions for Chat c').first); + await tester.pumpAndSettle(); + await tester.sendKeyEvent(LogicalKeyboardKey.escape); + await tester.pumpAndSettle(); + await tester.tap(find.text('Chat c').first); + await tester.pumpAndSettle(); + expect(_shown('Chat c'), findsOneWidget); + expect(tester.takeException(), isNull); + await app.stop(tester); + }); + testWidgets('X minimises the window: the chat stays open, returns nothing ' 'to the tiling, and the chord brings the window back', (tester) async { await _saved('a', 'b'); @@ -617,8 +646,8 @@ void main() { expect(_composerFocused(tester, 'a'), isTrue); expect(app.floating, ['c']); - // No window shown: the panes cycle and the hidden window stays hidden. - await _chord(tester); + // Choosing a docked chat hid the window; the panes keep cycling and the + // hidden window stays hidden. expect(_shown('Chat c'), findsNothing); await tester.tapAt(tester.getCenter(_input('a'))); await tester.pump();