Skip to content

Commit 7049811

Browse files
committed
autocomplete: Put best matches near input field. This commit reverses the list that was originally
presented to the user while showing the typeahead menu. This makes sense since on mobile its easier to click on options closer to the input box, i.e. where your fingers are currently present, instead of pressing arrow keys on a keyboard which is true on a desktop setup. Hence we place the best matching options not at the top of the typeahead menu, but instead put them at the bottom for better reachability and convenience of the user. Fixes zulip#1123. Fixes zulip#1121.
1 parent cf19d68 commit 7049811

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

lib/widgets/autocomplete.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class _AutocompleteFieldState<QueryT extends AutocompleteQuery, ResultT extends
134134
constraints: const BoxConstraints(maxHeight: 300), // TODO not hard-coded
135135
child: ListView.builder(
136136
padding: EdgeInsets.zero,
137+
reverse: true,
137138
shrinkWrap: true,
138139
itemCount: _resultsToDisplay.length,
139140
itemBuilder: _buildItem))));

test/widgets/autocomplete_test.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,59 @@ void main() {
246246

247247
debugNetworkImageHttpClientProvider = null;
248248
});
249+
testWidgets('emoji options appear in the correct rendering order', (tester) async {
250+
final composeInputFinder = await setupToComposeInput(tester);
251+
final store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
252+
253+
// Set up emoji data
254+
store.setServerEmojiData(
255+
ServerEmojiData(
256+
codeToNames: {
257+
'1f4a4': ['zzz', 'sleepy'], // Unicode emoji for "zzz"
258+
},
259+
),
260+
);
261+
await store.handleEvent(
262+
RealmEmojiUpdateEvent(
263+
id: 1,
264+
realmEmoji: {
265+
'1': eg.realmEmojiItem(emojiCode: '1', emojiName: 'buzzing'),
266+
},
267+
),
268+
);
269+
270+
const zulipOptionLabel = 'zulip';
271+
const zzzOptionLabel = 'zzz, sleepy';
272+
const unicodeGlyph = '💤';
273+
const buzzingOptionLabel = 'buzzing';
274+
275+
await tester.enterText(composeInputFinder, 'hi :');
276+
await tester.enterText(composeInputFinder, 'hi :z');
277+
await tester.pumpAndSettle();
278+
279+
final listViewFinder = find.byType(ListView);
280+
expect(listViewFinder, findsOneWidget, reason: 'ListView should be rendered');
281+
282+
// Explicitly check the `reverse` property of the `ListView`
283+
final listViewWidget = tester.widget<ListView>(listViewFinder);
284+
expect(listViewWidget.reverse, isTrue, reason: 'ListView reverse property should be true');
285+
286+
final positions = [
287+
find.text(zulipOptionLabel),
288+
find.text(zzzOptionLabel),
289+
find.text(unicodeGlyph),
290+
find.text(buzzingOptionLabel),
291+
].map((finder) {
292+
expect(finder, findsOneWidget, reason: 'Each emoji option should be rendered');
293+
return tester.getTopLeft(finder).dy;
294+
}).toList();
295+
296+
expect(positions[0] > positions[1], isTrue, reason: '"zzz, sleepy" should appear above "zulip" because of reverse');
297+
expect(positions[1] > positions[2], isTrue, reason: '"💤" should appear above "zzz, sleepy" because of reverse');
298+
expect(positions[2] > positions[3], isTrue, reason: '"buzzing" should appear above "💤" because of reverse');
299+
debugNetworkImageHttpClientProvider = null;
300+
301+
});
249302

250303
testWidgets('text emoji means just show text', (tester) async {
251304
final composeInputFinder = await setupToComposeInput(tester);

0 commit comments

Comments
 (0)