Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cursor position when select someone in iOS #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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