Skip to content

Commit 74bdc7e

Browse files
fix: setting mention without indicator typed (#606)
# Summary This PR fixes: #601 ## Test Plan Run reproduction steps from #601, the issue should be resolved ## Screenshots / Videos https://github.com/user-attachments/assets/9bc1f5f4-028a-4d39-9a6f-18fdf6bd7aca ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | Android | ✅ | ## Checklist - [x] E2E tests are passing - [ ] Required E2E tests have been added (if applicable)
1 parent 7957c7a commit 74bdc7e

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

android/src/main/java/com/swmansion/enriched/textinput/styles/ParametrizedStyles.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class ParametrizedStyles(
365365
spannable.removeSpan(span)
366366
}
367367

368-
val start = mentionStart ?: return
368+
val start = mentionStart ?: selectionStart
369369

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

384384
view.mentionHandler?.reset()
385385
view.selection.validateStyles()
386+
mentionStart = null
386387
}
387388

388389
fun getStyleRange(): Pair<Int, Int> = view.selection?.getInlineSelection() ?: Pair(0, 0)

ios/EnrichedTextInputView.mm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,15 +1519,15 @@ - (void)addMention:(NSString *)indicator
15191519
if (mentionStyleClass == nullptr) {
15201520
return;
15211521
}
1522-
if ([mentionStyleClass getActiveMentionRange] == nullptr) {
1523-
return;
1524-
}
15251522

1526-
if ([StyleUtils
1527-
handleStyleBlocksAndConflicts:[MentionStyle getType]
1528-
range:[[mentionStyleClass
1529-
getActiveMentionRange] rangeValue]
1530-
forHost:self]) {
1523+
NSValue *activeMentionRange = [mentionStyleClass getActiveMentionRange];
1524+
NSRange rangeToUse = activeMentionRange != nullptr
1525+
? [activeMentionRange rangeValue]
1526+
: self.textView.selectedRange;
1527+
1528+
if ([StyleUtils handleStyleBlocksAndConflicts:[MentionStyle getType]
1529+
range:rangeToUse
1530+
forHost:self]) {
15311531
[mentionStyleClass addMention:indicator text:text attributes:attributes];
15321532
[self anyTextMayHaveBeenModified];
15331533
}

ios/styles/MentionStyle.mm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ - (void)addMention:(NSString *)indicator
142142
text:(NSString *)text
143143
attributes:(NSString *)attributes {
144144
if (_activeMentionRange == nullptr) {
145-
return;
145+
// No draft mention (indicator not typed) - fall back to the current
146+
// selection.
147+
_activeMentionRange =
148+
[NSValue valueWithRange:self.host.textView.selectedRange];
149+
_activeMentionIndicator = indicator;
146150
}
147151

148152
_blockMentionEditing = YES;

0 commit comments

Comments
 (0)