3b0da38f70
One fixed-size list of grouped cards: actions and notes on the leading side, keys drawn as keycaps in an aligned trailing column that never ends a line on a joining word. A search field, focused when Ctrl+? opens it, filters fuzzily by action and keys (exactly by group and note) and highlights the matched letters.
36 lines
970 B
Dart
36 lines
970 B
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
import '../features/settings/keyboard_shortcuts_help.dart';
|
|
|
|
/// Opens and closes the keyboard shortcuts cheatsheet from the shell's global
|
|
/// key handler. Ctrl+? (or Escape) closes it, and it is only ever popped once:
|
|
/// closing clears the token first, and a dismissal by the barrier or close
|
|
/// button clears it when the route completes.
|
|
class ShellCheatsheet {
|
|
Object? _token;
|
|
|
|
bool get isOpen => _token != null;
|
|
|
|
void toggle(BuildContext context) {
|
|
if (isOpen) {
|
|
close(context);
|
|
} else {
|
|
open(context);
|
|
}
|
|
}
|
|
|
|
void open(BuildContext context) {
|
|
if (isOpen) return;
|
|
final token = _token = Object();
|
|
showKeyboardShortcutsHelp(context, focusSearch: true).whenComplete(() {
|
|
if (identical(_token, token)) _token = null;
|
|
});
|
|
}
|
|
|
|
void close(BuildContext context) {
|
|
if (!isOpen) return;
|
|
_token = null;
|
|
Navigator.of(context, rootNavigator: true).maybePop();
|
|
}
|
|
}
|