From 34cb22fa88705c834e1582db4324d66bcd1955b5 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Fri, 8 Nov 2024 19:09:27 +0100 Subject: [PATCH] fix(talk_app): Ignore invalid text selection when searching mentions Signed-off-by: provokateurin --- .../talk_app/lib/src/widgets/message_input.dart | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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 58817eaad6f..34cff42d209 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) {