Merge branch 'main' into pipelines/run-20261113-1520-search-opens-the-selected-chat-5f6a
This commit is contained in:
@@ -97,7 +97,7 @@ class KeyboardShortcutRegistry {
|
|||||||
keys: shellChatShortcutLabels(platform).join(', '),
|
keys: shellChatShortcutLabels(platform).join(', '),
|
||||||
caveat: web
|
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. 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(
|
const KeyboardShortcutEntry(
|
||||||
group: KeyboardShortcutGroup.navigation,
|
group: KeyboardShortcutGroup.navigation,
|
||||||
|
|||||||
@@ -416,9 +416,11 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Ctrl+K is the terminal's kill-line while the terminal has the keyboard;
|
// 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) &&
|
if (shellChatShortcut(event, keyboard) &&
|
||||||
(keyboard.isAltPressed || !primaryFocusIsTypingSurface())) {
|
(keyboard.isAltPressed ||
|
||||||
|
keyboard.isMetaPressed ||
|
||||||
|
!primaryFocusIsTypingSurface())) {
|
||||||
if (event is KeyDownEvent) _openChat();
|
if (event is KeyDownEvent) _openChat();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,28 +2,29 @@ import 'package:flutter/foundation.dart';
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
/// Whether [event] opens the Chat destination from any destination: Ctrl+K,
|
/// 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
|
/// Cmd+K (Meta+K), or Alt+K (Option+K on Apple platforms). Alt+K is
|
||||||
/// too, because Option+K yields a dead-key symbol on a Mac. Shift, Cmd and
|
/// recognised by key position too, because Option+K yields a dead-key symbol
|
||||||
/// chords with both Ctrl and Alt are not the shortcut. Repeats of a held chord
|
/// 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.
|
/// match as well, so the caller can swallow them; only its first press acts.
|
||||||
bool shellChatShortcut(KeyEvent event, HardwareKeyboard keyboard) {
|
bool shellChatShortcut(KeyEvent event, HardwareKeyboard keyboard) {
|
||||||
if (event is KeyUpEvent ||
|
if (event is KeyUpEvent || keyboard.isShiftPressed) return false;
|
||||||
keyboard.isShiftPressed ||
|
|
||||||
keyboard.isMetaPressed) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final control = keyboard.isControlPressed;
|
|
||||||
final alt = keyboard.isAltPressed;
|
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;
|
if (event.logicalKey == LogicalKeyboardKey.keyK) return true;
|
||||||
return alt && event.physicalKey == PhysicalKeyboardKey.keyK;
|
return alt && event.physicalKey == PhysicalKeyboardKey.keyK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The chords that open Chat as they read on this platform, for the help
|
/// 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
|
/// 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]) {
|
List<String> shellChatShortcutLabels([TargetPlatform? platform]) {
|
||||||
final target = platform ?? defaultTargetPlatform;
|
final target = platform ?? defaultTargetPlatform;
|
||||||
final apple = target == TargetPlatform.macOS || target == TargetPlatform.iOS;
|
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,
|
web: false,
|
||||||
).entries.firstWhere((entry) => entry.action == 'Open Chat');
|
).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);
|
final linux = openChat(TargetPlatform.linux);
|
||||||
expect(linux.keys, 'Alt+K, Ctrl+K');
|
expect(linux.keys, 'Alt+K, Ctrl+K');
|
||||||
expect(linux.caveat, contains('kill-line'));
|
expect(linux.caveat, contains('kill-line'));
|
||||||
|
|||||||
@@ -13,37 +13,48 @@ const _k = KeyDownEvent(
|
|||||||
);
|
);
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('Ctrl+K and Alt+K open Chat; other modifiers and plain K do not', () {
|
test(
|
||||||
bool chord(Set<LogicalKeyboardKey> held, [KeyEvent event = _k]) =>
|
'Ctrl+K, Cmd+K and Alt+K open Chat; other modifiers and plain K do not',
|
||||||
shellChatShortcut(event, _FakeKeyboard(held));
|
() {
|
||||||
expect(chord({}), isFalse);
|
bool chord(Set<LogicalKeyboardKey> held, [KeyEvent event = _k]) =>
|
||||||
expect(chord({LogicalKeyboardKey.controlLeft}), isTrue);
|
shellChatShortcut(event, _FakeKeyboard(held));
|
||||||
expect(chord({LogicalKeyboardKey.altLeft}), isTrue);
|
expect(chord({}), isFalse);
|
||||||
expect(
|
expect(chord({LogicalKeyboardKey.controlLeft}), isTrue);
|
||||||
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.altLeft}),
|
expect(chord({LogicalKeyboardKey.altLeft}), isTrue);
|
||||||
isFalse,
|
expect(
|
||||||
);
|
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.altLeft}),
|
||||||
expect(
|
isFalse,
|
||||||
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.shiftLeft}),
|
);
|
||||||
isFalse,
|
expect(
|
||||||
);
|
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.shiftLeft}),
|
||||||
expect(chord({LogicalKeyboardKey.metaLeft}), isFalse);
|
isFalse,
|
||||||
expect(
|
);
|
||||||
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.metaLeft}),
|
expect(chord({LogicalKeyboardKey.metaLeft}), isTrue);
|
||||||
isFalse,
|
expect(
|
||||||
);
|
chord({LogicalKeyboardKey.metaLeft, LogicalKeyboardKey.shiftLeft}),
|
||||||
expect(
|
isFalse,
|
||||||
shellChatShortcut(
|
);
|
||||||
const KeyUpEvent(
|
expect(
|
||||||
physicalKey: PhysicalKeyboardKey.keyK,
|
chord({LogicalKeyboardKey.metaLeft, LogicalKeyboardKey.altLeft}),
|
||||||
logicalKey: LogicalKeyboardKey.keyK,
|
isFalse,
|
||||||
timeStamp: Duration.zero,
|
);
|
||||||
|
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', () {
|
test('Option+K matches by key position though it types a symbol', () {
|
||||||
// On a Mac, Option+K produces ˚: the logical key is not K.
|
// 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.linux), ['Alt+K', 'Ctrl+K']);
|
||||||
expect(shellChatShortcutLabels(TargetPlatform.macOS), [
|
expect(shellChatShortcutLabels(TargetPlatform.macOS), [
|
||||||
'Option+K',
|
'Option+K',
|
||||||
|
'Cmd+K',
|
||||||
'Ctrl+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,
|
tester,
|
||||||
) async {
|
) async {
|
||||||
var opened = 0;
|
var opened = 0;
|
||||||
@@ -104,6 +116,12 @@ void main() {
|
|||||||
expect(find.text('chat body'), isOnstage);
|
expect(find.text('chat body'), isOnstage);
|
||||||
// Already in Chat, the chord still hands the keyboard to the composer.
|
// Already in Chat, the chord still hands the keyboard to the composer.
|
||||||
expect(opened, 2);
|
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);
|
expect(tester.takeException(), isNull);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -130,7 +148,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets(
|
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 {
|
(tester) async {
|
||||||
final terminal = FocusNode();
|
final terminal = FocusNode();
|
||||||
addTearDown(terminal.dispose);
|
addTearDown(terminal.dispose);
|
||||||
@@ -168,6 +186,12 @@ void main() {
|
|||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(find.text('chat body'), isOnstage);
|
expect(find.text('chat body'), isOnstage);
|
||||||
expect(opened, 1);
|
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);
|
expect(tester.takeException(), isNull);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user