3e0b1e55c7
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.
36 lines
951 B
Dart
36 lines
951 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).whenComplete(() {
|
|
if (identical(_token, token)) _token = null;
|
|
});
|
|
}
|
|
|
|
void close(BuildContext context) {
|
|
if (!isOpen) return;
|
|
_token = null;
|
|
Navigator.of(context, rootNavigator: true).maybePop();
|
|
}
|
|
}
|