Chat: choosing a chat focuses its composer on desktop

A row click or tap, Next chat and a created chat put the keyboard in the
composer, as Ctrl+1-9 does, on desktop hosts (native or desktop browser, any
window width) and after a mouse or trackpad click anywhere. A finger tap on a
phone or tablet (Android, iOS, mobile browsers) leaves focus alone so the
on-screen keyboard does not cover the transcript. Closed chats are not
focused, and a request yields when another control took focus meanwhile.
This commit is contained in:
2026-11-04 20:42:20 +00:00
parent 1d025bebf3
commit 38cd92813b
4 changed files with 278 additions and 4 deletions
@@ -75,13 +75,27 @@ class ComposerFocusRequestListener {
void _onRequest() {
final scope = _scope;
if (scope == null || !scope.requests.take(scope.sessionId)) return;
final before = FocusManager.instance.primaryFocus;
SchedulerBinding.instance
..addPostFrameCallback((_) {
if (!_disposed && canFocus()) focus.requestFocus();
if (!_disposed && _focusIsFree(before) && canFocus()) {
focus.requestFocus();
}
})
..ensureVisualUpdate();
}
/// False when, since the request, another control took focus (the
/// operator moved on before the chat was built); the composer then leaves
/// it there.
bool _focusIsFree(FocusNode? before) {
final current = FocusManager.instance.primaryFocus;
return current == null ||
current == before ||
current == focus ||
current is FocusScopeNode;
}
void dispose() {
_disposed = true;
_scope?.requests.removeListener(_onRequest);