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:
@@ -15,6 +15,7 @@ import 'conversation/chat_scroll.dart';
|
||||
import 'conversation/chat_thread_view.dart';
|
||||
import 'conversation/chat_transcript_cache.dart';
|
||||
import 'conversation/composer_focus_request.dart';
|
||||
import 'conversation/composer_selection_focus.dart';
|
||||
import 'data/chat_repository.dart';
|
||||
import 'domain/chat_commands.dart';
|
||||
import 'domain/chat_cycle.dart';
|
||||
@@ -95,7 +96,8 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
|
||||
String? _standaloneSelection;
|
||||
|
||||
/// Ctrl+1…Ctrl+9 put the keyboard in the opened chat's composer.
|
||||
/// Ctrl+1…Ctrl+9 put the keyboard in the opened chat's composer; choosing a
|
||||
/// chat does too where [chatSelectionFocusesComposer] allows.
|
||||
final ChatComposerFocusRequests _composerFocus = ChatComposerFocusRequests();
|
||||
|
||||
/// The list's folded sections, kept here so Next chat counts the rows the
|
||||
@@ -109,6 +111,8 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Seen from now on, so the press that chooses the first chat counts.
|
||||
LastPointerKind.instance;
|
||||
_sessions.addListener(_nextChanged);
|
||||
_folds.addListener(_nextChanged);
|
||||
}
|
||||
@@ -124,7 +128,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
/// Next chat opens that row exactly as a tap on it would.
|
||||
void _openNext(String id) {
|
||||
final next = _nextAfter(id);
|
||||
if (next != null) _open(next);
|
||||
if (next != null) _openBySelection(next);
|
||||
}
|
||||
|
||||
void _nextChanged() {
|
||||
@@ -153,6 +157,12 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
/// also when it is the chat already open.
|
||||
void _openByShortcut(JsonMap session) => _open(session, focusComposer: true);
|
||||
|
||||
/// Opens [session] chosen by a tap, click or Next chat: its composer takes
|
||||
/// focus on a desktop host or after a mouse click, not from a finger on a
|
||||
/// phone or tablet (see [chatSelectionFocusesComposer]).
|
||||
void _openBySelection(JsonMap session) =>
|
||||
_open(session, focusComposer: chatSelectionFocusesComposer(session));
|
||||
|
||||
void _open(JsonMap session, {bool focusComposer = false}) {
|
||||
final id = '${session['id'] ?? ''}';
|
||||
if (id.isEmpty) return;
|
||||
@@ -370,7 +380,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
syncToken: widget.syncToken,
|
||||
controller: _sessions,
|
||||
folds: _folds,
|
||||
onOpen: _open,
|
||||
onOpen: _openBySelection,
|
||||
onShortcutOpen: _openByShortcut,
|
||||
onSessions: _adoptRows,
|
||||
activeSessionId: selected,
|
||||
|
||||
Reference in New Issue
Block a user