Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions lib/chat/chat_history_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2413,8 +2413,7 @@ class _ChatHistoryViewState extends State<ChatHistoryView>
final viewport = RenderAbstractViewport.maybeOf(item);
if (viewport is! RenderBox) return false;
final top =
item.localToGlobal(Offset.zero).dy -
(viewport as RenderBox).localToGlobal(Offset.zero).dy +
item.localToGlobal(Offset.zero, ancestor: viewport).dy +
_gapBefore(index);
return top < _editorInset;
}
Expand Down Expand Up @@ -2595,8 +2594,12 @@ class _ChatHistoryViewState extends State<ChatHistoryView>
// Not following the end as the editor grows: that would push its top out
// of a short view, the end of the list in view but not the editor
// (#1257). It is brought into view as it grows (_ensureEditorVisible);
// closed, it follows again.
_followedBeforeEdit = _scrollController.anchored;
// closed, it follows again. A click opened it: the press stopped the list
// following while held, to follow again as it is let go, after this
// (the message hears it first, see _handlePointerUp); it is this that
// has it follow again now.
_followedBeforeEdit = _scrollController.anchored || _followedBeforePress;
_followedBeforePress = false;
_scrollController.anchored = false;
setState(() {
_closingIndex = null;
Expand Down Expand Up @@ -2719,9 +2722,7 @@ class _ChatHistoryViewState extends State<ChatHistoryView>
.where((box) => _indexOf(box) == index)
.firstOrNull;
if (item == null) return null;
final top =
item.localToGlobal(Offset(0, _gapBefore(index))).dy -
layer.localToGlobal(Offset.zero).dy;
final top = _topIn(layer, item, _gapBefore(index));
return _sticks ? math.max(top, inset) : top;
}
// Not findRenderObject: painted in the frame whose layout dropped the
Expand All @@ -2731,9 +2732,7 @@ class _ChatHistoryViewState extends State<ChatHistoryView>
(_editorPlaceholderKey.currentContext as Element?)?.renderObject
as RenderBox?;
if (placeholder != null && placeholder.attached && placeholder.hasSize) {
final top =
placeholder.localToGlobal(Offset.zero).dy -
layer.localToGlobal(Offset.zero).dy;
final top = _topIn(layer, placeholder, 0);
return _sticks ? math.max(top, inset) : top;
}
final first = _laidOutItems().firstOrNull;
Expand All @@ -2744,6 +2743,12 @@ class _ChatHistoryViewState extends State<ChatHistoryView>
return null;
}

/// How far [y] in [box] is below the top of [layer], in [layer]'s units:
/// not the difference of their places on screen, which the window's zoom
/// scales (see [UiZoom]) while [layer] paints in units of its own.
static double _topIn(RenderBox layer, RenderBox box, double y) =>
MatrixUtils.transformPoint(box.getTransformTo(layer), Offset(0, y)).dy;

// --- The sticky user message ---------------------------------------------

/// Room above the stuck message: as above the list's first item, and at
Expand Down
11 changes: 9 additions & 2 deletions lib/chat/widgets/user_message_bubble.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ class UserMessageBubble extends StatefulWidget {
if (box == null || !box.attached || !box.hasSize) return null;
final fitted = UserMessageStyle.current.value == UserMessageStyle.bubble;
return (
rect: box.localToGlobal(Offset.zero) & box.size,
// On screen, zoomed (see UiZoom) as its place is.
rect: MatrixUtils.transformRect(
box.getTransformTo(null),
Offset.zero & box.size,
),
radius: fitted ? _MessageShape.radius : radius,
tail: fitted ? 1.0 : 0.0,
);
Expand Down Expand Up @@ -919,7 +923,10 @@ class _RenderEditMorph extends RenderProxyBox {
super.paint(context, offset);
return;
}
final from = _fromHere ??= _from.rect.shift(-localToGlobal(Offset.zero));
final from = _fromHere ??= MatrixUtils.inverseTransformRect(
getTransformTo(null),
_from.rect,
);
final rect = Rect.lerp(from, Offset.zero & size, t)!;
final radius =
_from.radius + (UserMessageEditMorph.radius - _from.radius) * t;
Expand Down
48 changes: 45 additions & 3 deletions test/chat/message_edit_visibility_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:baocode/chat/widgets/user_message_bubble.dart';
import 'package:baocode/kernel/agent_kernel.dart';
import 'package:baocode/kernel/claude_code/claude_code_kernel.dart';
import 'package:baocode/theme/app_theme.dart';
import 'package:baocode/theme/ui_zoom.dart';

import '../kernel_test.dart' show FakeCli;

Expand Down Expand Up @@ -51,6 +52,7 @@ Future<void> _stopped(
Size size = const Size(1000, 600),
bool following = false,
bool toolRunning = false,
double zoom = 1,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
Expand Down Expand Up @@ -78,8 +80,11 @@ Future<void> _stopped(
MaterialApp(
theme: buildAppTheme(),
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context).copyWith(disableAnimations: reducedMotion),
child: child!,
data: UiZoom.zoomed(
MediaQuery.of(context),
zoom,
).copyWith(disableAnimations: reducedMotion),
child: UiZoom(scale: zoom, child: child),
),
home: ChatScreen(session: session, embedded: true),
),
Expand Down Expand Up @@ -137,12 +142,16 @@ Future<void> _stopped(
expect(position.pixels, lessThan(position.maxScrollExtent));
}

Future<void> _edit(WidgetTester tester) async {
Future<void> _edit(
WidgetTester tester, {
PointerDeviceKind kind = PointerDeviceKind.touch,
}) async {
await tester.tap(
find.descendant(
of: _bubble(),
matching: find.text(_message, findRichText: true),
),
kind: kind,
);
await tester.pumpAndSettle();
expect(_editor(), findsOneWidget);
Expand Down Expand Up @@ -229,6 +238,39 @@ void main() {
}
}, variant: platforms);

testWidgets('clicked with a mouse, the editor no more follows the end than '
'tapped ($style)', (tester) async {
await _stopped(tester, style, following: true);
await _edit(tester, kind: PointerDeviceKind.mouse);
_visible(tester);
final position = _position(tester);
// The editor's bottom at the view's: the list's own room under it is
// left out of view.
expect(position.pixels, lessThan(position.maxScrollExtent));
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
expect(position.pixels, position.maxScrollExtent);
await tester.pumpWidget(const SizedBox());
}, variant: platforms);

testWidgets('under the window\'s zoom, the editor opens where its message '
'is ($style)', (tester) async {
for (final zoom in [0.8, 1.25]) {
await _stopped(tester, style, zoom: zoom);
final before = tester.getRect(_bubble());
final offset = _position(tester).pixels;
await _edit(tester);
_visible(tester);
// On screen, the scroll is zoomed as the rest is.
final scrolled = (_position(tester).pixels - offset) * zoom;
expect(
tester.getRect(_editor()).top,
closeTo(before.top - scrolled, 1),
);
await tester.pumpWidget(const SizedBox());
}
}, variant: platforms);

testWidgets('a growing message editor stays above the composer ($style)', (
tester,
) async {
Expand Down