Rebind chat file and center-stage shortcuts

Give Cmd/Ctrl+E to the active chat Files panel while preserving terminal behavior, and move Center Stage to the shifted chord. Update shortcut documentation and regression coverage for the new bindings.
This commit is contained in:
2026-11-12 19:52:39 +00:00
parent 19b1d1326a
commit 3029295b1f
15 changed files with 382 additions and 52 deletions
@@ -25,6 +25,7 @@ class ChatPanePlacement {
this.ownsPasteWhenFocused = false,
this.paneControls,
this.paneCommands,
this.onComposerFocus,
this.onNextChat,
});
@@ -55,6 +56,7 @@ class ChatPanePlacement {
/// Choices the chat list hands to this chat's conversation to run.
final ChatPaneCommands? paneCommands;
final VoidCallback? onComposerFocus;
final VoidCallback? onNextChat;
}
@@ -115,6 +117,7 @@ Widget buildChatPaneContent({
showBackButton: placement.showBackButton,
paneControls: placement.paneControls?.call(context) ?? const [],
paneCommands: placement.paneCommands,
onComposerFocus: placement.onComposerFocus,
),
),
),
@@ -20,6 +20,7 @@ String _paneMoveLabel(ChatPaneDirection direction) => switch (direction) {
/// own handler for the row's chat, which is opened first.
mixin _ChatScreenPaneMenu on State<ChatScreen>, _ChatScreenWorkspace
implements SessionPaneMenu {
@override
ChatPaneCommands get _paneCommands;
void _openBySelection(JsonMap session);
@@ -4,6 +4,7 @@ part of 'screen.dart';
mixin _ChatScreenWorkspace on State<ChatScreen> {
Map<String, JsonMap> get _openedSessions;
ChatComposerFocusRequests get _composerFocus;
ChatPaneCommands get _paneCommands;
bool _chatOwnsKeyboard();
JsonMap? _rowFor(String id);
void _back();
@@ -443,6 +444,10 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
top: false,
child: ChatCenterStageKeys(
controller: ChatCenterStageController.instance,
onToggleFiles: () {
final id = _workspace.activePane?.sessionId;
if (id != null) _paneCommands.request(id, ChatPaneCommand.files);
},
enabled: () =>
_workspaceVisible &&
_workspace.paneCount > 0 &&
@@ -121,6 +121,7 @@ class ChatThreadView extends StatefulWidget {
this.onNextChat,
this.paneControls = const [],
this.paneCommands,
this.onComposerFocus,
this.sidebarControl,
this.showBackButton,
this.useNativeBack = false,
@@ -136,6 +137,7 @@ class ChatThreadView extends StatefulWidget {
/// The chat list's requests for this chat, run as the More menu runs them.
final ChatPaneCommands? paneCommands;
final VoidCallback? onComposerFocus;
final Widget? sidebarControl;
final bool? showBackButton;
final bool useNativeBack;
@@ -340,6 +342,11 @@ class _ChatThreadViewState extends State<ChatThreadView> {
final next = !_filesVisible;
if (!mounted) return;
setState(() => _filesVisible = next);
if (!next) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) widget.onComposerFocus?.call();
});
}
_reportCenterStageFilesWidth();
unawaited(_filesPreferences.setVisible(next));
if (next && MediaQuery.sizeOf(context).width < 700) _openFilesSheet();
@@ -116,6 +116,7 @@ class FilesHeader extends StatelessWidget {
Expanded(
child: TextField(
controller: filter,
autofocus: true,
onChanged: controller.setFilter,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.search),
+1
View File
@@ -424,6 +424,7 @@ class _ChatScreenState extends State<ChatScreen>
pasteTarget: _workspaceVisible && pane.id == _workspace.activePaneId,
showBackButton: _page.open || !showsListBesideDetail(context),
paneCommands: _paneCommands,
onComposerFocus: () => _composerFocus.request(selected),
paneControls: (paneContext) => [
ChatBarAction(
label: 'Add chat pane',
@@ -1,14 +1,19 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../../../shell/windows/window_entry.dart';
import '../../../ui/adaptive/window_margins.dart';
import '../../../ui/input/keyboard_owner.dart';
import '../chat_pane_content.dart';
import '../workspace/chat_center_stage_controller.dart';
import '../workspace/chat_pane_commands.dart';
import 'chat_window_tabs.dart';
import 'chat_windows.dart';
/// A floating window's chat: the same live view as a tiled pane (see
/// [buildChatPaneContent]), with what a window decides. Before the server
/// has been reached it says so instead of reading a chat.
class ChatWindowContent extends StatelessWidget {
class ChatWindowContent extends StatefulWidget {
const ChatWindowContent({
super.key,
required this.windows,
@@ -18,25 +23,59 @@ class ChatWindowContent extends StatelessWidget {
final ChatWindows windows;
final WindowEntry entry;
@override
State<ChatWindowContent> createState() => _ChatWindowContentState();
}
class _ChatWindowContentState extends State<ChatWindowContent> {
final _paneCommands = ChatPaneCommands();
@override
void initState() {
super.initState();
FocusManager.instance.addEarlyKeyEventHandler(_key);
}
@override
void dispose() {
FocusManager.instance.removeEarlyKeyEventHandler(_key);
_paneCommands.dispose();
super.dispose();
}
KeyEventResult _key(KeyEvent event) {
final scope = keyboardWindow();
final keyboard = HardwareKeyboard.instance;
if (scope?.entry.id != widget.entry.id ||
!chatFilesShortcut(event, keyboard) ||
primaryFocusIsTypingSurface()) {
return KeyEventResult.ignored;
}
if (event is KeyDownEvent) {
_paneCommands.request(widget.entry.contentId, ChatPaneCommand.files);
}
return KeyEventResult.handled;
}
@override
Widget build(BuildContext context) {
final runtime = windows.runtime;
final sessionId = entry.contentId;
final runtime = widget.windows.runtime;
final sessionId = widget.entry.contentId;
return ListenableBuilder(
listenable: Listenable.merge([
runtime,
runtime.syncToken,
windows.readiness,
widget.windows.readiness,
]),
builder: (context, _) {
// A chat is drawn once: the tiling wins, and this window closes.
if (windows.tiling?.holds(sessionId) ?? false) {
if (widget.windows.tiling?.holds(sessionId) ?? false) {
WidgetsBinding.instance.addPostFrameCallback(
(_) => windows.manager.close(entry.id),
(_) => widget.windows.manager.close(widget.entry.id),
);
return const SizedBox.shrink();
}
if (!windows.ready) {
if (!widget.windows.ready) {
return Center(
child: Text(
'Connecting…',
@@ -56,9 +95,17 @@ class ChatWindowContent extends StatelessWidget {
// Never the active pane: its composer takes a paste while it
// has the keyboard.
ownsPasteWhenFocused: true,
onNewSession: (previousId, session, notice) => windows
.startedNewSession(entry.id, previousId, session, notice),
onSessionClosed: () => windows.sessionClosed(entry.id),
paneCommands: _paneCommands,
onComposerFocus: () => runtime.composerFocus.request(sessionId),
onNewSession: (previousId, session, notice) =>
widget.windows.startedNewSession(
widget.entry.id,
previousId,
session,
notice,
),
onSessionClosed: () =>
widget.windows.sessionClosed(widget.entry.id),
),
),
);
@@ -72,8 +72,7 @@ class ChatCenterStageController extends ValueNotifier<bool> {
}
/// Whether [event] toggles center stage: Alt+E (Option+E on Apple platforms),
/// Cmd+E on Apple platforms (where Ctrl+E stays the text fields' and shell's
/// end of line), and Ctrl+E elsewhere. Option+E is recognized by physical key
/// or the shifted primary chord. Option+E is recognized by physical key
/// position because macOS delivers it as a dead-key logical value. Repeats of
/// a held chord match too, so they are swallowed; only the first press toggles.
bool chatCenterStageShortcut(
@@ -81,16 +80,39 @@ bool chatCenterStageShortcut(
HardwareKeyboard keyboard, {
TargetPlatform? platform,
}) {
if (event is KeyUpEvent || keyboard.isShiftPressed) {
if (event is KeyUpEvent) {
return false;
}
final alt = keyboard.isAltPressed;
if (alt) {
return event.physicalKey == PhysicalKeyboardKey.keyE &&
!keyboard.isShiftPressed &&
!keyboard.isControlPressed &&
!keyboard.isMetaPressed;
}
if (event.logicalKey != LogicalKeyboardKey.keyE) return false;
if (event.physicalKey != PhysicalKeyboardKey.keyE) return false;
return chatCenterStageUsesCommand(platform)
? keyboard.isShiftPressed &&
keyboard.isMetaPressed &&
!keyboard.isControlPressed
: keyboard.isShiftPressed &&
keyboard.isControlPressed &&
!keyboard.isMetaPressed;
}
/// Whether [event] is the Files toggle chord. It deliberately leaves Ctrl+E
/// to a terminal on every platform; macOS uses Cmd+E for the app shortcut.
bool chatFilesShortcut(
KeyEvent event,
HardwareKeyboard keyboard, {
TargetPlatform? platform,
}) {
if (event is KeyUpEvent ||
event.physicalKey != PhysicalKeyboardKey.keyE ||
keyboard.isShiftPressed ||
keyboard.isAltPressed) {
return false;
}
return chatCenterStageUsesCommand(platform)
? keyboard.isMetaPressed && !keyboard.isControlPressed
: keyboard.isControlPressed && !keyboard.isMetaPressed;
@@ -4,12 +4,15 @@ import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import '../../../ui/input/keyboard_owner.dart';
import '../windows/chat_window_tabs.dart';
import 'chat_center_stage_controller.dart';
void _ignoreFilesShortcut() {}
/// Answers the center-stage chord before any focused widget sees it, so it
/// works from the composer, the sidebar or a toolbar, and the focused field
/// never types it. Handling the key also stops a browser's own Ctrl+E/Cmd+E
/// (address-bar search, find with selection) in the web build.
/// never types it. Handling the app-owned chords also stops a browser's own
/// shortcut behavior in the web build.
///
/// Alt+E/Option+E works everywhere, including while a composer is focused.
/// On Apple platforms Cmd+E works in the terminal too. Elsewhere Ctrl+E is
@@ -20,6 +23,7 @@ class ChatCenterStageKeys extends StatefulWidget {
super.key,
required this.controller,
required this.enabled,
this.onToggleFiles = _ignoreFilesShortcut,
required this.child,
});
@@ -28,6 +32,7 @@ class ChatCenterStageKeys extends StatefulWidget {
/// Whether the chord belongs to this workspace now: wide, shown and with
/// no popup or other destination over it.
final bool Function() enabled;
final VoidCallback onToggleFiles;
final Widget child;
@override
@@ -49,12 +54,21 @@ class _ChatCenterStageKeysState extends State<ChatCenterStageKeys> {
}
KeyEventResult _key(KeyEvent event) {
if (!mounted ||
!chatCenterStageShortcut(event, HardwareKeyboard.instance) ||
!widget.enabled() ||
(!HardwareKeyboard.instance.isAltPressed &&
!chatCenterStageUsesCommand() &&
primaryFocusIsTypingSurface())) {
if (!mounted || !widget.enabled()) return KeyEventResult.ignored;
final keyboard = HardwareKeyboard.instance;
if (chatFilesShortcut(event, keyboard)) {
// A floating chat owns the command when its focused node is inside its
// WindowScope; its own early handler will route it to that chat.
if (keyboardWindow() != null) return KeyEventResult.ignored;
// Editable chat fields are still app-owned for this chord. A terminal
// is the exception: Ctrl+E must remain its shell end-of-line command.
if (primaryFocusIsTypingSurface()) return KeyEventResult.ignored;
if (event is KeyDownEvent) {
widget.onToggleFiles();
}
return KeyEventResult.handled;
}
if (!chatCenterStageShortcut(event, keyboard)) {
return KeyEventResult.ignored;
}
if (event is KeyDownEvent) widget.controller.toggle();
@@ -125,11 +125,16 @@ class KeyboardShortcutRegistry {
caveat:
'While the slash command list is open above the composer. Esc dismisses it.',
),
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'Toggle Files',
keys: _apple ? 'Cmd+E' : 'Ctrl+E',
),
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'Toggle Center Stage',
keys:
'${chatCenterStageShortcutLabel(platform)}${_apple ? ', Cmd+E' : ', Ctrl+E'}',
'${chatCenterStageShortcutLabel(platform)}${_apple ? ', Cmd+Shift+E' : ', Ctrl+Shift+E'}',
),
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,