diff --git a/app/lib/features/chat/conversation/chat_thread_view.dart b/app/lib/features/chat/conversation/chat_thread_view.dart index 7545f44d..08433399 100644 --- a/app/lib/features/chat/conversation/chat_thread_view.dart +++ b/app/lib/features/chat/conversation/chat_thread_view.dart @@ -318,6 +318,18 @@ class _ChatThreadViewState extends State { if (!mounted) return; _controller.removeLocal(send.operationId); _controller.insertLocal(send.toMessage()); + // Sending always shows the end of the conversation, even when the + // operator had scrolled up or the message is taller than the screen; + // following resumes so the reply stays in view too. + setState(() { + _following = true; + _newestAtRelease = null; + _distanceFromBottom = 0; + }); + _abandonRestore(); + WidgetsBinding.instance.addPostFrameCallback((_) { + if (mounted && !_userScrolling) _jumpToBottom(); + }); } /// A refused message leaves the transcript; it is drawn after it as "Not diff --git a/app/test/features/chat/conversation/chat_send_scrolls_bottom_test.dart b/app/test/features/chat/conversation/chat_send_scrolls_bottom_test.dart new file mode 100644 index 00000000..87c2b317 --- /dev/null +++ b/app/test/features/chat/conversation/chat_send_scrolls_bottom_test.dart @@ -0,0 +1,40 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'chat_thread_fixtures.dart'; +import 'chat_thread_scroll_test.dart' show transcriptScroll; +import 'chat_wheel_fixtures.dart'; + +// Sending a message always shows the end of the conversation, however long +// the message and wherever the operator had scrolled. +void main() { + testWidgets('a long multi-line message sent while scrolled up lands at ' + 'the bottom', (tester) async { + final gateway = FakeChatGateway(); + addTearDown(gateway.close); + gateway.history = (_) async => chatPage(chatWheelFillers(20)); + await openChatWheelThread(tester, gateway); + final scroll = transcriptScroll(tester).position; + + // Scroll well up, so the view no longer follows the end. + final at = chatWheelPoint(tester, chatWheelThread); + for (var i = 0; i < 6; i += 1) { + await wheel(tester, at, const Offset(0, -120)); + } + await tester.pumpAndSettle(); + expect(scroll.pixels, lessThan(scroll.maxScrollExtent - 300)); + + final long = List.generate( + 40, + (i) => 'Line $i of a long message', + ).join('\n'); + await tester.enterText(find.byKey(const Key('chat-composer-field')), long); + await tester.pump(); + await tester.tap(find.byKey(const Key('chat-composer-primary'))); + await tester.pump(); + await tester.pump(); + await tester.pumpAndSettle(); + + expect(scroll.pixels, closeTo(scroll.maxScrollExtent, 0.5)); + }); +}