Settle bottom-anchored restores, flush open timings in the probe, record numbers

This commit is contained in:
2026-11-02 00:55:03 +00:00
parent a5f0eb3811
commit c74065dc48
5 changed files with 123 additions and 33 deletions
@@ -203,6 +203,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
double? _restoreOffset;
bool _restoring = false;
double _restoreMeasuredExtent = 0;
double _restoreMeasuredStart = 0;
/// True during a pointer/touch/wheel scroll. Programmatic placement and
/// follow jumps never set it, so they cannot release the follow intent.
@@ -434,6 +435,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
_restoring = false;
_restoreOffset = null;
_restoreMeasuredExtent = 0;
_restoreMeasuredStart = 0;
_lastOffset = 0;
} else if (oldWidget.syncToken != widget.syncToken) {
// The socket was replaced: conditions recorded before the gap are stale,
@@ -585,6 +587,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
if (_scroll.position.pixels != target) _scroll.jumpTo(target);
_lastOffset = target;
_restoreMeasuredExtent = _scroll.position.maxScrollExtent;
_restoreMeasuredStart = _scroll.position.minScrollExtent;
_distanceFromBottom = chatBottomDistance(
maxScrollExtent: _restoreMeasuredExtent,
pixels: _scroll.position.pixels,
@@ -607,8 +610,12 @@ class _ChatThreadViewState extends State<ChatThreadView> {
}
if (_restoring) {
final measuredBefore = _restoreMeasuredExtent;
final startBefore = _restoreMeasuredStart;
_applyRestore();
if (_scroll.position.maxScrollExtent == measuredBefore) {
// Bottom-anchored, the older rows' estimated extent above the centre
// settles too, and a saved offset there is clamped to it.
if (_scroll.position.maxScrollExtent == measuredBefore &&
_scroll.position.minScrollExtent == startBefore) {
// The measured extent stopped changing: the restored offset is the
// operator's real position again, so follow intent can be judged.
_restoring = false;