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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user