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;
|
void toggle() => value = !value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether [event] toggles center stage: Cmd+E on Apple platforms (where
|
/// Whether [event] toggles center stage: Alt+E (Option+E on Apple platforms),
|
||||||
/// Ctrl+E stays the text fields' and shell's end of line) and Ctrl+E
|
/// Cmd+E on Apple platforms (where Ctrl+E stays the text fields' and shell's
|
||||||
/// elsewhere, with no other modifier. Repeats of a held chord match too, so
|
/// end of line), and Ctrl+E elsewhere. Option+E is recognized by physical key
|
||||||
/// they are swallowed; only the first press toggles.
|
/// 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(
|
bool chatCenterStageShortcut(
|
||||||
KeyEvent event,
|
KeyEvent event,
|
||||||
HardwareKeyboard keyboard, {
|
HardwareKeyboard keyboard, {
|
||||||
TargetPlatform? platform,
|
TargetPlatform? platform,
|
||||||
}) {
|
}) {
|
||||||
if (event is KeyUpEvent || keyboard.isShiftPressed || keyboard.isAltPressed) {
|
if (event is KeyUpEvent || keyboard.isShiftPressed) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
final alt = keyboard.isAltPressed;
|
||||||
|
if (alt) {
|
||||||
|
return event.physicalKey == PhysicalKeyboardKey.keyE &&
|
||||||
|
!keyboard.isControlPressed &&
|
||||||
|
!keyboard.isMetaPressed;
|
||||||
|
}
|
||||||
if (event.logicalKey != LogicalKeyboardKey.keyE) return false;
|
if (event.logicalKey != LogicalKeyboardKey.keyE) return false;
|
||||||
return chatCenterStageUsesCommand(platform)
|
return chatCenterStageUsesCommand(platform)
|
||||||
? keyboard.isMetaPressed && !keyboard.isControlPressed
|
? keyboard.isMetaPressed && !keyboard.isControlPressed
|
||||||
@@ -96,4 +103,4 @@ bool chatCenterStageUsesCommand([TargetPlatform? platform]) {
|
|||||||
|
|
||||||
/// The shortcut as this platform shows it, for menus and tooltips.
|
/// The shortcut as this platform shows it, for menus and tooltips.
|
||||||
String chatCenterStageShortcutLabel([TargetPlatform? platform]) =>
|
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
|
/// 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.
|
/// (address-bar search, find with selection) in the web build.
|
||||||
///
|
///
|
||||||
/// On Apple platforms the chord is Cmd+E and works in the terminal too.
|
/// Alt+E/Option+E works everywhere, including while a composer is focused.
|
||||||
/// Elsewhere it is Ctrl+E, which the terminal keeps while it has the
|
/// On Apple platforms Cmd+E works in the terminal too. Elsewhere Ctrl+E is
|
||||||
/// keyboard: there it is the shell's end of line.
|
/// left to the terminal while it has the keyboard: there it is the shell's
|
||||||
|
/// end of line.
|
||||||
class ChatCenterStageKeys extends StatefulWidget {
|
class ChatCenterStageKeys extends StatefulWidget {
|
||||||
const ChatCenterStageKeys({
|
const ChatCenterStageKeys({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -51,7 +52,9 @@ class _ChatCenterStageKeysState extends State<ChatCenterStageKeys> {
|
|||||||
if (!mounted ||
|
if (!mounted ||
|
||||||
!chatCenterStageShortcut(event, HardwareKeyboard.instance) ||
|
!chatCenterStageShortcut(event, HardwareKeyboard.instance) ||
|
||||||
!widget.enabled() ||
|
!widget.enabled() ||
|
||||||
(!chatCenterStageUsesCommand() && primaryFocusIsTypingSurface())) {
|
(!HardwareKeyboard.instance.isAltPressed &&
|
||||||
|
!chatCenterStageUsesCommand() &&
|
||||||
|
primaryFocusIsTypingSurface())) {
|
||||||
return KeyEventResult.ignored;
|
return KeyEventResult.ignored;
|
||||||
}
|
}
|
||||||
if (event is KeyDownEvent) widget.controller.toggle();
|
if (event is KeyDownEvent) widget.controller.toggle();
|
||||||
|
|||||||
@@ -7,9 +7,11 @@ unchanged.
|
|||||||
|
|
||||||
## Using it
|
## Using it
|
||||||
|
|
||||||
- Cmd+E on macOS/iOS, Ctrl+E elsewhere, or the pane's More menu:
|
- Alt+E (Option+E on macOS/iOS), Cmd+E on Apple platforms, Ctrl+E elsewhere, or
|
||||||
**Center stage (Cmd+E)** / **Leave center stage (Cmd+E)** (shown with two or
|
the pane's More menu: **Center stage (Option+E)** / **Leave center stage
|
||||||
more panes on a wide window).
|
(Option+E)** on Apple platforms (shown with two or more panes on a wide
|
||||||
|
window). Option+E is matched by physical key position because macOS treats it
|
||||||
|
as a dead key.
|
||||||
- The choice is device-local (`pipelines.next.chatCenterStage.v1` in shared
|
- The choice is device-local (`pipelines.next.chatCenterStage.v1` in shared
|
||||||
preferences) and survives reloads. It is not part of the server-scoped
|
preferences) and survives reloads. It is not part of the server-scoped
|
||||||
workspace snapshot.
|
workspace snapshot.
|
||||||
@@ -31,6 +33,12 @@ unchanged.
|
|||||||
|
|
||||||
- `tool/memwatch/full.sh 'test/features/chat/workspace'`: 87 passed, 0 failed.
|
- `tool/memwatch/full.sh 'test/features/chat/workspace'`: 87 passed, 0 failed.
|
||||||
`tool/analyze.sh`: clean.
|
`tool/analyze.sh`: clean.
|
||||||
|
- Shortcut fix: `tool/memwatch/full.sh
|
||||||
|
'test/features/chat/workspace/chat_center_stage_test.dart'`: 16 passed, 0
|
||||||
|
failed; `tool/analyze.sh`: clean. Covered Option/Alt+E dead-key position
|
||||||
|
matching, focused-composer handling, key-up rejection, existing aliases and
|
||||||
|
platform labels. Browser interaction/capture remains with the UI review
|
||||||
|
stage.
|
||||||
- Captures (`chats=3&rich=1&colors=1`, 1440x900, three panes, headless Chrome,
|
- Captures (`chats=3&rich=1&colors=1`, 1440x900, three panes, headless Chrome,
|
||||||
macOS platform, so Cmd+E): normal split, center stage on, stage moved to
|
macOS platform, so Cmd+E): normal split, center stage on, stage moved to
|
||||||
api refactor, and back to the same split sizes, plus filmed toggle-on, switch
|
api refactor, and back to the same split sizes, plus filmed toggle-on, switch
|
||||||
|
|||||||
@@ -385,6 +385,44 @@ void main() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test('Alt+E toggles by physical key position, including Option dead keys', () {
|
||||||
|
const event = KeyDownEvent(
|
||||||
|
physicalKey: PhysicalKeyboardKey.keyE,
|
||||||
|
logicalKey: LogicalKeyboardKey(0x00B4),
|
||||||
|
character: '´',
|
||||||
|
timeStamp: Duration.zero,
|
||||||
|
);
|
||||||
|
expect(chatCenterStageShortcut(event, _AltHeld()), isTrue);
|
||||||
|
expect(
|
||||||
|
chatCenterStageShortcut(
|
||||||
|
const KeyUpEvent(
|
||||||
|
physicalKey: PhysicalKeyboardKey.keyE,
|
||||||
|
logicalKey: LogicalKeyboardKey(0x00B4),
|
||||||
|
timeStamp: Duration.zero,
|
||||||
|
),
|
||||||
|
_AltHeld(),
|
||||||
|
),
|
||||||
|
isFalse,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Alt+E toggles from a focused composer without typing', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
wide(tester);
|
||||||
|
final workspace = threePanes();
|
||||||
|
final stage = ChatCenterStageController(store: _MemoryStore());
|
||||||
|
addTearDown(workspace.dispose);
|
||||||
|
addTearDown(stage.dispose);
|
||||||
|
await tester.pumpWidget(host(workspace, stage));
|
||||||
|
await tester.tap(find.byKey(const ValueKey('input-three')));
|
||||||
|
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
|
||||||
|
await tester.sendKeyEvent(LogicalKeyboardKey.keyE);
|
||||||
|
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
|
||||||
|
expect(stage.value, isTrue);
|
||||||
|
expect(find.text('e'), findsNothing);
|
||||||
|
});
|
||||||
|
|
||||||
test('the choice is remembered', () async {
|
test('the choice is remembered', () async {
|
||||||
final store = _MemoryStore();
|
final store = _MemoryStore();
|
||||||
final first = ChatCenterStageController(store: store)..toggle();
|
final first = ChatCenterStageController(store: store)..toggle();
|
||||||
@@ -398,7 +436,18 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('labels name the platform chord', () {
|
test('labels name the platform chord', () {
|
||||||
expect(chatCenterStageShortcutLabel(TargetPlatform.macOS), 'Cmd+E');
|
expect(chatCenterStageShortcutLabel(TargetPlatform.macOS), 'Option+E');
|
||||||
expect(chatCenterStageShortcutLabel(TargetPlatform.windows), 'Ctrl+E');
|
expect(chatCenterStageShortcutLabel(TargetPlatform.windows), 'Alt+E');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _AltHeld extends HardwareKeyboard {
|
||||||
|
@override
|
||||||
|
bool get isAltPressed => true;
|
||||||
|
@override
|
||||||
|
bool get isControlPressed => false;
|
||||||
|
@override
|
||||||
|
bool get isMetaPressed => false;
|
||||||
|
@override
|
||||||
|
bool get isShiftPressed => false;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user