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, _ChatScreenWorkspace { ChatRuntime get _runtime; ModalRoute? _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?; } }