Merge commit 'c3c2c1bbc9adcb06c09ac53dd572948890a868e3' into pipelines/run-20261113-1519-natural-read-aloud-voices-1d6b

This commit is contained in:
2026-11-13 16:06:12 +00:00
5 changed files with 75 additions and 48 deletions
@@ -97,7 +97,7 @@ class KeyboardShortcutRegistry {
keys: shellChatShortcutLabels(platform).join(', '),
caveat: web
? 'Shows the open chat and focuses its message input. The browser may reserve Ctrl+K.'
: 'Shows the open chat and focuses its message input. In the terminal Ctrl+K stays kill-line; Alt+K still opens Chat.',
: 'Shows the open chat and focuses its message input. In the terminal Ctrl+K stays kill-line; ${_apple ? 'Option+K and Cmd+K still open' : 'Alt+K still opens'} Chat.',
),
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.navigation,
+4 -2
View File
@@ -416,9 +416,11 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
return true;
}
// Ctrl+K is the terminal's kill-line while the terminal has the keyboard;
// Alt+K still opens Chat there.
// Alt+K and Cmd+K still open Chat there.
if (shellChatShortcut(event, keyboard) &&
(keyboard.isAltPressed || !primaryFocusIsTypingSurface())) {
(keyboard.isAltPressed ||
keyboard.isMetaPressed ||
!primaryFocusIsTypingSurface())) {
if (event is KeyDownEvent) _openChat();
return true;
}
+13 -12
View File
@@ -2,28 +2,29 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
/// Whether [event] opens the Chat destination from any destination: Ctrl+K,
/// or Alt+K (Option+K on Apple platforms). Alt+K is recognised by key position
/// too, because Option+K yields a dead-key symbol on a Mac. Shift, Cmd and
/// chords with both Ctrl and Alt are not the shortcut. Repeats of a held chord
/// Cmd+K (Meta+K), or Alt+K (Option+K on Apple platforms). Alt+K is
/// recognised by key position too, because Option+K yields a dead-key symbol
/// on a Mac. Shift and chords of more than one of Ctrl, Cmd and Alt are not
/// the shortcut. Repeats of a held chord
/// match as well, so the caller can swallow them; only its first press acts.
bool shellChatShortcut(KeyEvent event, HardwareKeyboard keyboard) {
if (event is KeyUpEvent ||
keyboard.isShiftPressed ||
keyboard.isMetaPressed) {
return false;
}
final control = keyboard.isControlPressed;
if (event is KeyUpEvent || keyboard.isShiftPressed) return false;
final alt = keyboard.isAltPressed;
if (control == alt) return false;
final held = [
keyboard.isControlPressed,
keyboard.isMetaPressed,
alt,
].where((pressed) => pressed).length;
if (held != 1) return false;
if (event.logicalKey == LogicalKeyboardKey.keyK) return true;
return alt && event.physicalKey == PhysicalKeyboardKey.keyK;
}
/// The chords that open Chat as they read on this platform, for the help
/// page. Alt (Option on Apple platforms) leads, as it does for the floating
/// chats; Ctrl+K is the other chord everywhere.
/// chats; Cmd+K follows on Apple platforms and Ctrl+K works everywhere.
List<String> shellChatShortcutLabels([TargetPlatform? platform]) {
final target = platform ?? defaultTargetPlatform;
final apple = target == TargetPlatform.macOS || target == TargetPlatform.iOS;
return [apple ? 'Option+K' : 'Alt+K', 'Ctrl+K'];
return apple ? ['Option+K', 'Cmd+K', 'Ctrl+K'] : ['Alt+K', 'Ctrl+K'];
}
@@ -33,7 +33,7 @@ void main() {
web: false,
).entries.firstWhere((entry) => entry.action == 'Open Chat');
expect(openChat(TargetPlatform.macOS).keys, 'Option+K, Ctrl+K');
expect(openChat(TargetPlatform.macOS).keys, 'Option+K, Cmd+K, Ctrl+K');
final linux = openChat(TargetPlatform.linux);
expect(linux.keys, 'Alt+K, Ctrl+K');
expect(linux.caveat, contains('kill-line'));
+56 -32
View File
@@ -13,37 +13,48 @@ const _k = KeyDownEvent(
);
void main() {
test('Ctrl+K and Alt+K open Chat; other modifiers and plain K do not', () {
bool chord(Set<LogicalKeyboardKey> held, [KeyEvent event = _k]) =>
shellChatShortcut(event, _FakeKeyboard(held));
expect(chord({}), isFalse);
expect(chord({LogicalKeyboardKey.controlLeft}), isTrue);
expect(chord({LogicalKeyboardKey.altLeft}), isTrue);
expect(
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.altLeft}),
isFalse,
);
expect(
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.shiftLeft}),
isFalse,
);
expect(chord({LogicalKeyboardKey.metaLeft}), isFalse);
expect(
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.metaLeft}),
isFalse,
);
expect(
shellChatShortcut(
const KeyUpEvent(
physicalKey: PhysicalKeyboardKey.keyK,
logicalKey: LogicalKeyboardKey.keyK,
timeStamp: Duration.zero,
test(
'Ctrl+K, Cmd+K and Alt+K open Chat; other modifiers and plain K do not',
() {
bool chord(Set<LogicalKeyboardKey> held, [KeyEvent event = _k]) =>
shellChatShortcut(event, _FakeKeyboard(held));
expect(chord({}), isFalse);
expect(chord({LogicalKeyboardKey.controlLeft}), isTrue);
expect(chord({LogicalKeyboardKey.altLeft}), isTrue);
expect(
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.altLeft}),
isFalse,
);
expect(
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.shiftLeft}),
isFalse,
);
expect(chord({LogicalKeyboardKey.metaLeft}), isTrue);
expect(
chord({LogicalKeyboardKey.metaLeft, LogicalKeyboardKey.shiftLeft}),
isFalse,
);
expect(
chord({LogicalKeyboardKey.metaLeft, LogicalKeyboardKey.altLeft}),
isFalse,
);
expect(
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.metaLeft}),
isFalse,
);
expect(
shellChatShortcut(
const KeyUpEvent(
physicalKey: PhysicalKeyboardKey.keyK,
logicalKey: LogicalKeyboardKey.keyK,
timeStamp: Duration.zero,
),
_FakeKeyboard({LogicalKeyboardKey.controlLeft}),
),
_FakeKeyboard({LogicalKeyboardKey.controlLeft}),
),
isFalse,
);
});
isFalse,
);
},
);
test('Option+K matches by key position though it types a symbol', () {
// On a Mac, Option+K produces ˚: the logical key is not K.
@@ -65,11 +76,12 @@ void main() {
expect(shellChatShortcutLabels(TargetPlatform.linux), ['Alt+K', 'Ctrl+K']);
expect(shellChatShortcutLabels(TargetPlatform.macOS), [
'Option+K',
'Cmd+K',
'Ctrl+K',
]);
});
testWidgets('Ctrl+K and Alt+K show Chat from another destination', (
testWidgets('Ctrl+K, Alt+K and Cmd+K show Chat from another destination', (
tester,
) async {
var opened = 0;
@@ -104,6 +116,12 @@ void main() {
expect(find.text('chat body'), isOnstage);
// Already in Chat, the chord still hands the keyboard to the composer.
expect(opened, 2);
await tester.sendKeyDownEvent(LogicalKeyboardKey.metaLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyK);
await tester.sendKeyUpEvent(LogicalKeyboardKey.metaLeft);
await tester.pump();
expect(opened, 3);
expect(tester.takeException(), isNull);
});
@@ -130,7 +148,7 @@ void main() {
});
testWidgets(
'terminal keeps Ctrl+K for kill-line but Alt+K still opens Chat',
'terminal keeps Ctrl+K for kill-line but Alt+K and Cmd+K still open Chat',
(tester) async {
final terminal = FocusNode();
addTearDown(terminal.dispose);
@@ -168,6 +186,12 @@ void main() {
await tester.pump();
expect(find.text('chat body'), isOnstage);
expect(opened, 1);
await tester.sendKeyDownEvent(LogicalKeyboardKey.metaLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyK);
await tester.sendKeyUpEvent(LogicalKeyboardKey.metaLeft);
await tester.pump();
expect(opened, 2);
expect(tester.takeException(), isNull);
},
);