Files
pipelines/app/lib/shell/shell_chat_shortcut.dart
T
alan ac5f28bb83 Add global shortcuts for opening Chat
Allow Ctrl+K and Alt+K to switch to Chat from any destination, while preserving terminal Ctrl+K behavior and focusing the active composer. Register the shortcuts in help and cover matching, navigation, terminal handling, and composer focus with regression tests.
2026-11-12 01:08:18 +00:00

30 lines
1.3 KiB
Dart

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
/// 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;
final alt = keyboard.isAltPressed;
if (control == alt) 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.
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'];
}