c3c2c1bbc9
Cmd is the natural modifier on a Mac. Like Option+K, it also opens Chat from the terminal, where Ctrl+K stays kill-line.
31 lines
1.4 KiB
Dart
31 lines
1.4 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
/// Whether [event] opens the Chat destination from any destination: Ctrl+K,
|
|
/// 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) return false;
|
|
final alt = keyboard.isAltPressed;
|
|
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; 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', 'Cmd+K', 'Ctrl+K'] : ['Alt+K', 'Ctrl+K'];
|
|
}
|