Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class ParametrizedStyles(
spannable.removeSpan(span)
}

val start = mentionStart ?: return
val start = mentionStart ?: selectionStart

view.runAsATransaction {
spannable.replace(start, selectionEnd, text)
Expand All @@ -383,6 +383,7 @@ class ParametrizedStyles(

view.mentionHandler?.reset()
view.selection.validateStyles()
mentionStart = null
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify why it's needed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without setting mentionStart to null, the value is never reset. As a result, when a mention is first added by typing @ and then another one is inserted manually via setMention, mentionStart still points to the position of the first typed mention, which is incorrect.

Screen.Recording.2026-05-18.at.10.26.15.mov

}

fun getStyleRange(): Pair<Int, Int> = view.selection?.getInlineSelection() ?: Pair(0, 0)
Expand Down
16 changes: 8 additions & 8 deletions ios/EnrichedTextInputView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1479,15 +1479,15 @@ - (void)addMention:(NSString *)indicator
if (mentionStyleClass == nullptr) {
return;
}
if ([mentionStyleClass getActiveMentionRange] == nullptr) {
return;
}

if ([StyleUtils
handleStyleBlocksAndConflicts:[MentionStyle getType]
range:[[mentionStyleClass
getActiveMentionRange] rangeValue]
forHost:self]) {
NSValue *activeMentionRange = [mentionStyleClass getActiveMentionRange];
NSRange rangeToUse = activeMentionRange != nullptr
? [activeMentionRange rangeValue]
: self.textView.selectedRange;

if ([StyleUtils handleStyleBlocksAndConflicts:[MentionStyle getType]
range:rangeToUse
forHost:self]) {
[mentionStyleClass addMention:indicator text:text attributes:attributes];
[self anyTextMayHaveBeenModified];
}
Expand Down
6 changes: 5 additions & 1 deletion ios/styles/MentionStyle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ - (void)addMention:(NSString *)indicator
text:(NSString *)text
attributes:(NSString *)attributes {
if (_activeMentionRange == nullptr) {
return;
// No draft mention (indicator not typed) - fall back to the current
// selection.
_activeMentionRange =
[NSValue valueWithRange:self.host.textView.selectedRange];
_activeMentionIndicator = indicator;
}

_blockMentionEditing = YES;
Expand Down
Loading