Add global shortcuts for opening Chat

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.
This commit is contained in:
2026-11-12 01:08:18 +00:00
parent 4f1b45571f
commit ac5f28bb83
8 changed files with 389 additions and 1 deletions
+21 -1
View File
@@ -9,6 +9,7 @@ import 'destination.dart';
import 'list_detail.dart';
import 'list_pane_widths.dart';
import 'shell_bar.dart';
import 'shell_chat_shortcut.dart';
import 'shell_list_shortcuts.dart';
import 'shell_search_shortcut_labels.dart';
import 'tab_history.dart';
@@ -22,6 +23,7 @@ class AdaptiveShell extends StatefulWidget {
this.onDestinationSelected,
this.onClosePage,
this.onSearch,
this.onOpenChat,
this.attentionCount = 0,
this.runningRunCount,
this.listPaneWidthStore = const SharedPreferencesListPaneWidthStore(),
@@ -47,6 +49,10 @@ class AdaptiveShell extends StatefulWidget {
/// shell tests and compositions without routing keep their tab set only.
final VoidCallback? onSearch;
/// Runs after Ctrl+K or Alt+K has shown the Chat destination (also when it
/// was already shown), so the open chat's composer can take the keyboard.
final VoidCallback? onOpenChat;
/// Runs needing the operator today, retained in the tab's accessible label.
final int attentionCount;
@@ -271,9 +277,16 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
/// fields. Split-pane navigation belongs to the chat workspace; tab changes
/// have no global keyboard chord.
bool _handleDestinationKeyEvent(KeyEvent event) {
final keyboard = HardwareKeyboard.instance;
// Ctrl+K is the terminal's kill-line while the terminal has the keyboard;
// Alt+K still opens Chat there.
if (shellChatShortcut(event, keyboard) &&
(keyboard.isAltPressed || !primaryFocusIsTypingSurface())) {
if (event is KeyDownEvent) _openChat();
return true;
}
// A terminal keeps its keys (Escape, Ctrl+/, Ctrl+digits).
if (primaryFocusIsTypingSurface()) return false;
final keyboard = HardwareKeyboard.instance;
if (_selected == AppDestination.search &&
event is KeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.escape &&
@@ -299,6 +312,13 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
return _bar.lists.open(AppDestination.chat, listIndex);
}
/// Shows Chat (the tab's own selection, so its open chat returns) and then
/// lets the app focus that chat's composer.
void _openChat() {
if (_selected != AppDestination.chat) _select(AppDestination.chat);
widget.onOpenChat?.call();
}
/// A popup or nested viewer owns Escape before the underlying Search tab.
bool _searchEscape() {
final route = ModalRoute.of(context);