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
@@ -82,6 +82,30 @@ class FileChange {
parsedPatch: parsedPatch,
);
/// The entry as the server records it ([tryParse] reads it back), with
/// the stages that touched it, so a diff can be handed to another window.
Map<String, Object?> toJson() => {
'path': path,
'kind': kind.name,
'patch': ?patch,
if (binary) 'binary': true,
if (truncated) 'truncated': true,
'no_patch_reason': ?noPatchReason,
'before_mode': ?beforeMode,
'after_mode': ?afterMode,
if (steps.isNotEmpty) 'steps': steps,
};
/// Reads back an entry [toJson] wrote, stages included.
static FileChange? fromHandover(Object? value) {
final file = tryParse(value);
if (file == null || value is! Map) return file;
final steps = value['steps'];
return steps is List && steps.isNotEmpty
? file.withSteps([for (final step in steps) '$step'])
: file;
}
/// Parses one server file entry; null when it has no usable path. The
/// capture owns the decision to skip such an entry, so it is never rendered
/// as an anonymous row.
@@ -14,6 +14,8 @@ import 'diff_search_bar.dart';
import 'diff_search_controller.dart';
import 'file_diff_viewer.dart';
import 'stacked_diff_view.dart';
import '../../../shell/detached/detached_window_scope.dart';
import '../../../shell/windows/window_scope.dart';
import '../windows/diff_windows.dart';
/// Whether diff pages show every file stacked (GitHub's Files changed) rather
@@ -54,6 +56,7 @@ class FileDiffPage extends StatefulWidget {
required this.files,
this.initialIndex = 0,
this.inWindow = false,
this.actions = const [],
});
final List<FileChange> files;
@@ -62,6 +65,10 @@ class FileDiffPage extends StatefulWidget {
/// Shown inside a floating window: no Back, and no Open in a window.
final bool inWindow;
/// The host's own bar buttons, after the diff's (a detached window's
/// Bring back).
final List<Widget> actions;
@override
State<FileDiffPage> createState() => _FileDiffPageState();
}
@@ -184,6 +191,25 @@ class _FileDiffPageState extends State<FileDiffPage> {
windows.open(widget.files, initialIndex: _index);
}
/// Sends the diff to a window of its own; once it opens, this page closes
/// (or the floating window it is in).
void _openInNewWindow(DetachedWindowOpener opener, String title) {
final window = WindowScope.maybeOf(context);
opener.openDiff(
[for (final file in widget.files) file.toJson()],
initialIndex: _index,
title: title,
onOpened: () {
if (!mounted) return;
if (window != null) {
window.manager.close(window.entry.id);
} else {
Navigator.of(context).maybePop();
}
},
);
}
void _toggleFile(int index) => setState(() {
if (!_collapsed.remove(index)) _collapsed.add(index);
});
@@ -288,6 +314,13 @@ class _FileDiffPageState extends State<FileDiffPage> {
),
null => null,
},
if (DetachedWindowScope.maybeOf(context) case final opener?)
IconButton(
key: const ValueKey('diff-open-new-window'),
tooltip: detachedWindowLabel,
onPressed: () => _openInNewWindow(opener, title),
icon: const Icon(Icons.open_in_browser),
),
IconButton(
key: const ValueKey('diff-search-open'),
tooltip: 'Find in diff (/)',
@@ -315,6 +348,7 @@ class _FileDiffPageState extends State<FileDiffPage> {
_all ? Icons.article_outlined : Icons.view_agenda_outlined,
),
),
...widget.actions,
],
),
body: body,
+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
@@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart';
import '../chat/workspace/chat_center_stage_controller.dart';
import '../chat/workspace/chat_float_shortcut.dart';
import '../terminal/terminal_shortcuts.dart';
import '../../shell/detached/detached_window_scope.dart';
import '../../shell/windows/window_shortcuts.dart';
import '../../shell/shell_chat_actions_shortcut.dart';
import '../../shell/shell_chat_shortcut.dart';
@@ -221,6 +222,18 @@ class KeyboardShortcutRegistry {
action: 'Cycle floating windows',
keys: _cycleKeys,
),
// A phone has no windows of its own to send a chat to.
if (web ||
platform == TargetPlatform.linux ||
platform == TargetPlatform.macOS)
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.windows,
action: 'Open the chat in a new window',
keys: detachedWindowShortcutLabel(platform),
caveat:
'Moves the chat that has the keyboard to a browser or app '
'window of its own; its "Bring back to main window" returns it.',
),
];
/// Alt+` (Option+` on macOS) and the same chord with Shift, backwards.
@@ -132,6 +132,10 @@ class TerminalLayout extends ChangeNotifier {
/// Whether the last change could not be saved.
bool saveFailed = false;
/// Whether changes are saved. A detached window reads the device's layout
/// but never writes it: the main window owns it.
bool persist = true;
Future<void> restore() async {
final revision = _revision;
final raw = await _store.load();
@@ -196,6 +200,7 @@ class TerminalLayout extends ChangeNotifier {
/// Saves the current layout (a drag saves once, when it ends).
Future<void> save() async {
if (!persist) return;
final revision = _revision;
final saved = await _store.save(
jsonEncode({
@@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import '../../shell/detached/detached_window_scope.dart';
import 'terminal_browser_keys.dart';
import 'terminal_hub.dart';
import 'terminal_layout.dart';
@@ -67,43 +68,67 @@ class TerminalTabStrip extends StatelessWidget {
);
}
/// The options menu: the modes, the browser keys capture (on a browser
/// that can) and Hide terminal, with the shortcuts under them.
Widget _options(BuildContext context) => TerminalMenuButton<_Option>(
label: 'Terminal options',
info: TerminalShortcutLabels.current().summary,
icon: Icons.more_vert,
choices: [
for (final mode in TerminalMode.values)
TerminalChoice(
_Option(mode),
mode.label,
checked: layout.mode == mode,
key: ValueKey('terminal-mode-${mode.name}'),
/// The options menu: the modes, Open in new window (where the platform
/// has windows), the browser keys capture (on a browser that can) and
/// Hide terminal, with the shortcuts under them.
Widget _options(BuildContext context) {
final opener = DetachedWindowScope.maybeOf(context);
return TerminalMenuButton<_Option>(
label: 'Terminal options',
info: TerminalShortcutLabels.current().summary,
icon: Icons.more_vert,
choices: [
for (final mode in TerminalMode.values)
TerminalChoice(
_Option(mode),
mode.label,
checked: layout.mode == mode,
key: ValueKey('terminal-mode-${mode.name}'),
),
if (opener != null)
const TerminalChoice(
_Option(null, newWindow: true),
detachedWindowLabel,
key: ValueKey('terminal-new-window'),
),
if (browserKeys.supported)
TerminalChoice(
const _Option(null, browserKeys: true),
'Capture browser keys',
checked: browserKeys.active,
key: const ValueKey('terminal-browser-keys'),
),
const TerminalChoice(
_Option(null),
'Hide terminal',
key: ValueKey('terminal-hide'),
),
if (browserKeys.supported)
TerminalChoice(
const _Option(null, browserKeys: true),
'Capture browser keys',
checked: browserKeys.active,
key: const ValueKey('terminal-browser-keys'),
),
const TerminalChoice(
_Option(null),
'Hide terminal',
key: ValueKey('terminal-hide'),
),
],
onSelected: (option) {
if (option.browserKeys) {
unawaited(toggleTerminalBrowserKeys(context, browserKeys));
} else if (option.mode == null) {
layout.hide();
} else {
layout.setMode(option.mode!);
}
},
);
],
onSelected: (option) {
if (option.newWindow) {
_openInNewWindow(opener!);
} else if (option.browserKeys) {
unawaited(toggleTerminalBrowserKeys(context, browserKeys));
} else if (option.mode == null) {
layout.hide();
} else {
layout.setMode(option.mode!);
}
},
);
}
/// The terminal moves to a window of its own, on the selected tab; this
/// one hides it once that window is open. The terminals keep running on
/// the machines, so both windows reach the same shells.
void _openInNewWindow(DetachedWindowOpener opener) {
final tab = hub.selected;
opener.openTerminal(
tabKey: tab?.key ?? '',
title: tab == null ? 'Terminal' : 'Terminal: ${tab.title}',
onOpened: layout.hide,
);
}
String _label(TerminalTab tab) =>
hub.multiMachine ? '${tab.title} · ${tab.machineName}' : tab.title;
@@ -152,7 +177,8 @@ class TerminalTabStrip extends StatelessWidget {
/// A mode to switch to, (null) hiding the terminal, or the browser keys
/// capture.
class _Option {
const _Option(this.mode, {this.browserKeys = false});
const _Option(this.mode, {this.browserKeys = false, this.newWindow = false});
final TerminalMode? mode;
final bool browserKeys;
final bool newWindow;
}