ac5f28bb83
Allow Ctrl+K and Alt+K to switch to Chat from any destination, while preserving terminal Ctrl+K behavior and focusing the active composer. Register the shortcuts in help and cover matching, navigation, terminal handling, and composer focus with regression tests.
101 lines
3.3 KiB
Dart
101 lines
3.3 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_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.',
|
|
),
|
|
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',
|
|
),
|
|
];
|
|
}
|