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:
2026-11-12 14:41:20 +00:00
parent a3fb506a57
commit 3e0b1e55c7
9 changed files with 1002 additions and 50 deletions
@@ -5,6 +5,10 @@ import 'keyboard_shortcuts_registry.dart';
const keyboardShortcutsLabel = 'Keyboard shortcuts';
/// The narrowest content width (after the page padding) that shows the groups
/// in two columns. Narrower content, such as a phone sheet, stacks them.
const _twoColumnMinWidth = 520.0;
Future<void> showKeyboardShortcutsHelp(BuildContext context) =>
showAppDetails<void>(
context,
@@ -19,7 +23,12 @@ class KeyboardShortcutsHelp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final entries = (registry ?? KeyboardShortcutRegistry.current()).entries;
final source = registry ?? KeyboardShortcutRegistry.current();
final groups = [
for (final group in KeyboardShortcutGroup.values)
if (source.inGroup(group) case final entries when entries.isNotEmpty)
(group: group, entries: entries),
];
final content = Semantics(
scopesRoute: true,
namesRoute: true,
@@ -52,13 +61,7 @@ class KeyboardShortcutsHelp extends StatelessWidget {
style: Theme.of(context).textTheme.bodyMedium,
),
const SizedBox(height: 16),
for (final (index, entry) in entries.indexed) ...[
if (index > 0) const Divider(height: 1),
Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: _ShortcutRow(entry: entry),
),
],
_ShortcutGroups(groups: groups),
const SizedBox(height: 4),
Text(
'On macOS, Option is shown for Alt. Browsers can reserve system or tab shortcuts.',
@@ -77,6 +80,89 @@ class KeyboardShortcutsHelp extends StatelessWidget {
}
}
typedef _Group = ({
KeyboardShortcutGroup group,
List<KeyboardShortcutEntry> entries,
});
/// The groups in display order: one column when narrow, otherwise two. Each
/// group goes to the shorter column so the two stay about the same height.
class _ShortcutGroups extends StatelessWidget {
const _ShortcutGroups({required this.groups});
final List<_Group> groups;
@override
Widget build(BuildContext context) => LayoutBuilder(
builder: (context, constraints) {
if (constraints.maxWidth < _twoColumnMinWidth) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [for (final group in groups) _GroupBlock(group: group)],
);
}
final left = <_Group>[];
final right = <_Group>[];
var leftRows = 0;
var rightRows = 0;
for (final group in groups) {
if (leftRows <= rightRows) {
left.add(group);
leftRows += group.entries.length + 1;
} else {
right.add(group);
rightRows += group.entries.length + 1;
}
}
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(child: _GroupColumn(groups: left)),
const SizedBox(width: 24),
Expanded(child: _GroupColumn(groups: right)),
],
);
},
);
}
class _GroupColumn extends StatelessWidget {
const _GroupColumn({required this.groups});
final List<_Group> groups;
@override
Widget build(BuildContext context) => Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [for (final group in groups) _GroupBlock(group: group)],
);
}
class _GroupBlock extends StatelessWidget {
const _GroupBlock({required this.group});
final _Group group;
@override
Widget build(BuildContext context) => Padding(
padding: const EdgeInsets.only(bottom: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(group.group.title, style: Theme.of(context).textTheme.titleSmall),
const SizedBox(height: 4),
for (final (index, entry) in group.entries.indexed) ...[
if (index > 0) const Divider(height: 1),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: _ShortcutRow(entry: entry),
),
],
],
),
);
}
class _ShortcutRow extends StatelessWidget {
const _ShortcutRow({required this.entry});
@@ -5,18 +5,34 @@ import '../chat/workspace/chat_float_shortcut.dart';
import '../terminal/terminal_shortcuts.dart';
import '../../shell/windows/window_shortcuts.dart';
import '../../shell/shell_chat_shortcut.dart';
import '../../shell/shell_cheatsheet_shortcut.dart';
import '../../shell/shell_runs_pipelines_shortcut.dart';
import '../../shell/shell_search_shortcut_labels.dart';
/// The headings the help page groups its shortcuts under, in display order.
enum KeyboardShortcutGroup {
navigation('Navigation'),
chat('Chat'),
windows('Windows'),
terminal('Terminal'),
lists('Lists');
const KeyboardShortcutGroup(this.title);
final String title;
}
/// A shortcut entry shown in the in-app help. Keeping these entries together
/// prevents the help page from inventing chords that the handlers do not use.
class KeyboardShortcutEntry {
const KeyboardShortcutEntry({
required this.group,
required this.action,
required this.keys,
this.caveat,
});
final KeyboardShortcutGroup group;
final String action;
final String keys;
final String? caveat;
@@ -36,8 +52,150 @@ class KeyboardShortcutRegistry {
bool get _macOS => platform == TargetPlatform.macOS;
/// The entries of one [group], in the order they are listed.
List<KeyboardShortcutEntry> inGroup(KeyboardShortcutGroup group) => [
for (final entry in entries)
if (entry.group == group) entry,
];
List<KeyboardShortcutEntry> get entries => [
..._navigation,
..._chat,
..._windows,
..._terminal,
..._lists,
];
String get _cheatsheetKeys => shellCheatsheetShortcutLabel(platform);
List<KeyboardShortcutEntry> get _navigation => [
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.navigation,
action: 'Show keyboard shortcuts',
keys: _cheatsheetKeys,
caveat:
'Press again or Esc to close. Ctrl+/ still opens Search. In the terminal the key goes to the terminal.',
),
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.navigation,
action: 'Open Search',
keys: shellSearchShortcutLabels(platform).join(', '),
caveat: web ? 'The browser may reserve some keyboard shortcuts.' : null,
),
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.navigation,
action: 'Leave Search',
keys: 'Esc',
caveat:
'Focuses the search field first, then goes back to the previous page.',
),
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.navigation,
action: 'Open Chat',
keys: shellChatShortcutLabels(platform).join(', '),
caveat: web
? 'Shows the open chat and focuses its message input. The browser may reserve Ctrl+K.'
: 'Shows the open chat and focuses its message input. In the terminal Ctrl+K stays kill-line; Alt+K still opens Chat.',
),
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.navigation,
action: 'Switch between Runs and Pipelines',
keys: shellRunsPipelinesShortcutLabel,
caveat:
'Goes to Runs from other destinations and to Pipelines from Runs. In a text field or the terminal Ctrl+A keeps its own meaning.',
),
];
List<KeyboardShortcutEntry> get _chat => [
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'Focus the active chat composer',
keys: '/',
caveat: 'Only outside text fields and other popup surfaces.',
),
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'Send a chat message',
keys: _apple ? 'Cmd+Enter' : 'Ctrl+Enter',
),
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'Choose a slash command',
keys: 'Up, Down, Enter',
caveat:
'While the slash command list is open above the composer. Esc dismisses it.',
),
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'Toggle Center Stage',
keys:
'${chatCenterStageShortcutLabel(platform)}${_apple ? ', Cmd+E' : ', Ctrl+E'}',
),
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'Stop a running chat',
keys: 'Esc, Esc',
caveat:
'Press Esc twice within one second while a turn runs; the first press shows a hint.',
),
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'Focus the neighbouring chat pane',
keys: _apple ? 'Cmd+Shift+Arrows' : 'Ctrl+Shift+Arrows',
),
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'Move the active chat pane',
keys: _apple ? 'Cmd+Option+Shift+Arrows' : 'Ctrl+Alt+Shift+Arrows',
),
if (!web)
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'Cycle chat panes and floating chats',
keys: 'Ctrl+Tab, Ctrl+Shift+Tab',
caveat:
'While the terminal is shown, Ctrl+Tab moves between its tabs instead.',
),
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'Resize panes with a focused divider',
keys: 'Arrow keys',
caveat: 'While the divider between panes has keyboard focus.',
),
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'Scroll a wide transcript block',
keys: 'Left, Right',
caveat: 'While the block has keyboard focus.',
),
];
List<KeyboardShortcutEntry> get _windows => [
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.windows,
action: 'Show or hide floating chats',
keys: _apple
? '${chatFloatShortcutLabel(platform)}, Ctrl+Y, Cmd+Y'
: '${chatFloatShortcutLabel(platform)}, Ctrl+Y',
caveat:
'Brings a chat forward from Terminal and focuses its message input.',
),
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.windows,
action: 'Cycle floating windows',
keys: _cycleKeys,
),
];
/// Alt+` (Option+` on macOS) and the same chord with Shift, backwards.
String get _cycleKeys {
final forward = windowCycleShortcutLabel(platform);
return '$forward, ${forward.replaceFirst('+', '+Shift+')}';
}
List<KeyboardShortcutEntry> get _terminal => [
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.terminal,
action: 'Show or hide terminal',
keys: TerminalShortcutLabels(
web: web,
@@ -47,61 +205,59 @@ class KeyboardShortcutRegistry {
? 'Browser tab shortcuts such as Cmd+T are not available to the app.'
: null,
),
if (!web)
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.terminal,
action: 'Move between terminal tabs',
keys: 'Ctrl+Tab, Ctrl+Shift+Tab',
),
KeyboardShortcutEntry(
action: 'Show or hide floating chats',
keys: _apple
? '${chatFloatShortcutLabel(platform)}, Ctrl+Y, Cmd+Y'
: '${chatFloatShortcutLabel(platform)}, Ctrl+Y',
caveat:
'Brings a chat forward from Terminal and focuses its message input.',
group: KeyboardShortcutGroup.terminal,
action: 'Copy selected terminal text',
keys: TerminalShortcutLabels(web: web, platform: platform).copy,
caveat: _apple
? null
: 'Ctrl+C copies only while text is selected; otherwise it reaches the process.',
),
KeyboardShortcutEntry(
action: 'Open Chat',
keys: shellChatShortcutLabels(platform).join(', '),
caveat: web
? 'Shows the open chat and focuses its message input. The browser may reserve Ctrl+K.'
: 'Shows the open chat and focuses its message input. In the terminal Ctrl+K stays kill-line; Alt+K still opens Chat.',
group: KeyboardShortcutGroup.terminal,
action: 'Paste into the terminal',
keys: _apple ? 'Cmd+V' : 'Ctrl+V, Ctrl+Shift+V',
),
if (_apple)
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.terminal,
action: 'Select all terminal text',
keys: 'Cmd+A',
),
const KeyboardShortcutEntry(
action: 'Switch between Runs and Pipelines',
keys: shellRunsPipelinesShortcutLabel,
caveat:
'Goes to Runs from other destinations and to Pipelines from Runs. In a text field or the terminal Ctrl+A keeps its own meaning.',
),
KeyboardShortcutEntry(
action: 'Toggle Center Stage',
keys:
'${chatCenterStageShortcutLabel(platform)}${_apple ? ', Cmd+E' : ', Ctrl+E'}',
),
KeyboardShortcutEntry(
action: 'Open Search',
keys: shellSearchShortcutLabels(platform).join(', '),
caveat: web ? 'The browser may reserve some keyboard shortcuts.' : null,
),
KeyboardShortcutEntry(
action: 'Cycle floating windows',
keys:
'${windowCycleShortcutLabel(platform)}, ${windowCycleShortcutLabel(platform)} with Shift',
group: KeyboardShortcutGroup.terminal,
action: 'Resize the terminal panel',
keys: 'Up, Down',
caveat: 'While the panel has keyboard focus.',
),
];
List<KeyboardShortcutEntry> get _lists => [
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.lists,
action: 'Open a chat list item',
keys: _macOS ? 'Cmd+1…9' : 'Ctrl+1…9',
caveat:
'Available when the Chat list is mounted; numbers select its visible item.',
),
KeyboardShortcutEntry(
action: 'Focus the active chat composer',
keys: '/',
caveat: 'Only outside text fields and other popup surfaces.',
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.lists,
action: 'Resize a list pane',
keys: 'Left, Right',
caveat: 'While the divider beside a list has keyboard focus.',
),
KeyboardShortcutEntry(
action: 'Send a chat message',
keys: _apple ? 'Cmd+Enter' : 'Ctrl+Enter',
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.lists,
action: 'Previous or next artifact or changed file',
keys: 'Left, Right',
caveat:
'In an artifact or file-diff viewer. Esc closes an artifact viewer.',
),
if (!web)
const KeyboardShortcutEntry(
action: 'Move between terminal tabs',
keys: 'Ctrl+Tab, Ctrl+Shift+Tab',
),
];
}