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.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user