Skip to content

Commit 95c2ac6

Browse files
committed
compose_box: Send typing notifications on scroll
When selecting from the list of autocompletion, the user is still considered to be actively composing. Fixes: #666
1 parent 7a29e50 commit 95c2ac6

File tree

2 files changed

+52
-15
lines changed

2 files changed

+52
-15
lines changed

lib/widgets/compose_box.dart

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ class _ContentInputState extends State<_ContentInput> with WidgetsBindingObserve
339339
store.typingNotifier.stoppedComposing();
340340
}
341341

342+
bool _handleScroll(ScrollNotification notification) {
343+
final store = PerAccountStoreWidget.of(context);
344+
store.typingNotifier.keystroke(widget.destination);
345+
return false;
346+
}
347+
342348
@override
343349
void didChangeAppLifecycleState(AppLifecycleState state) {
344350
switch (state) {
@@ -377,21 +383,23 @@ class _ContentInputState extends State<_ContentInput> with WidgetsBindingObserve
377383
// TODO constrain this adaptively (i.e. not hard-coded 200)
378384
maxHeight: 200,
379385
),
380-
child: ComposeAutocomplete(
381-
narrow: widget.narrow,
382-
controller: widget.controller,
383-
focusNode: widget.focusNode,
384-
fieldViewBuilder: (context) {
385-
return TextField(
386-
controller: widget.controller,
387-
focusNode: widget.focusNode,
388-
style: TextStyle(color: colorScheme.onSurface),
389-
decoration: InputDecoration.collapsed(hintText: widget.hintText),
390-
maxLines: null,
391-
textCapitalization: TextCapitalization.sentences,
392-
);
393-
}),
394-
));
386+
child: NotificationListener<ScrollNotification>(
387+
onNotification: _handleScroll,
388+
child: ComposeAutocomplete(
389+
narrow: widget.narrow,
390+
controller: widget.controller,
391+
focusNode: widget.focusNode,
392+
fieldViewBuilder: (context) {
393+
return TextField(
394+
controller: widget.controller,
395+
focusNode: widget.focusNode,
396+
style: TextStyle(color: colorScheme.onSurface),
397+
decoration: InputDecoration.collapsed(hintText: widget.hintText),
398+
maxLines: null,
399+
textCapitalization: TextCapitalization.sentences,
400+
);
401+
}),
402+
)));
395403
}
396404
}
397405

test/widgets/compose_box_test.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,35 @@ void main() {
423423
await tester.pump(store.typingNotifier.typingStoppedWaitPeriod);
424424
checkTypingRequest(TypingOp.stop, narrow);
425425
});
426+
427+
testWidgets('scrolling autocompletion sends "typing started" notice', (tester) async {
428+
final users = List.generate(10, (i) => eg.user(fullName: 'User $i'));
429+
final narrow = DmNarrow.withUser(
430+
users[0].userId, selfUserId: eg.selfUser.userId);
431+
await prepareComposeBox(tester,
432+
narrow: narrow, users: [eg.otherUser, ...users]);
433+
434+
connection.prepare(json: {});
435+
// TODO(#226): Remove this extra edit when this bug is fixed.
436+
await tester.enterText(contentInputFinder, '@Use');
437+
await tester.enterText(contentInputFinder, '@User');
438+
await tester.pumpAndSettle(); // async computation; options appear
439+
checkTypingRequest(TypingOp.start, narrow);
440+
441+
connection.prepare(json: {});
442+
await tester.pump(store.typingNotifier.typingStoppedWaitPeriod);
443+
checkTypingRequest(TypingOp.stop, narrow);
444+
445+
connection.prepare(json: {});
446+
await tester.drag(find.text(users[0].fullName), const Offset(0, 5));
447+
await tester.pump(Duration.zero);
448+
checkTypingRequest(TypingOp.start, narrow);
449+
450+
// Ensures that a "typing stopped" notice is sent when the test ends.
451+
connection.prepare(json: {});
452+
await tester.pump(store.typingNotifier.typingStoppedWaitPeriod);
453+
checkTypingRequest(TypingOp.stop, narrow);
454+
});
426455
});
427456

428457
group('message-send request response', () {

0 commit comments

Comments
 (0)