c5af000453
- Desktop and web terminals use the text-input path too, so IMEs, dead keys, the emoji picker and dictation work; the key handler still encodes special keys and chords first (handled keys are never typed again), composing text is drawn at the cursor and sent on commit, the platform editable sits at the cursor, and a closed input reopens on the next key. The editable terminal is a semantics text field so web typing also works with semantics on. - Web: "Capture browser keys" (terminal menu and right-click menu) goes full screen and calls navigator.keyboard.lock(); hold Esc to leave. No-op where unsupported; cheatsheet and menu note give alternatives. - Touch: scrollable key row with sticky Ctrl/Alt (tap once, double-tap lock), Esc, Tab, arrows, Home/End, PgUp/PgDn and symbols through the hardware encoder; soft keyboard types per key (delete detection, Return as Enter); the line field moves behind the row's Line button. - Capture kit: compose=, --semantics false, --user-agent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
294 lines
10 KiB
Dart
294 lines
10 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_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
|
|
? '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; ${_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: '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:
|
|
'With one tiled pane, cycles open sidebar chats (excluding closed, hidden and floating chats); with multiple panes, cycles panes. 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',
|
|
),
|
|
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: '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.',
|
|
),
|
|
];
|
|
}
|