diff --git a/packages/neon_framework/packages/talk_app/lib/src/widgets/message_input.dart b/packages/neon_framework/packages/talk_app/lib/src/widgets/message_input.dart index 0f16950dd09..1557f7136d4 100644 --- a/packages/neon_framework/packages/talk_app/lib/src/widgets/message_input.dart +++ b/packages/neon_framework/packages/talk_app/lib/src/widgets/message_input.dart @@ -170,12 +170,18 @@ class _TalkMessageInputState extends State { controller: controller, focusNode: focusNode, suggestionsCallback: (_) async { - final cursor = controller.selection.start; - if (controller.text.isEmpty || cursor != controller.selection.end) { + final selection = controller.selection; + if (!selection.isValid) { return []; } - var matchingPart = controller.text.substring(0, cursor); + final cursor = selection.start; + final text = controller.text; + if (text.isEmpty || cursor != selection.end) { + return []; + } + + var matchingPart = text.substring(0, cursor); final index = matchingPart.lastIndexOf(' ') + 1; matchingPart = matchingPart.substring(index); if (!matchingPart.startsWith('@') || matchingPart.isEmpty) {