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.
111 lines
4.6 KiB
Dart
111 lines
4.6 KiB
Dart
import 'package:flutter/gestures.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
/// Mouse-wheel and trackpad scrolling that reaches the page's vertical list.
|
|
///
|
|
/// A [Scrollable] claims a pointer scroll event whenever its own axis' delta
|
|
/// can move it, and the first claim (the innermost) wins. Two cases follow
|
|
/// that make a vertical list feel stuck:
|
|
///
|
|
/// * a horizontally scrolling code block or table takes a trackpad gesture
|
|
/// for its small sideways component, and the vertical part is dropped;
|
|
/// * controls floating over the list (a bar, a composer, a button) claim
|
|
/// nothing, so the wheel over them moves nothing.
|
|
///
|
|
/// [HorizontalScrollView] and [VerticalWheelForwarder] hand those events to
|
|
/// the vertical list instead.
|
|
|
|
/// Claims [event] for scrolling [position] by the event's vertical delta,
|
|
/// when that delta would move it. Returns whether it was claimed.
|
|
///
|
|
/// The claim goes through the [PointerSignalResolver], so a scrollable deeper
|
|
/// under the pointer that claimed the event first keeps it.
|
|
bool claimVerticalWheel(PointerSignalEvent event, ScrollPosition position) {
|
|
if (event is! PointerScrollEvent) return false;
|
|
if (position.axis != Axis.vertical || !position.hasPixels) return false;
|
|
if (!position.physics.shouldAcceptUserOffset(position)) return false;
|
|
final dy = event.scrollDelta.dy;
|
|
final delta = axisDirectionIsReversed(position.axisDirection) ? -dy : dy;
|
|
if (delta == 0 || _target(position, delta) == position.pixels) return false;
|
|
GestureBinding.instance.pointerSignalResolver.register(event, (event) {
|
|
if (!position.hasPixels) return;
|
|
if (_target(position, delta) == position.pixels) return;
|
|
position.pointerScroll(delta);
|
|
(event as PointerScrollEvent).respond(allowPlatformDefault: false);
|
|
});
|
|
return true;
|
|
}
|
|
|
|
double _target(ScrollPosition position, double delta) =>
|
|
(position.pixels + delta)
|
|
.clamp(position.minScrollExtent, position.maxScrollExtent)
|
|
.toDouble();
|
|
|
|
/// Whether [event] means to scroll sideways: a mostly horizontal gesture, or
|
|
/// a mouse wheel turned with the axis modifier (Shift) held.
|
|
bool isSidewaysWheel(BuildContext context, PointerScrollEvent event) {
|
|
final delta = event.scrollDelta;
|
|
if (event.kind == PointerDeviceKind.mouse) {
|
|
final modifiers = ScrollConfiguration.of(context).pointerAxisModifiers;
|
|
final pressed = HardwareKeyboard.instance.logicalKeysPressed;
|
|
if (pressed.any(modifiers.contains)) return true;
|
|
}
|
|
return delta.dx.abs() > delta.dy.abs();
|
|
}
|
|
|
|
/// A horizontally scrolling box (a code block, a table) inside a vertical
|
|
/// list, which leaves mostly vertical wheel and trackpad scrolling to that
|
|
/// list. A mostly sideways gesture, or Shift + wheel, scrolls this box; touch
|
|
/// drags are unchanged (the gesture arena already splits them by axis).
|
|
class HorizontalScrollView extends StatelessWidget {
|
|
const HorizontalScrollView({super.key, required this.child});
|
|
|
|
final Widget child;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
// Below the horizontal scrollable, so this claim comes before its own.
|
|
// Translucent: the gaps between a table's cells or a block's lines hit no
|
|
// child, yet the scrollable around them still claims the event there.
|
|
child: Listener(
|
|
behavior: HitTestBehavior.translucent,
|
|
onPointerSignal: (event) {
|
|
if (event is! PointerScrollEvent) return;
|
|
if (isSidewaysWheel(context, event)) return;
|
|
final list = Scrollable.maybeOf(context, axis: Axis.vertical);
|
|
if (list != null) claimVerticalWheel(event, list.position);
|
|
},
|
|
child: child,
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Scrolls [controller]'s vertical list with a wheel or trackpad over
|
|
/// [child] (controls floating over the list) when nothing under the pointer
|
|
/// claimed the event first, as the browser scrolls a page under fixed bars.
|
|
/// A multi-line field that can still scroll its own text keeps the event.
|
|
class VerticalWheelForwarder extends StatelessWidget {
|
|
const VerticalWheelForwarder({
|
|
super.key,
|
|
required this.controller,
|
|
required this.child,
|
|
});
|
|
|
|
final ScrollController controller;
|
|
final Widget child;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Listener(
|
|
onPointerSignal: (event) {
|
|
if (event is! PointerScrollEvent || !controller.hasClients) return;
|
|
if (isSidewaysWheel(context, event)) return;
|
|
// A list with several positions (it is being swapped) is left alone.
|
|
if (controller.positions.length != 1) return;
|
|
claimVerticalWheel(event, controller.position);
|
|
},
|
|
child: child,
|
|
);
|
|
}
|