Files
pipelines/app/lib/shell/shell_cheatsheet_shortcut.dart
T
alan 3e0b1e55c7 Add global keyboard shortcuts cheatsheet
Expose the existing shortcut help as a global Ctrl+?/Cmd+? cheatsheet while preserving Ctrl+/ search behavior. Register the current shortcuts and cover composer, terminal, layout, and close interactions with focused tests.
2026-11-12 14:41:20 +00:00

32 lines
1.2 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'shell_list_shortcuts.dart';
/// Whether [event] opens or closes the keyboard shortcuts cheatsheet: Ctrl+?
/// (Cmd+? on macOS). The chord is the one that types '?', so it is matched
/// by the logical '?' key or character, or by the slash key held with Shift on
/// US layouts. Ctrl+/ without Shift is Search and never matches here, and
/// Alt is never part of this chord. Only the first press of a held chord acts.
bool shellCheatsheetShortcut(
KeyEvent event,
HardwareKeyboard keyboard, {
TargetPlatform? platform,
}) {
if (event is! KeyDownEvent ||
keyboard.isAltPressed ||
!shellPrimaryModifier(keyboard, platform: platform)) {
return false;
}
return event.logicalKey == LogicalKeyboardKey.question ||
event.character == '?' ||
(event.logicalKey == LogicalKeyboardKey.slash && keyboard.isShiftPressed);
}
/// The chord as it reads on this platform, for the help page. macOS accepts
/// Cmd or Ctrl (as Search does), so both are shown there.
String shellCheatsheetShortcutLabel([TargetPlatform? platform]) =>
(platform ?? defaultTargetPlatform) == TargetPlatform.macOS
? 'Cmd+?, Ctrl+?'
: 'Ctrl+?';