fix: focus of chat input

This commit is contained in:
cogwheel0
2025-08-28 18:59:59 +05:30
parent 6427caaa5d
commit 729ab45ee7

View File

@@ -170,6 +170,7 @@ class _ModernChatInputState extends ConsumerState<ModernChatInput>
int _intensity = 0; // 0..10 from service int _intensity = 0; // 0..10 from service
String _baseTextAtStart = ''; String _baseTextAtStart = '';
bool _isDeactivated = false; bool _isDeactivated = false;
int _lastHandledFocusTick = 0;
@override @override
void initState() { void initState() {
@@ -376,13 +377,19 @@ class _ModernChatInputState extends ConsumerState<ModernChatInput>
// React to external focus requests (e.g., from share prefill) // React to external focus requests (e.g., from share prefill)
final focusTick = ref.watch(inputFocusTriggerProvider); final focusTick = ref.watch(inputFocusTriggerProvider);
if (focusTick != _lastHandledFocusTick) {
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted || _isDeactivated) return; if (!mounted || _isDeactivated) return;
if (focusTick > 0) { // Do not steal focus if another input currently has primary focus
final currentFocus = FocusManager.instance.primaryFocus;
final anotherHasFocus = currentFocus != null && currentFocus != _focusNode;
if (!anotherHasFocus) {
_ensureFocusedIfEnabled(); _ensureFocusedIfEnabled();
if (!_isExpanded) _setExpanded(true); if (!_isExpanded) _setExpanded(true);
} }
_lastHandledFocusTick = focusTick;
}); });
}
return Container( return Container(
// Transparent wrapper so rounded corners are visible against page background // Transparent wrapper so rounded corners are visible against page background