App: open a chat, the terminal or a diff in a new window

"Open in new window" sits beside Float: the chat pane and chat list row
menus, a floating chat window's title bar, the terminal options menu and
the diff bar, plus Alt+Shift+Y for the chat with the keyboard (listed in
the shortcut help). Once the window opens the item leaves the main window
as Float takes a pane out of the tiling.

The window is its own app instance at /window/chat/<id>,
/window/terminal?tab=<key> or /window/diff/<token>: only that item, named
after it, with "Bring back to main window". It has its own connection and
writes no shared layout (no open-chat workspace, window store or terminal
layout) and posts no notifications, so they stay the main window's.

Web opens a popup window (a blocked popup offers a tab); Linux and macOS
start a second process with --detached (Flutter's multi-window API is still
experimental); Android and iOS hide the action. The capture kit gains a
follow step for windows a page opens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 12:47:42 +00:00
parent c4de1de27b
commit 61c7eee2b0
46 changed files with 3223 additions and 72 deletions
+32 -7
View File
@@ -25,6 +25,8 @@ mixin _ChatScreenFloat on State<ChatScreen>, _ChatScreenWorkspace {
final pane = _workspace.activePane;
if (pane != null) _floatPane(pane.id);
},
release: _releaseSession,
activeSession: () => _workspace.activePane?.sessionId,
);
}
@@ -66,6 +68,19 @@ mixin _ChatScreenFloat on State<ChatScreen>, _ChatScreenWorkspace {
}
}
/// [sessionId] went to a window of its own: its panes leave the tiling,
/// as a floated pane does, and the list shows when none is left.
void _releaseSession(String sessionId) {
if (!mounted) return;
final panes = _workspace.panes.where((p) => p.sessionId == sessionId);
if (panes.isEmpty) return;
for (final pane in panes.toList()) {
_workspace.detach(pane.id);
}
_syncOpenWorkspace();
if (_workspace.paneCount == 0) _back();
}
void _dockSession(String sessionId) {
if (!mounted) return;
_workspaceVisible = true;
@@ -75,15 +90,25 @@ mixin _ChatScreenFloat on State<ChatScreen>, _ChatScreenWorkspace {
_composerFocus.request(sessionId);
}
/// The pane menu's Float choice, on a tiled pane that can.
/// The pane menu's Float choice, on a tiled pane that can, and Open in
/// new window where the platform has windows.
List<Widget> _floatControls(ChatWorkspacePane pane) {
if (!_floatsHere || !_workspace.canFloat(pane.id)) return const [];
final windows = widget.windows;
if (windows == null || !_workspace.canFloat(pane.id)) return const [];
return [
ChatBarAction(
label: 'Float (${chatFloatShortcutLabel()})',
onPressed: () => _floatPane(pane.id),
materialIcon: Icons.picture_in_picture_alt_outlined,
),
if (_floatsHere)
ChatBarAction(
label: 'Float (${chatFloatShortcutLabel()})',
onPressed: () => _floatPane(pane.id),
materialIcon: Icons.picture_in_picture_alt_outlined,
),
if (windows.detached != null)
ChatBarAction(
label: detachedChatWindowLabel(),
identifier: 'chat-open-new-window',
onPressed: () => windows.detach(pane.sessionId),
materialIcon: Icons.open_in_browser,
),
];
}
}
@@ -43,6 +43,12 @@ mixin _ChatScreenPaneMenu on State<ChatScreen>, _ChatScreenWorkspace
final moves = pane == null ? null : _paneMoveTargets[pane.id];
final directory = '${session['directory'] ?? ''}'.trim();
return [
if (widget.windows?.detached != null)
(
action: SessionPaneAction.newWindow,
label: detachedChatWindowLabel(),
enabled: true,
),
(
action: SessionPaneAction.addPane,
label: 'Add chat pane',
@@ -97,6 +103,8 @@ mixin _ChatScreenPaneMenu on State<ChatScreen>, _ChatScreenWorkspace
final id = '${session['id'] ?? ''}';
if (id.isEmpty) return;
switch (action) {
case SessionPaneAction.newWindow:
widget.windows?.detach(id);
case SessionPaneAction.addPane:
_openBySelection(session);
_addPane(context);
+1
View File
@@ -22,6 +22,7 @@ import 'package:flutter/services.dart';
import '../../core/api_gateway.dart';
import '../../core/servers/server_context.dart';
import '../../core/servers/server_scope.dart';
import '../../shell/detached/detached_window_scope.dart';
import '../../shell/windows/window_scope.dart';
import 'shell/chat_shell_dismiss.dart';
import '../terminal/terminal_open_action.dart';
@@ -105,6 +105,7 @@ class SessionActionsButton extends StatelessWidget {
}
IconData _paneIcon(SessionPaneAction action) => switch (action) {
SessionPaneAction.newWindow => Icons.open_in_browser,
SessionPaneAction.addPane => Icons.add_box_outlined,
SessionPaneAction.openChats => Icons.view_quilt_outlined,
SessionPaneAction.centerStage => Icons.center_focus_strong_outlined,
@@ -4,6 +4,7 @@ import '../../../../core/api_gateway.dart';
/// The pane More menu's choices that a chat row's menu also offers.
enum SessionPaneAction {
newWindow,
addPane,
openChats,
centerStage,
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../../../core/api_gateway.dart';
import '../../../shell/detached/detached_window_scope.dart';
import '../../../shell/list_detail_policy.dart';
import '../../../shell/windows/window_entry.dart';
import '../../../shell/windows/window_kind.dart';
@@ -25,6 +26,8 @@ class ChatTiling {
required this.dock,
required this.canFloatActive,
required this.floatActive,
this.release,
this.activeSession,
});
/// Whether the tiling shows [sessionId].
@@ -36,6 +39,13 @@ class ChatTiling {
/// Whether the chord can float the active pane now.
final bool Function() canFloatActive;
final VoidCallback floatActive;
/// Takes [sessionId]'s panes out of the tiling (it went to a window of
/// its own).
final void Function(String sessionId)? release;
/// The active pane's chat.
final String? Function()? activeSession;
}
/// The floating chat windows, for the app's lifetime: the `chat` window kind
@@ -66,6 +76,10 @@ class ChatWindows {
/// The mounted Chat destination's tiling, if it is built.
ChatTiling? tiling;
/// Opens a chat in a window of its own (a browser window or app process);
/// null where the platform has none.
DetachedWindowOpener? detached;
late final ChatWindowKind kind = ChatWindowKind(this);
bool _started = false;
@@ -86,7 +100,8 @@ class ChatWindows {
manager.kinds.register(kind);
FocusManager.instance
..addEarlyKeyEventHandler(_key)
..addEarlyKeyEventHandler(_tabKey);
..addEarlyKeyEventHandler(_tabKey)
..addEarlyKeyEventHandler(_detachKey);
runtime.addSessionReplacedListener(_replacedElsewhere);
runtime.sessions.addListener(_rowsChanged);
manager.addListener(_rowsChanged);
@@ -98,7 +113,8 @@ class ChatWindows {
_started = false;
FocusManager.instance
..removeEarlyKeyEventHandler(_key)
..removeEarlyKeyEventHandler(_tabKey);
..removeEarlyKeyEventHandler(_tabKey)
..removeEarlyKeyEventHandler(_detachKey);
runtime.removeSessionReplacedListener(_replacedElsewhere);
runtime.sessions.removeListener(_rowsChanged);
manager.removeListener(_rowsChanged);
@@ -154,6 +170,35 @@ class ChatWindows {
}
}
/// Opens [sessionId] in a window of its own. Once that window is open the
/// chat leaves this one: its floating window closes and its tiled panes
/// close, as Float takes a pane out of the tiling.
void detach(String sessionId) {
final opener = detached;
if (opener == null || sessionId.isEmpty) return;
opener.openChat(
sessionId,
title: runtime.titleFor(sessionId),
onOpened: () {
final entry = manager.find(chatWindowKind, sessionId);
if (entry != null) manager.close(entry.id);
tiling?.release?.call(sessionId);
},
);
}
/// A detached window gave [sessionId] back: it goes into the tiling, or
/// opens in the Chat destination when that is not built.
void bringBack(String sessionId) {
if (sessionId.isEmpty) return;
final tiling = this.tiling;
if (tiling != null) {
tiling.dock(sessionId);
} else {
openInChat(sessionId);
}
}
/// `/new` in a window's chat: the window follows the new session, unless
/// that session is already open elsewhere.
void startedNewSession(
@@ -242,6 +287,29 @@ class ChatWindows {
return KeyEventResult.handled;
}
/// Alt+Shift+Y sends the chat with the keyboard (a floating window's, else
/// the active tiled pane's) to a new window. Left alone when there is no
/// such chat or no platform window.
KeyEventResult _detachKey(KeyEvent event) {
if (detached == null ||
!detachedWindowShortcut(event, HardwareKeyboard.instance)) {
return KeyEventResult.ignored;
}
final scope = keyboardWindow();
String? id;
if (scope != null) {
if (scope.entry.kind == chatWindowKind) id = scope.entry.contentId;
} else {
final tiling = this.tiling;
if (tiling != null && tiling.canFloatActive()) {
id = tiling.activeSession?.call();
}
}
if (id == null || id.isEmpty) return KeyEventResult.ignored;
if (event is KeyDownEvent) detach(id);
return KeyEventResult.handled;
}
/// Ctrl+Tab and Ctrl+Shift+Tab while a floating chat window holds the
/// keyboard: the next (previous) shown chat window, in open order and
/// wrapping, comes to the top. The window host then gives it the keyboard,
@@ -350,6 +418,12 @@ class ChatWindowKind extends WindowKind {
icon: Icons.vertical_split_outlined,
onPressed: () => windows.dock(entry),
),
if (windows.detached != null)
WindowAction(
label: detachedChatWindowLabel(),
icon: Icons.open_in_browser,
onPressed: () => windows.detach(entry.contentId),
),
];
@override