part of 'screen.dart'; /// Keys the Chat destination answers from anywhere in it, also while the /// sidebar or a toolbar owns focus: a bare `/` puts the keyboard in the open /// chat's composer. It is handled before the focus tree, like the workspace's /// pane cycling, and leaves other destinations, popups, dialogs and any /// focused text field alone. mixin _ChatScreenKeys on State, _ChatScreenWorkspace { /// Whether the shown destination is Chat with no popup, dialog or other /// route over it, so a key pressed now is meant for the open chat. @override bool _chatOwnsKeyboard() { final destination = ShellBarScope.maybeOf(context)?.registry.focus; if (destination != null && destination != AppDestination.chat) return false; final focusContext = FocusManager.instance.primaryFocus?.context; final route = focusContext == null ? ModalRoute.of(context) : ModalRoute.of(focusContext); return route is! PopupRoute && (route == null || route.isCurrent); } /// A bare `/` typed outside any text field focuses the active chat's /// composer. The composer takes focus after this frame (see /// [ChatComposerFocusRequests]), once the host has finished delivering the /// keystroke, so the slash itself is not typed into it. Inside a text field /// (the composer, a dialog's field) `/` stays an ordinary character. bool _slashFocusKey(KeyEvent event) { final keyboard = HardwareKeyboard.instance; if (event is! KeyDownEvent || event.character != '/' || keyboard.isControlPressed || keyboard.isMetaPressed || keyboard.isAltPressed || !_workspaceVisible) { return false; } final id = _workspace.activePane?.sessionId; if (id == null || _textFieldHasFocus() || !_chatOwnsKeyboard()) { return false; } _composerFocus.request(id); return true; } /// Whether something that takes typing holds focus, wherever it is: an /// editable text field or a terminal. bool _textFieldHasFocus() => primaryFocusTakesTyping(); }