Support Alt+E center stage shortcut
Recognize Option+E by physical key position so macOS dead-key delivery works, including from focused composers, while preserving existing platform aliases and shell behavior. Update labels, notes, and focused coverage.
This commit is contained in:
@@ -71,18 +71,25 @@ class ChatCenterStageController extends ValueNotifier<bool> {
|
||||
void toggle() => value = !value;
|
||||
}
|
||||
|
||||
/// Whether [event] toggles center stage: Cmd+E on Apple platforms (where
|
||||
/// Ctrl+E stays the text fields' and shell's end of line) and Ctrl+E
|
||||
/// elsewhere, with no other modifier. Repeats of a held chord match too, so
|
||||
/// they are swallowed; only the first press toggles.
|
||||
/// 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
|
||||
/// 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(
|
||||
KeyEvent event,
|
||||
HardwareKeyboard keyboard, {
|
||||
TargetPlatform? platform,
|
||||
}) {
|
||||
if (event is KeyUpEvent || keyboard.isShiftPressed || keyboard.isAltPressed) {
|
||||
if (event is KeyUpEvent || keyboard.isShiftPressed) {
|
||||
return false;
|
||||
}
|
||||
final alt = keyboard.isAltPressed;
|
||||
if (alt) {
|
||||
return event.physicalKey == PhysicalKeyboardKey.keyE &&
|
||||
!keyboard.isControlPressed &&
|
||||
!keyboard.isMetaPressed;
|
||||
}
|
||||
if (event.logicalKey != LogicalKeyboardKey.keyE) return false;
|
||||
return chatCenterStageUsesCommand(platform)
|
||||
? keyboard.isMetaPressed && !keyboard.isControlPressed
|
||||
@@ -96,4 +103,4 @@ bool chatCenterStageUsesCommand([TargetPlatform? platform]) {
|
||||
|
||||
/// The shortcut as this platform shows it, for menus and tooltips.
|
||||
String chatCenterStageShortcutLabel([TargetPlatform? platform]) =>
|
||||
chatCenterStageUsesCommand(platform) ? 'Cmd+E' : 'Ctrl+E';
|
||||
chatCenterStageUsesCommand(platform) ? 'Option+E' : 'Alt+E';
|
||||
|
||||
@@ -11,9 +11,10 @@ import 'chat_center_stage_controller.dart';
|
||||
/// 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.
|
||||
///
|
||||
/// On Apple platforms the chord is Cmd+E and works in the terminal too.
|
||||
/// Elsewhere it is Ctrl+E, which the terminal keeps while it has the
|
||||
/// keyboard: there it is the shell's end of line.
|
||||
/// 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
|
||||
/// left to the terminal while it has the keyboard: there it is the shell's
|
||||
/// end of line.
|
||||
class ChatCenterStageKeys extends StatefulWidget {
|
||||
const ChatCenterStageKeys({
|
||||
super.key,
|
||||
@@ -51,7 +52,9 @@ class _ChatCenterStageKeysState extends State<ChatCenterStageKeys> {
|
||||
if (!mounted ||
|
||||
!chatCenterStageShortcut(event, HardwareKeyboard.instance) ||
|
||||
!widget.enabled() ||
|
||||
(!chatCenterStageUsesCommand() && primaryFocusIsTypingSurface())) {
|
||||
(!HardwareKeyboard.instance.isAltPressed &&
|
||||
!chatCenterStageUsesCommand() &&
|
||||
primaryFocusIsTypingSurface())) {
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
if (event is KeyDownEvent) widget.controller.toggle();
|
||||
|
||||
Reference in New Issue
Block a user