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
14 changes: 13 additions & 1 deletion lib/chat/chat_history_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,11 @@ class _ChatHistoryViewState extends State<ChatHistoryView>
/// The press went to the bar over the selection (see [_placeBubbleBy]).
bool _pressOnBubble = false;

/// The last press in the history, which [_handlePointerDown] saw (and,
/// selecting, gave a bar of its own): not one outside the bar's to take
/// that away again (see [_buildBubble]).
int? _historyPress;

// --- Scrubbing ---------------------------------------------------------------
//
// The minimap's glass or the bar's thumb dragged: each frame a jump to rows
Expand Down Expand Up @@ -1758,6 +1763,7 @@ class _ChatHistoryViewState extends State<ChatHistoryView>

void _handlePointerDown(PointerDownEvent event) {
_pressedDevices.add(event.device);
_historyPress = event.pointer;
final onBubble = _pressOnBubble;
_pressOnBubble = false;
if (!onBubble) _hideBubble();
Expand Down Expand Up @@ -2303,7 +2309,13 @@ class _ChatHistoryViewState extends State<ChatHistoryView>
key: ValueKey(_bubbleShows),
child: shown != 0
? TapRegion(
onTapOutside: (_) => _hideBubble(),
// A press elsewhere in the app. One in the history was
// seen there first (it hears it first, being deeper): it
// took the bar away and, starting a selection, may have
// had it come back, which this would undo.
onTapOutside: (event) {
if (event.pointer != _historyPress) _hideBubble();
},
child: PopIn(
// As the user's messages are: their fill and line.
child: SelectionBubble(
Expand Down
73 changes: 73 additions & 0 deletions test/chat/history_selection_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,79 @@ void main() {
expect(bar, findsOneWidget, reason: 'left where it is');
}, variant: TargetPlatformVariant.only(TargetPlatform.macOS));

testWidgets('a drag begun while the bar shows has a bar of its own; a press '
'outside the history takes it away', (tester) async {
const first = 'The parser drops the last token of every line.';
const second = 'Then the printer has nothing to close the block with.';
final feed = _Feed([
const UserMessageItem(text: 'Why does it fail?'),
const AssistantTextItem('$first\n\n$second'),
])..streaming = false;
addTearDown(feed.dispose);
const outside = Key('outside');
await tester.pumpWidget(
MaterialApp(
theme: buildAppTheme(),
home: Scaffold(
body: Column(
children: [
Expanded(
child: ChatHistoryView(feed: feed, onQuote: (_) {}),
),
const SizedBox(key: outside, height: 60),
],
),
),
),
);
await tester.pumpAndSettle();
RenderParagraph paragraph(String text) =>
tester.renderObject<RenderParagraph>(
find.byWidgetPredicate(
(widget) => widget is RichText && widget.text.toPlainText() == text,
),
);
Offset at(RenderParagraph p, double x) =>
p.localToGlobal(Offset(x, p.size.height / 2));
final bar = find.byType(SelectionBubble);
Future<void> select(RenderParagraph p) async {
final drag = await tester.startGesture(
at(p, 2),
kind: PointerDeviceKind.mouse,
);
await tester.pump();
await drag.moveTo(at(p, 160));
await tester.pumpAndSettle();
await drag.up();
await tester.pumpAndSettle();
}

await select(paragraph(first));
expect(bar, findsOneWidget);
// The next, the bar still there: its press in the history is not one
// outside the bar's, which would take the new one away (only every
// other selection had a bar).
final below = paragraph(second);
await select(below);
expect(bar, findsOneWidget);
expect(
tester.getRect(bar).bottom,
lessThanOrEqualTo(below.localToGlobal(Offset.zero).dy),
);
expect(
tester.getRect(bar).bottom,
greaterThan(paragraph(first).localToGlobal(Offset.zero).dy),
reason: 'over the second paragraph, not the first',
);

await tester.tapAt(
tester.getCenter(find.byKey(outside)),
kind: PointerDeviceKind.mouse,
);
await tester.pumpAndSettle();
expect(bar, findsNothing);
}, variant: TargetPlatformVariant.only(TargetPlatform.macOS));

testWidgets('dragged from the end of a message down into the reply, the '
'bar is over the reply\'s text, not over the message the drag began '
'beside', (tester) async {
Expand Down