Chat: Ctrl+K / Alt+K on Chat opens a quick switcher for the open chats
On Chat the chord now toggles a centred dialog (bottom sheet on a phone) with an autofocused filter over the open chats in list order; Ctrl+N/Down and Ctrl+P/Up move the wrapping selection, Enter opens the chat as Ctrl+Tab does (pane reused, composer focused), Esc or the chord closes it. From other destinations the chord still jumps to Chat. Ctrl+N/Ctrl+P are handled so the web page prevents their defaults (Ctrl+P no longer prints); a browser tab keeps Ctrl+N reserved, documented in the help and notes/chat-quick-switch.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
part of 'screen.dart';
|
||||
|
||||
/// The quick switcher Ctrl+K / Alt+K (Cmd+K on a Mac) shows when pressed on
|
||||
/// the Chat destination: the open chats to jump to, filtered as the operator
|
||||
/// types (see [showChatQuickSwitch]). Pressing the shortcut again closes it.
|
||||
/// A chosen chat opens as a keyboard choice from the list does: its pane is
|
||||
/// reused when it is already open, and its composer takes the keyboard.
|
||||
mixin _ChatScreenQuickSwitch on State<ChatScreen>, _ChatScreenWorkspace {
|
||||
ChatRuntime get _runtime;
|
||||
|
||||
ModalRoute<JsonMap>? _quickSwitchRoute;
|
||||
|
||||
void _bindQuickSwitch() => _runtime.quickSwitch.attach(_toggleQuickSwitch);
|
||||
|
||||
void _unbindQuickSwitch() {
|
||||
_runtime.quickSwitch.detach(_toggleQuickSwitch);
|
||||
final open = _quickSwitchRoute;
|
||||
_quickSwitchRoute = null;
|
||||
// The navigator is locked while this screen is torn down; close after.
|
||||
if (open != null) {
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
(_) => closeChatQuickSwitch(open),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _toggleQuickSwitch() {
|
||||
final open = _quickSwitchRoute;
|
||||
if (open != null && open.isActive) {
|
||||
_quickSwitchRoute = null;
|
||||
closeChatQuickSwitch(open);
|
||||
return;
|
||||
}
|
||||
// Another popup or dialog over the chat keeps the keyboard.
|
||||
if (!mounted || !_chatOwnsKeyboard()) return;
|
||||
final route = showChatQuickSwitch(
|
||||
context,
|
||||
sessions: _runtime.sessions,
|
||||
serverName: _quickSwitchServerName,
|
||||
onSelected: (row) {
|
||||
if (mounted) _openByShortcut(row);
|
||||
},
|
||||
);
|
||||
_quickSwitchRoute = route;
|
||||
route.popped.whenComplete(() {
|
||||
if (identical(_quickSwitchRoute, route)) _quickSwitchRoute = null;
|
||||
});
|
||||
}
|
||||
|
||||
/// The machine a federated row is on, as the list names it.
|
||||
String? _quickSwitchServerName(JsonMap row) {
|
||||
final id = '${row['_server_id'] ?? ''}';
|
||||
final named = mounted && id.isNotEmpty
|
||||
? ServerContext.nameFor(context, id)
|
||||
: null;
|
||||
return named ?? row['_server_name'] as String?;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user