Files
pipelines/app/lib/features/settings/keyboard_shortcuts_registry.dart
T
alan 61c7eee2b0 App: open a chat, the terminal or a diff in a new window
"Open in new window" sits beside Float: the chat pane and chat list row
menus, a floating chat window's title bar, the terminal options menu and
the diff bar, plus Alt+Shift+Y for the chat with the keyboard (listed in
the shortcut help). Once the window opens the item leaves the main window
as Float takes a pane out of the tiling.

The window is its own app instance at /window/chat/<id>,
/window/terminal?tab=<key> or /window/diff/<token>: only that item, named
after it, with "Bring back to main window". It has its own connection and
writes no shared layout (no open-chat workspace, window store or terminal
layout) and posts no notifications, so they stay the main window's.

Web opens a popup window (a blocked popup offers a tab); Linux and macOS
start a second process with --detached (Flutter's multi-window API is still
experimental); Android and iOS hide the action. The capture kit gains a
follow step for windows a page opens.

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

350 lines
13 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/detached/detached_window_scope.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: 'Find in chat',
keys: _apple ? 'Cmd+F' : 'Ctrl+F',
caveat:
'Enter moves to an older match, Shift+Enter to a newer one; Esc closes and returns to the composer. Older history is searched on the server and loaded as needed. In the terminal the key goes to the terminal.',
),
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,
),
// A phone has no windows of its own to send a chat to.
if (web ||
platform == TargetPlatform.linux ||
platform == TargetPlatform.macOS)
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.windows,
action: 'Open the chat in a new window',
keys: detachedWindowShortcutLabel(platform),
caveat:
'Moves the chat that has the keyboard to a browser or app '
'window of its own; its "Bring back to main window" returns it.',
),
];
/// 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: 'Next or previous changed file',
keys: 'J, K, Down, Up',
caveat:
'In Changes on a wide window, once the file list has focus; Enter opens the file on its own page. 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.',
),
];
}