Skip to content

Commit

Permalink
compose_box: Send typing notifications on scroll
Browse files Browse the repository at this point in the history
When selecting from the list of autocompletion, the user is still
considered to be actively composing.

Fixes: #666
  • Loading branch information
PIG208 committed Oct 31, 2024
1 parent 7a29e50 commit 95c2ac6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 15 deletions.
38 changes: 23 additions & 15 deletions lib/widgets/compose_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,12 @@ class _ContentInputState extends State<_ContentInput> with WidgetsBindingObserve
store.typingNotifier.stoppedComposing();
}

bool _handleScroll(ScrollNotification notification) {
final store = PerAccountStoreWidget.of(context);
store.typingNotifier.keystroke(widget.destination);
return false;
}

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
Expand Down Expand Up @@ -377,21 +383,23 @@ class _ContentInputState extends State<_ContentInput> with WidgetsBindingObserve
// TODO constrain this adaptively (i.e. not hard-coded 200)
maxHeight: 200,
),
child: ComposeAutocomplete(
narrow: widget.narrow,
controller: widget.controller,
focusNode: widget.focusNode,
fieldViewBuilder: (context) {
return TextField(
controller: widget.controller,
focusNode: widget.focusNode,
style: TextStyle(color: colorScheme.onSurface),
decoration: InputDecoration.collapsed(hintText: widget.hintText),
maxLines: null,
textCapitalization: TextCapitalization.sentences,
);
}),
));
child: NotificationListener<ScrollNotification>(
onNotification: _handleScroll,
child: ComposeAutocomplete(
narrow: widget.narrow,
controller: widget.controller,
focusNode: widget.focusNode,
fieldViewBuilder: (context) {
return TextField(
controller: widget.controller,
focusNode: widget.focusNode,
style: TextStyle(color: colorScheme.onSurface),
decoration: InputDecoration.collapsed(hintText: widget.hintText),
maxLines: null,
textCapitalization: TextCapitalization.sentences,
);
}),
)));
}
}

Expand Down
29 changes: 29 additions & 0 deletions test/widgets/compose_box_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,35 @@ void main() {
await tester.pump(store.typingNotifier.typingStoppedWaitPeriod);
checkTypingRequest(TypingOp.stop, narrow);
});

testWidgets('scrolling autocompletion sends "typing started" notice', (tester) async {
final users = List.generate(10, (i) => eg.user(fullName: 'User $i'));
final narrow = DmNarrow.withUser(
users[0].userId, selfUserId: eg.selfUser.userId);
await prepareComposeBox(tester,
narrow: narrow, users: [eg.otherUser, ...users]);

connection.prepare(json: {});
// TODO(#226): Remove this extra edit when this bug is fixed.
await tester.enterText(contentInputFinder, '@Use');
await tester.enterText(contentInputFinder, '@User');
await tester.pumpAndSettle(); // async computation; options appear
checkTypingRequest(TypingOp.start, narrow);

connection.prepare(json: {});
await tester.pump(store.typingNotifier.typingStoppedWaitPeriod);
checkTypingRequest(TypingOp.stop, narrow);

connection.prepare(json: {});
await tester.drag(find.text(users[0].fullName), const Offset(0, 5));
await tester.pump(Duration.zero);
checkTypingRequest(TypingOp.start, narrow);

// Ensures that a "typing stopped" notice is sent when the test ends.
connection.prepare(json: {});
await tester.pump(store.typingNotifier.typingStoppedWaitPeriod);
checkTypingRequest(TypingOp.stop, narrow);
});
});

group('message-send request response', () {
Expand Down

0 comments on commit 95c2ac6

Please sign in to comment.