From 417a696785a65baa9c9f7b80efe8ecced75de36a Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 6 Nov 2026 18:24:58 +0000 Subject: [PATCH] Keep background pane updates from stealing destination navigation --- .../features/chat/chat_screen_workspace.dart | 23 ++++++---- app/lib/features/chat/screen.dart | 5 +++ app/notes/multi-chat-workspace.md | 18 ++++++++ .../chat/chat_split_integration_test.dart | 42 +++++++++++++++++++ 4 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 app/notes/multi-chat-workspace.md diff --git a/app/lib/features/chat/chat_screen_workspace.dart b/app/lib/features/chat/chat_screen_workspace.dart index 6a183fda..866bf905 100644 --- a/app/lib/features/chat/chat_screen_workspace.dart +++ b/app/lib/features/chat/chat_screen_workspace.dart @@ -28,15 +28,8 @@ mixin _ChatScreenWorkspace on State { _workspaceSignature = signature; void update() { if (!mounted) return; - final id = _workspace.activePane?.sessionId; setState(() {}); - if (!_workspaceVisible || - id == null || - id == _publishedWorkspaceSession) { - return; - } - _publishedWorkspaceSession = id; - widget.onSessionSelected?.call(id); + _publishWorkspaceRoute(); } if (SchedulerBinding.instance.schedulerPhase == @@ -47,6 +40,20 @@ mixin _ChatScreenWorkspace on State { } } + void _publishWorkspaceRoute() { + if (!mounted) return; + final id = _workspace.activePane?.sessionId; + final destination = ShellBarScope.maybeOf(context)?.registry.focus; + if (!_workspaceVisible || + id == null || + id == _publishedWorkspaceSession || + (destination != null && destination != AppDestination.chat)) { + return; + } + _publishedWorkspaceSession = id; + widget.onSessionSelected?.call(id); + } + void _split(JsonMap session, ChatSplitAxis axis) { final id = '${session['id'] ?? ''}'; if (id.isEmpty) return; diff --git a/app/lib/features/chat/screen.dart b/app/lib/features/chat/screen.dart index b7fab1f0..12a96903 100644 --- a/app/lib/features/chat/screen.dart +++ b/app/lib/features/chat/screen.dart @@ -435,6 +435,11 @@ class _ChatScreenState extends State with _ChatScreenWorkspace { @override Widget build(BuildContext context) { final selected = _selected; + if (_workspaceVisible && selected != _publishedWorkspaceSession) { + WidgetsBinding.instance.addPostFrameCallback( + (_) => _publishWorkspaceRoute(), + ); + } _offeredNext = selected != null && _nextAfter(selected) != null; // A phone opens a chat as a real Navigator page with stock Back. A wide // window keeps the destination rail and the chat list beside the open diff --git a/app/notes/multi-chat-workspace.md b/app/notes/multi-chat-workspace.md new file mode 100644 index 00000000..2f1f6015 --- /dev/null +++ b/app/notes/multi-chat-workspace.md @@ -0,0 +1,18 @@ +# Multiple chat panes + +The chat list's More menu offers **Open to the right** and **Open below** on wide windows. Each action splits the active pane; nested horizontal and vertical splits can be combined. A normal row click or conversation-number shortcut replaces the active pane, or focuses an already-open chat. Each chat appears once in the workspace. + +Drag the divider in either direction to resize. The divider has an accessible label and keyboard arrow resizing; double-click restores an even split. Minimum pane sizes protect the composer. An accent outline identifies the active pane. Clicking a pane activates it without stealing a transcript selection. Closing a pane collapses its adjoining split and never closes or interrupts the underlying chat. + +Keyboard navigation: + +- Ctrl+Shift+Arrow moves to the neighbouring pane; Command+Shift+Arrow also works on macOS. +- With one pane, these keys retain their normal editing behavior. +- Ctrl+/ opens/refocuses Search; Command+/ also works on macOS. The existing query is preserved. +- Ctrl+1…9 and macOS Command+1…9 select conversations only in Chat. Pipelines and Runs no longer consume number shortcuts; Ctrl+Tab no longer cycles destinations. + +Narrow windows show only the active pane, with an **Open chats** picker retaining the others. Widening restores the split layout and drafts. Each leaf has a stable pane identity and its own header registry, composer, transcript, stream filtering and scroll position. Closing a neighbour or resizing does not remount those views. `/new` results update their originating pane even if focus moved while the request was pending. Route navigation names the active chat. The split layout is visit-local, not restored after a browser reload. + +Implementation is app-only; no new backend, pipeline definition or TUI changes. The existing WebSocket multiplexes session streams. A new generic capture key mapping supports physical Slash/left/right key codes for browser acceptance. + +Background `/new` completions update their retained pane without navigating away from Search or another destination. Returning to Chat publishes the current active session route. Narrow-window Back returns to the list without issuing a server chat-close or interrupt request. diff --git a/app/test/features/chat/chat_split_integration_test.dart b/app/test/features/chat/chat_split_integration_test.dart index 39ae2a90..3863a49d 100644 --- a/app/test/features/chat/chat_split_integration_test.dart +++ b/app/test/features/chat/chat_split_integration_test.dart @@ -4,6 +4,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/chat/screen.dart'; +import 'package:pipelines_app/shell/adaptive_shell.dart'; +import 'package:pipelines_app/shell/destination.dart'; import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart'; import 'package:pipelines_app/features/chat/ui/sessions/session_actions.dart'; import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart'; @@ -260,4 +262,44 @@ void main() { await tester.pumpWidget(const SizedBox.shrink()); }, ); + testWidgets( + 'background new-session completion never navigates away from Search', + (tester) async { + final gateway = await _setup(tester); + final opened = []; + await tester.pumpWidget( + MaterialApp( + home: AdaptiveShell( + destination: AppDestination.chat, + destinationBodies: { + AppDestination.chat: (_) => + ChatScreen(gateway: gateway, onSessionSelected: opened.add), + AppDestination.search: (_) => const Text('Search destination'), + }, + ), + ), + ); + await tester.pumpAndSettle(); + await tester.tap(find.text('Chat a').first); + await tester.pumpAndSettle(); + await _split(tester, 'b', 'Open to the right'); + final finishedNew = tester + .widget(_thread('b')) + .onNewSession!; + final before = opened.length; + await tester.tap(find.byKey(const ValueKey('shell.destination.search'))); + await tester.pumpAndSettle(); + finishedNew('b', {'id': 'b-new', 'title': 'Fresh B'}, 'Started fresh'); + await tester.pumpAndSettle(); + expect(find.text('Search destination'), findsOneWidget); + expect(opened.length, before); + await tester.tap(find.byKey(const ValueKey('shell.destination.chat'))); + await tester.pumpAndSettle(); + expect(_thread('a'), findsOneWidget); + expect(_thread('b-new'), findsOneWidget); + expect(opened.last, 'b-new'); + expect(tester.takeException(), isNull); + await tester.pumpWidget(const SizedBox.shrink()); + }, + ); }