d02d5ea11d
Root causes found in release web captures (1280x800 and 560x900): - Follow mode undid small wheel/trackpad ticks at the end: each tick is its own scroll, re-judged as following within 32 px and jumped back. A user scroll toward older rows now releases the end however small; the jump control appears once streamed content moves the end beyond the threshold. - The end-of-scroll jump ran inside the position's activity switch, so a touch or scrollbar drag released near the end recursed without end (stack overflow during the gesture). The jump now runs after the notification. - Horizontally scrolling code blocks and tables claimed diagonal trackpad gestures whole. HorizontalScrollView gives mostly vertical gestures to the enclosing list; sideways and Shift + wheel still scroll the block. - The wheel over the floating chat bar, composer and jump control moved nothing. VerticalWheelForwarder scrolls the transcript from them unless something under the pointer claims the event. Adds widget tests per content kind and scroll mode, follow/touch/Load older tests, a capture-kit check (tool/capture/examples/chat-wheel-scroll.json) with eval/expect steps, wheel dx/repeat, --params and eval: targets, a transcript scroll probe and fixture options, and fixes the kit ignoring a script's size. Notes in notes/chat-wheel-scroll.md.
155 lines
5.3 KiB
Dart
155 lines
5.3 KiB
Dart
// Scroll position probe for browser captures of the chat transcript.
|
|
//
|
|
// `window.chatScrollMetrics()` returns the open transcript's vertical scroll
|
|
// position as JSON: `{"pixels", "min", "max", "viewport"}`, or `null` when no
|
|
// transcript is shown. tool/capture's `eval=` and `expect=` steps read it, so a
|
|
// wheel step can be checked against the offset it should have moved.
|
|
//
|
|
// `window.chatScrollTargets()` returns, as JSON, the centre point of the
|
|
// visible part of the first instance of each content kind in the transcript (`code`,
|
|
// `wide` code, `table`, `image`, `agent` report, `notice`), so a capture can
|
|
// put the wheel over it. `window.chatSidewaysOffsets()` lists the built code
|
|
// blocks' and tables' horizontal offsets, so a sideways scroll can be seen.
|
|
import 'dart:convert';
|
|
import 'dart:js_interop';
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:pipelines_app/features/chat/conversation/chat_transcript_scroll_view.dart';
|
|
import 'package:pipelines_app/features/chat/ui/transcript/chat_attachment_gallery.dart';
|
|
import 'package:pipelines_app/features/chat/ui/transcript/chat_injected_rows.dart';
|
|
|
|
@JS('chatScrollMetrics')
|
|
external set _chatScrollMetrics(JSFunction probe);
|
|
|
|
@JS('chatScrollTargets')
|
|
external set _chatScrollTargets(JSFunction probe);
|
|
|
|
@JS('chatSidewaysOffsets')
|
|
external set _chatSidewaysOffsets(JSFunction probe);
|
|
|
|
void installChatScrollProbe() {
|
|
_chatScrollMetrics = (() => _metrics()?.toJS).toJS;
|
|
_chatScrollTargets = (() => _targets().toJS).toJS;
|
|
_chatSidewaysOffsets = (() => _sideways().toJS).toJS;
|
|
}
|
|
|
|
/// The content kind [element] draws, or null for one that is not a target.
|
|
String? _kind(Element element) {
|
|
final widget = element.widget;
|
|
if (widget is Table) return 'table';
|
|
if (widget is ChatAttachmentGallery) return 'image';
|
|
if (widget is ChatAgentReportCard) return 'agent';
|
|
if (widget is ChatSystemNoticeLine) return 'notice';
|
|
if (widget is SingleChildScrollView &&
|
|
widget.scrollDirection == Axis.horizontal) {
|
|
// A code block; a table's own element is reported as `table`.
|
|
var table = false;
|
|
ScrollPosition? position;
|
|
void inside(Element child) {
|
|
if (child.widget is Table) table = true;
|
|
if (child is StatefulElement && child.state is ScrollableState) {
|
|
position ??= (child.state as ScrollableState).position;
|
|
}
|
|
if (!table) child.visitChildren(inside);
|
|
}
|
|
|
|
element.visitChildren(inside);
|
|
final scroll = position;
|
|
if (table || scroll == null || !scroll.hasContentDimensions) return null;
|
|
return scroll.maxScrollExtent > 0 ? 'wide' : 'code';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
String _targets() {
|
|
final points = <String, List<double>>{};
|
|
final view = WidgetsBinding.instance.platformDispatcher.views.first;
|
|
final screen = Offset.zero & (view.physicalSize / view.devicePixelRatio);
|
|
// Clear of the floating bar above and the composer below.
|
|
final region = Rect.fromLTRB(0, 80, screen.width, screen.height - 160);
|
|
void visit(Element element) {
|
|
final kind = _kind(element);
|
|
if (kind != null && !points.containsKey(kind)) {
|
|
final box = element.findRenderObject();
|
|
if (box is RenderBox && box.attached && box.hasSize) {
|
|
final rect = (box.localToGlobal(Offset.zero) & box.size).intersect(
|
|
region,
|
|
);
|
|
if (rect.width >= 20 && rect.height >= 20) {
|
|
points[kind] = [rect.center.dx, rect.center.dy];
|
|
}
|
|
}
|
|
}
|
|
element.visitChildren(visit);
|
|
}
|
|
|
|
void transcript(Element element) {
|
|
if (element.widget is ChatTranscriptScrollView) {
|
|
element.visitChildren(visit);
|
|
return;
|
|
}
|
|
element.visitChildren(transcript);
|
|
}
|
|
|
|
WidgetsBinding.instance.rootElement?.visitChildren(transcript);
|
|
return jsonEncode(points);
|
|
}
|
|
|
|
String _sideways() {
|
|
final offsets = <double>[];
|
|
void visit(Element element) {
|
|
if (element is StatefulElement && element.state is ScrollableState) {
|
|
final position = (element.state as ScrollableState).position;
|
|
if (position.axis == Axis.horizontal && position.hasPixels) {
|
|
offsets.add(position.pixels);
|
|
}
|
|
}
|
|
element.visitChildren(visit);
|
|
}
|
|
|
|
void transcript(Element element) {
|
|
if (element.widget is ChatTranscriptScrollView) {
|
|
element.visitChildren(visit);
|
|
return;
|
|
}
|
|
element.visitChildren(transcript);
|
|
}
|
|
|
|
WidgetsBinding.instance.rootElement?.visitChildren(transcript);
|
|
return jsonEncode(offsets);
|
|
}
|
|
|
|
String? _metrics() {
|
|
ScrollPosition? found;
|
|
void scrollable(Element element) {
|
|
if (found != null) return;
|
|
if (element is StatefulElement && element.state is ScrollableState) {
|
|
final position = (element.state as ScrollableState).position;
|
|
if (position.axis == Axis.vertical) {
|
|
found = position;
|
|
return;
|
|
}
|
|
}
|
|
element.visitChildren(scrollable);
|
|
}
|
|
|
|
void transcript(Element element) {
|
|
if (found != null) return;
|
|
if (element.widget is ChatTranscriptScrollView) {
|
|
scrollable(element);
|
|
return;
|
|
}
|
|
element.visitChildren(transcript);
|
|
}
|
|
|
|
WidgetsBinding.instance.rootElement?.visitChildren(transcript);
|
|
final position = found;
|
|
if (position == null || !position.hasPixels) return null;
|
|
return jsonEncode({
|
|
'pixels': position.pixels,
|
|
'min': position.minScrollExtent,
|
|
'max': position.maxScrollExtent,
|
|
'viewport': position.viewportDimension,
|
|
});
|
|
}
|