Files
pipelines/app/lib/features/settings/keyboard_shortcuts_registry.dart
T
alan 12c7642e35 Chat quick switcher MRU, Closed section and markers; Alt+N, Alt+J and run tab keys
Ctrl+K lists open chats most recently used first (tracked on open and pane
focus, persisted per server) and preselects the previous chat, so Ctrl+K,
Enter returns to it. Rows mark needs you / working / unread; a query also
lists matching closed chats under Closed, and choosing one reopens it.
Alt+N (Option+N) starts a new chat and Alt+J (Option+J) opens the next chat
waiting for you, unread or failed, cycling; the terminal keeps both. In run
detail, bare 1-4 switch tabs when not typing. Cheatsheet entries added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:49:36 +00:00

323 lines
12 KiB
Dart

import 'package:flutter/foundation.dart';
import '../chat/workspace/chat_center_stage_controller.dart';
import '../chat/workspace/chat_float_shortcut.dart';
import '../terminal/terminal_shortcuts.dart';
import '../../shell/windows/window_shortcuts.dart';
import '../../shell/shell_chat_actions_shortcut.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'),
search('Search');
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;
}
class KeyboardShortcutRegistry {
const KeyboardShortcutRegistry({required this.platform, required this.web});
factory KeyboardShortcutRegistry.current() =>
KeyboardShortcutRegistry(platform: defaultTargetPlatform, web: kIsWeb);
final TargetPlatform platform;
final bool web;
bool get _apple =>
platform == TargetPlatform.macOS || platform == TargetPlatform.iOS;
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,
..._search,
];
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
? 'From another destination: shows the open chat and focuses its message input. On Chat it opens the chat switcher. The browser may reserve Ctrl+K.'
: 'From another destination: shows the open chat and focuses its message input. On Chat it opens the chat switcher. In the terminal Ctrl+K stays kill-line; ${_apple ? 'Option+K and Cmd+K still open' : '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: 'Switch to another chat',
keys: shellChatShortcutLabels(platform).join(', '),
caveat:
'On Chat: the open chats, most recently used first, with the previous chat selected, so the shortcut then Enter goes back to it. Type to filter (matching closed chats are listed under Closed; Enter reopens one), Ctrl+N or Down and Ctrl+P or Up to move, Enter to open, Esc or the shortcut again to close.${web ? ' A browser tab keeps Ctrl+N (new window) for itself; use Down, or the installed app.' : ''}',
),
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'New chat',
keys: shellChatActionLabel(ShellChatAction.newChat, platform),
caveat:
'From any destination. In the terminal the key goes to the terminal.',
),
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'Next chat needing you',
keys: shellChatActionLabel(ShellChatAction.nextAttention, platform),
caveat:
'Opens the next chat waiting for you, with unread replies, or with a failed action, in list order; press again to cycle. In the terminal the key goes to the terminal.',
),
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 Files',
keys: _apple ? 'Cmd+E' : 'Ctrl+E',
),
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'Toggle Center Stage',
keys:
'${chatCenterStageShortcutLabel(platform)}${_apple ? ', Cmd+Shift+E' : ', Ctrl+Shift+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 chats and floating chat panes',
keys: 'Ctrl+Tab, Ctrl+Shift+Tab',
caveat:
'Opens the next or previous chat in list order: only the starred chats when any are starred, otherwise all open chats (not closed, hidden or floating ones). A chat already shown in another pane is focused there. 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,
platform: platform,
).toggle.join(', '),
caveat: [
TerminalShortcutLabels(web: web, platform: platform).inTerminalNote,
if (web)
'Browser tab shortcuts such as Cmd+T are not available to the app.',
].join(' '),
),
if (!web)
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.terminal,
action: 'Move between terminal tabs',
keys: 'Ctrl+Tab, Ctrl+Shift+Tab',
),
KeyboardShortcutEntry(
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(
group: KeyboardShortcutGroup.terminal,
action: 'Paste into the terminal',
keys: _apple ? 'Cmd+V' : 'Ctrl+V, Ctrl+Shift+V, Shift+Insert',
),
if (_apple)
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.terminal,
action: 'Select all terminal text',
keys: 'Cmd+A',
),
if (TerminalShortcutLabels(web: web, platform: platform).browserKeysNote
case final note?)
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.terminal,
action: 'Send browser keys to the terminal',
keys: 'Terminal menu: Capture browser keys',
caveat:
'$note Firefox and Safari cannot capture them; readline '
'alternatives that reach the page: Ctrl+U deletes to the line '
'start, Alt+B and Alt+F move by word.',
),
const KeyboardShortcutEntry(
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.',
),
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.lists,
action: 'Switch run detail tabs',
keys: '1, 2, 3, 4',
caveat:
'In a run: Summary, Timeline, Artifacts, Changes, as the run offers them. Not while typing.',
),
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.lists,
action: 'Resize a list pane',
keys: 'Left, Right',
caveat: 'While the divider beside a list has keyboard focus.',
),
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.',
),
];
List<KeyboardShortcutEntry> get _search => [
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.search,
action: 'Move through Search results',
keys: 'Ctrl+N, Ctrl+P, Up, Down',
caveat:
'While the Search field is focused. Uses Control rather than Cmd on macOS; Enter opens the highlighted result.',
),
];
}