2bbc737604
Provide a platform-independent destination shortcut that preserves Ctrl+A for text fields and the terminal. Document the shortcut in help and cover navigation and focus exceptions with regression tests.
108 lines
3.7 KiB
Dart
108 lines
3.7 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_runs_pipelines_shortcut.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: '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(
|
|
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',
|
|
),
|
|
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',
|
|
),
|
|
];
|
|
}
|