The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Desktop thread: open at the newest reply, like Slack (no Jump to latest click) (#2432)
0xken159e2443e346c2
diff --git a/desktop/lib/super_tabs/thread_panel.dart b/desktop/lib/super_tabs/thread_panel.dartindex e14b0d64e..2aa13b395 100644--- a/desktop/lib/super_tabs/thread_panel.dart+++ b/desktop/lib/super_tabs/thread_panel.dart@@ -18,6 +18,7 @@ import 'composer_toggle.dart';import 'controller.dart';import 'jump_to_latest.dart';import 'model.dart';+import 'thread_scroll.dart';import 'project_sidebar.dart' show kProductManagersChannel;/// One thread beside the chat (Dee, 2026-10-29): its root, a "N replies"@@ -54,7 +55,8 @@ class _SuperTabThreadPanelState extends State<SuperTabThreadPanel> {text: c.threadDraft(widget.root),);final _focus = FocusNode();- final _scroll = ScrollController();+ // Opens at the newest reply and follows it until the reader scrolls up.+ final _scroll = SuperTabThreadScroll();bool _alsoSend = false;// The reply starts this thread's own Buddy session (reader's Buddy chat).bool _newSession = false;@@ -63,9 +65,10 @@ class _SuperTabThreadPanelState extends State<SuperTabThreadPanel> {// the thread's replies are known), and the latest replies and rows (replies// and those on their way): what came since is the control's count.bool _away = false, _atEnd = false, _baselined = false;- int _repliesAtEnd = 0, _replies = 0, _rows = 0, _rowsMeasured = 0;- // Each jump to the end supersedes the one before it.- int _jumpRequest = 0;+ int _repliesAtEnd = 0, _replies = 0;+ // The newest row (reply or one on its way), as built and as last measured:+ // earlier replies arriving above do not change it.+ String? _newest, _newestMeasured;SuperTabController get c => widget.controller;@@ -80,14 +83,13 @@ class _SuperTabThreadPanelState extends State<SuperTabThreadPanel> {void didUpdateWidget(SuperTabThreadPanel old) {super.didUpdateWidget(old);if (old.root != widget.root) {- // Another thread starts from its top, with nothing counted.+ // Another thread opens at its newest reply, with nothing counted._away = false;_atEnd = false;_baselined = false;_repliesAtEnd = 0;- _rowsMeasured = 0;- _jumpRequest++;- if (_scroll.hasClients) _scroll.jumpTo(0);+ _newestMeasured = null;+ _scroll.followEnd();// Each thread keeps its own draft._composer.text = c.threadDraft(widget.root);_alsoSend = false;@@ -97,7 +99,6 @@ class _SuperTabThreadPanelState extends State<SuperTabThreadPanel> {@overridevoid dispose() {- _jumpRequest++;_scroll.dispose();_composer.dispose();_focus.dispose();@@ -113,11 +114,12 @@ class _SuperTabThreadPanelState extends State<SuperTabThreadPanel> {void _measure() {if (!mounted || !_scroll.hasClients) return;final position = _scroll.position;- if (_rows > _rowsMeasured && _atEnd && position.extentAfter >= 40) {- _rowsMeasured = _rows;- position.jumpTo(position.maxScrollExtent);+ // Near the end (not quite at it, where the scroll follows by itself), a+ // new row still brings the reader down to it.+ if (_newest != _newestMeasured && _atEnd && position.extentAfter >= 40) {+ _scroll.followEnd();}- _rowsMeasured = _rows;+ _newestMeasured = _newest;final away = position.extentAfter >= 40;final atEnd = !away;// What the thread held when it opened is not new; nor is what the reader@@ -133,31 +135,11 @@ class _SuperTabThreadPanelState extends State<SuperTabThreadPanel> {});}- /// Scrolls to the newest reply. A lazy list refines its extent as rows near- /// the end are laid out, so one jump can stop above the last reply: jump- /// again, a bounded number of times, until nothing is left below.+ /// Scrolls to the newest reply and follows it again; the scroll settles on+ /// the real end as the rows there are laid out.void _jumpToLatest() {- final request = ++_jumpRequest;- void advance(int attempt) {- WidgetsBinding.instance.addPostFrameCallback((_) {- if (!mounted || request != _jumpRequest || !_scroll.hasClients) return;- _scroll.jumpTo(_scroll.position.maxScrollExtent);- WidgetsBinding.instance.addPostFrameCallback((_) {- if (!mounted || request != _jumpRequest || !_scroll.hasClients) {- return;- }- if (_scroll.position.extentAfter > 1 && attempt < 12) {- advance(attempt + 1);- } else {- _measure();- }- });- WidgetsBinding.instance.scheduleFrame();- });- WidgetsBinding.instance.scheduleFrame();- }-- advance(0);+ _scroll.followEnd();+ _measureAfterFrame();}/// Where "Also send" also puts the reply, full wording first (Scholes,@@ -273,7 +255,7 @@ class _SuperTabThreadPanelState extends State<SuperTabThreadPanel> {final count =c.thread(c.selectedId, widget.root)?.replies ?? replies.length;_replies = count > replies.length ? count : replies.length;- _rows = replies.length + pending.length;+ _newest = '${replies.lastOrNull?.id}/${pending.length}';if (!_baselined &&(c.thread(c.selectedId, widget.root) != null || replies.isNotEmpty)) {_baselined = true;@@ -372,9 +354,11 @@ class _SuperTabThreadPanelState extends State<SuperTabThreadPanel> {key: const ValueKey('super-thread-earlier'),onPressed: c.readingEarlierReplies? null- : () => unawaited(- c.loadThread(earlier: true),- ),+ : () {+ // They read on from where they are.+ _scroll.holdPlace();+ unawaited(c.loadThread(earlier: true));+ },child: Text(c.readingEarlierReplies? 'Loading earlier replies…'diff --git a/desktop/lib/super_tabs/thread_scroll.dart b/desktop/lib/super_tabs/thread_scroll.dartnew file mode 100644index 000000000..6b95de7b9--- /dev/null+++ b/desktop/lib/super_tabs/thread_scroll.dart@@ -0,0 +1,92 @@+import 'package:flutter/widgets.dart';++/// A thread's scroll: it opens at the newest reply and stays there, as+/// Slack's threads do (Dee, 2026-10-31).+///+/// The list's end is known only as its rows are laid out: replies still being+/// read, a long message or a picture settling, a lazy list refining its+/// estimate of the rows not built yet. So the view does not jump once and+/// hope; while it follows the end, every layout puts it there, before+/// anything is painted. The reader scrolling away stops that; scrolling back+/// to the end, or Jump to latest, starts it again.+class SuperTabThreadScroll extends ScrollController {+ SuperTabThreadScroll() : super(keepScrollOffset: false);++ /// Puts the view at the newest reply and keeps it there, as when a thread+ /// opens.+ void followEnd() {+ for (final position in positions) {+ if (position is _EndPosition) position._followEnd();+ }+ }++ /// Keeps the view where it is as rows arrive, even at the end: the reader+ /// asked for earlier replies and reads on from where they are.+ void holdPlace() {+ for (final position in positions) {+ if (position is _EndPosition) position._following = false;+ }+ }++ @override+ ScrollPosition createScrollPosition(+ ScrollPhysics physics,+ ScrollContext context,+ ScrollPosition? oldPosition,+ ) => _EndPosition(+ physics: physics,+ context: context,+ oldPosition: oldPosition,+ debugLabel: debugLabel,+ );+}++class _EndPosition extends ScrollPositionWithSingleContext {+ _EndPosition({+ required super.physics,+ required super.context,+ super.oldPosition,+ super.debugLabel,+ }) : super(keepScrollOffset: false);++ // A new view starts at the end.+ bool _following = true;++ void _followEnd() {+ // A fling still coasting would move the view off the end again.+ goIdle();+ _following = true;+ // The next layout (a new thread's rows) settles it at the real end.+ notifyListeners();+ }++ @override+ bool applyContentDimensions(double minScrollExtent, double maxScrollExtent) {+ if (_following && (pixels - maxScrollExtent).abs() > .5) {+ // Laid out again from there: rows near the end are built and measured,+ // and the end is checked once more.+ correctPixels(maxScrollExtent);+ return false;+ }+ return super.applyContentDimensions(minScrollExtent, maxScrollExtent);+ }++ // The reader moved the view (a drag, the wheel, a key, a jump): at the+ // end, it follows the end; anywhere else it stays where it is.+ void _moved() {+ if (hasContentDimensions) _following = pixels >= maxScrollExtent - .5;+ }++ @override+ double setPixels(double newPixels) {+ final overscroll = super.setPixels(newPixels);+ _moved();+ return overscroll;+ }++ @override+ void forcePixels(double value) {+ super.forcePixels(value);+ _moved();+ }+}diff --git a/desktop/test/super_tab_jump_to_latest_test.dart b/desktop/test/super_tab_jump_to_latest_test.dartindex 60ef55174..dbbb9d174 100644--- a/desktop/test/super_tab_jump_to_latest_test.dart+++ b/desktop/test/super_tab_jump_to_latest_test.dart@@ -171,7 +171,10 @@ void main() {c.openThread('message-1');await tester.pumpAndSettle();expect(panel(), findsOneWidget);- // A thread opens at its root, replies below.+ // A thread opens at its newest reply; read back, it offers the way down.+ expect(inPanel(find.byKey(jump)), findsNothing);+ threadScroll(tester).jumpTo(0);+ await tester.pumpAndSettle();expect(inPanel(find.byKey(jump)), findsOneWidget);await tester.tap(inPanel(find.byKey(jump)));@@ -214,11 +217,13 @@ void main() {});testWidgets('replies that arrive while the reader stays at the root of a '- 'long thread are counted, with no scrolling first', (tester) async {+ 'long thread are counted', (tester) async {final server = threadOf(30);final c = await show(tester, server);c.openThread('message-1');await tester.pumpAndSettle();+ threadScroll(tester).jumpTo(0);+ await tester.pumpAndSettle();for (final text in ['Reply 31: late.', 'Reply 32: later.']) {server.append(text);server.messages.last@@ -258,6 +263,12 @@ void main() {final c = await show(tester, server);c.openThread('message-1');await tester.pumpAndSettle();+ // It opens on the real last reply, not an estimate of where it is.+ expect(threadScroll(tester).position.extentAfter, lessThan(1));+ expect(inPanel(find.textContaining('Reply 60:')), findsOneWidget);+ expect(inPanel(find.byKey(jump)), findsNothing);+ threadScroll(tester).jumpTo(0);+ await tester.pumpAndSettle();expect(inPanel(find.byKey(jump)), findsOneWidget);await tester.tap(inPanel(find.byKey(jump)));@@ -276,9 +287,6 @@ void main() {final c = await show(tester, server);c.openThread('message-1');await tester.pumpAndSettle();- final scroll = threadScroll(tester);- scroll.jumpTo(scroll.position.maxScrollExtent);- await tester.pumpAndSettle();server.append('Reply 31: late.');server.messages.last..['thread'] = 'message-1'diff --git a/desktop/test/super_tab_thread_scroll_shots_test.dart b/desktop/test/super_tab_thread_scroll_shots_test.dartnew file mode 100644index 000000000..63b6f876c--- /dev/null+++ b/desktop/test/super_tab_thread_scroll_shots_test.dart@@ -0,0 +1,111 @@+import 'dart:io';+import 'dart:ui' as ui;++import 'package:flutter/material.dart';+import 'package:flutter/rendering.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness/shared/theme/app_theme.dart' as grid;+import 'package:harness/super_tabs/view.dart';++import 'box_render_preview_test.dart' show loadPreviewFonts;+import 'support/super_tab_fixture.dart';++/// Set to a folder to write the PR's screenshots there.+final shots = Platform.environment['SUPER_TAB_THREAD_OPEN_SHOTS'];++const _updates = [+ 'Reading the offline queue before the reconnect.',+ 'The reconnect keeps every queued edit in order.',+ 'Two devices editing at once settle on the newest edit.',+ 'Pushed the branch; the checks are running.',+];++/// A long thread just opened: at its newest reply, the reply box under it,+/// and no Jump to latest (Dee, 2026-10-31).+void main() {+ setUpAll(() async {+ if (shots != null) await loadPreviewFonts();+ });++ for (final brightness in Brightness.values) {+ testWidgets('screenshots for review (${brightness.name})', (tester) async {+ final picture = GlobalKey();+ const peer = {'kind': 'person', 'id': 'peer', 'name': '[email protected]'};+ final server = ConversationServer()..threads = true;+ (server.state['people'] as List).add({+ 'id': 'peer',+ 'email': '[email protected]',+ 'role': 'collaborator',+ });+ server.append('Should we do thread replies?');+ for (var i = 1; i <= 24; i++) {+ server.append('${_updates[i % _updates.length]} ($i)');+ server.messages.last+ ..['thread'] = 'message-1'+ ..['replyTo'] = 'message-1'+ ..['author'] = peer;+ }+ for (var i = 1; i <= 40; i++) {+ server.append('${_updates[i % _updates.length]} ($i)');+ server.messages.last['author'] = {+ 'kind': 'agent',+ 'id': 'lead-agent',+ 'name': 'Lead',+ };+ }+ final c = server.controller();+ addTearDown(c.dispose);+ await c.refresh();+ grid.AppTheme.brightness.value = brightness;+ addTearDown(() => grid.AppTheme.brightness.value = Brightness.light);+ await tester.binding.setSurfaceSize(const Size(1400, 800));+ addTearDown(() => tester.binding.setSurfaceSize(null));+ await tester.pumpWidget(+ MaterialApp(+ theme: grid.buildAppTheme(brightness: brightness),+ builder: (context, child) =>+ RepaintBoundary(key: picture, child: child),+ home: Scaffold(+ body: SuperTabView(+ controller: c,+ onInvite: () {},+ onAddAgent: (_) {},+ onOpenTerminal: (_) {},+ machineName: (_) => 'Mac Studio',+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ c.openThread('message-1');+ await tester.pumpAndSettle();+ final thread = tester+ .widget<ListView>(+ find.descendant(+ of: find.byKey(const ValueKey('super-thread-panel')),+ matching: find.byType(ListView),+ ),+ )+ .controller!;+ expect(thread.position.extentAfter, lessThan(1));+ expect(find.textContaining('(24)'), findsWidgets);+ expect(find.byKey(const ValueKey('super-jump-latest')), findsNothing);++ if (shots != null) {+ await tester.runAsync(() async {+ final boundary =+ picture.currentContext!.findRenderObject()!+ as RenderRepaintBoundary;+ final image = await boundary.toImage(pixelRatio: 1.5);+ final bytes = await image.toByteData(format: ui.ImageByteFormat.png);+ await Directory(shots!).create(recursive: true);+ await File('$shots/thread-opens-at-newest-${brightness.name}.png')+ .writeAsBytes(bytes!.buffer.asUint8List());+ image.dispose();+ });+ }+ await tester.pumpWidget(const SizedBox());+ await c.flush();+ });+ }+}diff --git a/desktop/test/super_tab_thread_scroll_test.dart b/desktop/test/super_tab_thread_scroll_test.dartnew file mode 100644index 000000000..a4334f6f0--- /dev/null+++ b/desktop/test/super_tab_thread_scroll_test.dart@@ -0,0 +1,367 @@+import 'dart:async';++import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness/shared/theme/app_theme.dart' as grid;+import 'package:harness/super_tabs/controller.dart';+import 'package:harness/super_tabs/model.dart';+import 'package:harness/super_tabs/thread_panel.dart';+import 'package:harness/super_tabs/view.dart';++import 'support/super_tab_fixture.dart';++/// A thread opens at its newest reply, as Slack's do (Dee, 2026-10-31): never+/// at its root or somewhere in the middle, and with no Jump to latest until+/// the reader scrolls up.+void main() {+ const jump = ValueKey('super-jump-latest');+ const peer = {'kind': 'person', 'id': 'peer', 'name': '[email protected]'};++ Future<SuperTabController> show(+ WidgetTester tester,+ ConversationServer server,+ ) async {+ await tester.binding.setSurfaceSize(const Size(1400, 900));+ addTearDown(() => tester.binding.setSurfaceSize(null));+ final c = server.controller();+ await c.refresh();+ await tester.pumpWidget(+ MaterialApp(+ theme: grid.buildAppTheme(brightness: Brightness.dark),+ home: Scaffold(+ body: SuperTabView(+ controller: c,+ onInvite: () {},+ onAddAgent: (_) {},+ onOpenTerminal: (_) {},+ machineName: (_) => 'Team Mac',+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ addTearDown(c.dispose);+ return c;+ }++ Finder panel() => find.byKey(const ValueKey('super-thread-panel'));+ Finder inPanel(Finder finder) =>+ find.descendant(of: panel(), matching: finder);+ ScrollPosition threadScroll(WidgetTester tester) => tester+ .widget<ListView>(inPanel(find.byType(ListView)))+ .controller!+ .position;++ void reply(+ ConversationServer server,+ String text, {+ String root = 'message-1',+ }) {+ server.append(text);+ server.messages.last+ ..['thread'] = root+ ..['replyTo'] = root+ ..['author'] = peer;+ }++ ConversationServer server() {+ final s = ConversationServer()..threads = true;+ (s.state['people'] as List).add({+ 'id': 'peer',+ 'email': '[email protected]',+ 'role': 'collaborator',+ });+ return s;+ }++ /// A root and [replies] replies; every third runs to many lines.+ ConversationServer threadOf(int replies) {+ final s = server();+ s.append('Should we do thread replies?');+ for (var i = 1; i <= replies; i++) {+ reply(+ s,+ i % 3 == 0+ ? 'Reply $i: ${List.filled(60, 'word$i').join(' ')}'+ : 'Reply $i: a long enough answer to fill the pane.',+ );+ }+ return s;+ }++ void expectAtNewest(WidgetTester tester, String newest) {+ final position = threadScroll(tester);+ expect(position.extentAfter, lessThan(1), reason: 'not at the end');+ expect(inPanel(find.textContaining(newest)), findsOneWidget);+ expect(inPanel(find.byKey(jump)), findsNothing);+ }++ testWidgets('a long thread opens at its newest reply, with no Jump to '+ 'latest and the reply box focused', (tester) async {+ final c = await show(tester, threadOf(40));+ c.openThread('message-1');+ await tester.pumpAndSettle();++ expectAtNewest(tester, 'Reply 40:');+ final box = tester.widget<EditableText>(+ inPanel(find.byType(EditableText)).first,+ );+ expect(box.focusNode.hasFocus, isTrue);+ expect(tester.takeException(), isNull);+ });++ testWidgets('replies read after the thread opened still land at the '+ 'newest one', (tester) async {+ final s = threadOf(40)..messagePage = 3;+ final c = await show(tester, s);+ s.holdReads = Completer<void>();+ c.openThread('message-1');+ await tester.pump();+ await tester.pump();+ // Only what the chat had read is there yet.+ expect(inPanel(find.textContaining('Reply 10:')), findsNothing);++ s.holdReads!.complete();+ s.holdReads = null;+ await tester.pumpAndSettle();++ expect(c.threadMessages('message-1').length, greaterThan(10));+ expectAtNewest(tester, 'Reply 40:');+ });++ testWidgets('a thread reopened after it was read back opens at its newest '+ 'reply again', (tester) async {+ final c = await show(tester, threadOf(40));+ c.openThread('message-1');+ await tester.pumpAndSettle();+ threadScroll(tester).jumpTo(300);+ await tester.pumpAndSettle();+ expect(inPanel(find.byKey(jump)), findsOneWidget);++ c.closeThread();+ await tester.pumpAndSettle();+ c.openThread('message-1');+ await tester.pumpAndSettle();++ expectAtNewest(tester, 'Reply 40:');+ });++ testWidgets('another thread opened in its place opens at its own newest '+ 'reply', (tester) async {+ final s = threadOf(40);+ s.append('A second topic.');+ final second = s.messages.last['id'] as String;+ for (var i = 1; i <= 30; i++) {+ reply(+ s,+ 'Other $i: a long enough answer to fill the pane.',+ root: second,+ );+ }+ final c = await show(tester, s);+ c.openThread('message-1');+ await tester.pumpAndSettle();+ threadScroll(tester).jumpTo(200);+ await tester.pumpAndSettle();++ c.openThread(second);+ await tester.pumpAndSettle();++ expectAtNewest(tester, 'Other 30:');+ });++ testWidgets('a reply arriving at the end keeps the thread at its end; '+ 'scrolled up, it stays put and is counted', (tester) async {+ final s = threadOf(40);+ final c = await show(tester, s);+ c.openThread('message-1');+ await tester.pumpAndSettle();++ reply(s, 'Reply 41: while at the end.');+ await c.refresh();+ await tester.pumpAndSettle();+ expectAtNewest(tester, 'Reply 41:');++ threadScroll(tester).jumpTo(0);+ await tester.pumpAndSettle();+ reply(s, 'Reply 42: while read back.');+ await c.refresh();+ await tester.pumpAndSettle();+ expect(threadScroll(tester).pixels, 0);+ expect(inPanel(find.text('1 new reply')), findsOneWidget);+ await tester.pumpWidget(const SizedBox());+ await c.flush();+ });++ testWidgets('a reader who drags the thread up is left there, with Jump to '+ 'latest, as replies arrive', (tester) async {+ final s = threadOf(40);+ final c = await show(tester, s);+ c.openThread('message-1');+ await tester.pumpAndSettle();++ await tester.drag(inPanel(find.byType(ListView)), const Offset(0, 400));+ await tester.pumpAndSettle();+ final read = threadScroll(tester).pixels;+ expect(threadScroll(tester).extentAfter, greaterThan(40));+ expect(inPanel(find.byKey(jump)), findsOneWidget);++ reply(s, 'Reply 41: while dragged up.');+ await c.refresh();+ await tester.pumpAndSettle();+ expect(threadScroll(tester).pixels, read);+ expect(inPanel(find.text('1 new reply')), findsOneWidget);++ await tester.tap(inPanel(find.text('1 new reply')));+ await tester.pumpAndSettle();+ expectAtNewest(tester, 'Reply 41:');+ await tester.pumpWidget(const SizedBox());+ await c.flush();+ });++ final macOS = TargetPlatformVariant.only(TargetPlatform.macOS);++ /// Flings the thread back up and lets it coast for a moment, still moving.+ Future<void> flingUp(WidgetTester tester) async {+ await tester.fling(+ inPanel(find.byType(ListView)),+ const Offset(0, 600),+ 4000,+ );+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 80));+ expect(+ threadScroll(tester).activity,+ isA<BallisticScrollActivity>(),+ reason: 'the fling should still be moving',+ );+ }++ testWidgets('Jump to latest clicked while a fling still coasts ends at the '+ 'newest reply', (tester) async {+ final c = await show(tester, threadOf(60));+ c.openThread('message-1');+ await tester.pumpAndSettle();++ await flingUp(tester);+ expect(inPanel(find.byKey(jump)), findsOneWidget);+ await tester.tap(inPanel(find.byKey(jump)));+ await tester.pumpAndSettle();++ expectAtNewest(tester, 'Reply 60:');+ }, variant: macOS);++ testWidgets('another thread opened while a fling still coasts opens at its '+ 'newest reply', (tester) async {+ final s = threadOf(60);+ s.append('A second topic.');+ final second = s.messages.last['id'] as String;+ for (var i = 1; i <= 30; i++) {+ reply(+ s,+ 'Other $i: a long enough answer to fill the pane.',+ root: second,+ );+ }+ final c = await show(tester, s);+ c.openThread('message-1');+ await tester.pumpAndSettle();++ await flingUp(tester);+ c.openThread(second);+ await tester.pumpAndSettle();++ expectAtNewest(tester, 'Other 30:');+ }, variant: macOS);++ testWidgets('Show earlier replies in a thread that fits the pane keeps the '+ 'reader where they were', (tester) async {+ final s = server()..messagePage = 2;+ s.append('Should we do thread replies?');+ for (var i = 1; i <= 16; i++) {+ reply(s, i <= 6 ? 'Early $i.' : 'Reply $i.');+ }+ final c = s.controller();+ await c.refresh();+ addTearDown(c.dispose);+ c.openThread('message-1');+ await c.loadThread();+ await tester.binding.setSurfaceSize(const Size(500, 575));+ addTearDown(() => tester.binding.setSurfaceSize(null));+ await tester.pumpWidget(+ MaterialApp(+ theme: grid.buildAppTheme(brightness: Brightness.dark),+ home: Scaffold(+ // Redrawn as the controller changes, as the chat view does.+ body: ListenableBuilder(+ listenable: c,+ builder: (_, _) => SuperTabThreadPanel(+ controller: c,+ root: 'message-1',+ // The earliest replies, read only on request, are tall.+ row: (SuperTabMessage m, bool grouped) => SizedBox(+ height: m.text.startsWith('Early') ? 120 : 30,+ child: Text(m.text, maxLines: 1),+ ),+ outgoing: (_) => const SizedBox.shrink(),+ ),+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ // It fits: the root, the earlier-replies button and the newest replies.+ expect(threadScroll(tester).maxScrollExtent, 0);+ expect(find.text('Should we do thread replies?'), findsOneWidget);++ await tester.tap(find.byKey(const ValueKey('super-thread-earlier')));+ await tester.pumpAndSettle();++ // Read back, it no longer fits, and the reader is still at the top.+ expect(threadScroll(tester).maxScrollExtent, greaterThan(0));+ expect(threadScroll(tester).pixels, 0);+ expect(find.text('Should we do thread replies?'), findsOneWidget);+ });++ testWidgets('rows that grow after the thread opened (a picture, a code '+ 'block) keep it at the newest reply', (tester) async {+ final s = threadOf(12);+ final c = s.controller();+ await c.refresh();+ addTearDown(c.dispose);+ c.openThread('message-1');+ await c.loadThread();+ // Each row's height settles only after it is first drawn.+ final grown = ValueNotifier(false);+ addTearDown(grown.dispose);+ await tester.binding.setSurfaceSize(const Size(500, 700));+ addTearDown(() => tester.binding.setSurfaceSize(null));+ await tester.pumpWidget(+ MaterialApp(+ theme: grid.buildAppTheme(brightness: Brightness.dark),+ home: Scaffold(+ body: SuperTabThreadPanel(+ controller: c,+ root: 'message-1',+ row: (SuperTabMessage m, bool grouped) => ValueListenableBuilder(+ valueListenable: grown,+ builder: (_, grown, _) => SizedBox(+ height: grown ? 160 : 40,+ child: Text(m.text, maxLines: 1),+ ),+ ),+ outgoing: (_) => const SizedBox.shrink(),+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ expectAtNewest(tester, 'Reply 12:');++ grown.value = true;+ await tester.pumpAndSettle();++ expectAtNewest(tester, 'Reply 12:');+ expect(tester.takeException(), isNull);+ });+}