fix(#238): Enter selects the highlighted emoji/mention in autocomplete
The autocomplete only completed an unambiguous emoji on Enter; ambiguous queries (e.g. `:shrug` with multiple matches) sent the literal text instead of the highlighted glyph, and mentions only selected via Tab. Enter now accepts the highlighted item (emoji or mention) like Tab, then sends; Tab still selects without sending, Esc dismisses to send literal text. Removes the now-dead _emojiQuery field. (#231, emoji + mentions per Ben) Widget tests: Enter inserts the highlighted emoji (ambiguous `:shr`) and the highlighted mention (`@Bo` -> @[Bob]). Part of #231. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>pull/241/head
parent
d39893f120
commit
ad29ea3f0e
@ -0,0 +1,90 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/widgets/mention_autocomplete.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Enter inserts the highlighted emoji, not literal text (#231)', (
|
||||
tester,
|
||||
) async {
|
||||
final controller = TextEditingController();
|
||||
final focusNode = FocusNode();
|
||||
addTearDown(() {
|
||||
controller.dispose();
|
||||
focusNode.dispose();
|
||||
});
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: MentionAutocompleteField(
|
||||
maxBytes: 200,
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
// Ambiguous query: ':shr' matches both, so the pre-#231 code would
|
||||
// have sent the literal ':shr' instead of the highlighted glyph.
|
||||
emojiShortcodes: const {
|
||||
'shrug': '\u{1F937}',
|
||||
'shrimp': '\u{1F990}',
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
focusNode.requestFocus();
|
||||
await tester.pump();
|
||||
|
||||
controller.value = const TextEditingValue(
|
||||
text: ':shr',
|
||||
selection: TextSelection.collapsed(offset: 4),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.pump();
|
||||
|
||||
expect(controller.text.contains(':shr'), isFalse);
|
||||
expect(
|
||||
controller.text.contains('\u{1F937}') ||
|
||||
controller.text.contains('\u{1F990}'),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Enter inserts the highlighted mention (#231)', (tester) async {
|
||||
final controller = TextEditingController();
|
||||
final focusNode = FocusNode();
|
||||
addTearDown(() {
|
||||
controller.dispose();
|
||||
focusNode.dispose();
|
||||
});
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: MentionAutocompleteField(
|
||||
maxBytes: 200,
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
candidates: const [MentionCandidate(name: 'Bob', recent: false)],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
focusNode.requestFocus();
|
||||
await tester.pump();
|
||||
|
||||
controller.value = const TextEditingValue(
|
||||
text: '@Bo',
|
||||
selection: TextSelection.collapsed(offset: 3),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.pump();
|
||||
|
||||
expect(controller.text, contains('@[Bob]'));
|
||||
});
|
||||
}
|
||||
Loading…
Reference in new issue