Files
pipelines/app/lib/features/settings/keyboard_shortcuts_registry.dart
T
alan 21115f8e8f Add unified keyboard shortcut help
Expose platform-aware shortcut help from Settings, keep narrow layouts scrollable, share Search tooltip labels, and document Terminal-to-chat composer focus. Integrate together with the separately reviewed Alt-slash handler.
2026-11-11 20:05:56 +00:00

93 lines
2.9 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_search_shortcut_labels.dart';
/// 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.action,
required this.keys,
this.caveat,
});
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;
List<KeyboardShortcutEntry> get entries => [
KeyboardShortcutEntry(
action: 'Show or hide terminal',
keys: TerminalShortcutLabels(
web: web,
platform: platform,
).toggle.join(', '),
caveat: web
? 'Browser tab shortcuts such as Cmd+T are not available to the app.'
: null,
),
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.',
),
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',
),
KeyboardShortcutEntry(
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.',
),
KeyboardShortcutEntry(
action: 'Send a chat message',
keys: _apple ? 'Cmd+Enter' : 'Ctrl+Enter',
),
if (!web)
const KeyboardShortcutEntry(
action: 'Move between terminal tabs',
keys: 'Ctrl+Tab, Ctrl+Shift+Tab',
),
];
}