Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions lib/src/mention_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -303,22 +303,37 @@ class FlutterMentionsState extends State<FlutterMentions> {
? widget.mentions.firstWhere(
(element) => selectedMention.str.contains(element.trigger))
: widget.mentions[0];

// find the text by range and replace with the new value.
controller.text = controller.value.text.replaceRange(

final currentText = controller.text.replaceRange(
selectedMention.start,
selectedMention.end,
"${_list.trigger}${value['display']}${widget.appendSpaceOnAdd ? ' ' : ''}",
);

controller.value = TextEditingValue(
text: currentText,
selection: TextSelection.fromPosition(TextPosition(offset: currentText.length))
);

if (widget.onMentionAdd != null) widget.onMentionAdd(value);

//-----------------------------------------------------------------

// Move the cursor to next position after the new mentioned item.
int nextCursorPosition =
selectedMention.start + 1 + value['display']?.length ?? 0;
if (widget.appendSpaceOnAdd) nextCursorPosition++;
controller.selection =
TextSelection.fromPosition(TextPosition(offset: nextCursorPosition));
// find the text by range and replace with the new value.
// controller.text = controller.value.text.replaceRange(
// selectedMention.start,
// selectedMention.end,
// "${_list.trigger}${value['display']}${widget.appendSpaceOnAdd ? ' ' : ''}",
// );

// if (widget.onMentionAdd != null) widget.onMentionAdd(value);

// // Move the cursor to next position after the new mentioned item.
// int nextCursorPosition =
// selectedMention.start + 1 + value['display']?.length ?? 0;
// if (widget.appendSpaceOnAdd) nextCursorPosition++;
// controller.selection =
// TextSelection.fromPosition(TextPosition(offset: nextCursorPosition));
}

void suggestionListerner() {
Expand Down