Open Chat with Cmd+K as well as Ctrl+K

Cmd is the natural modifier on a Mac. Like Option+K, it also opens Chat
from the terminal, where Ctrl+K stays kill-line.
This commit is contained in:
2026-11-13 16:02:31 +00:00
parent ccc80a9a8d
commit c3c2c1bbc9
5 changed files with 75 additions and 48 deletions
+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);
},
);