File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -158,9 +158,25 @@ - (void)addMention:(NSString *)indicator
158158 params.indicator = indicator;
159159 params.attributes = attributes;
160160
161- // add a single space after the mention
162- NSString *newText = [NSString stringWithFormat: @" %@ " , text];
163161 NSRange rangeToBeReplaced = [_activeMentionRange rangeValue ];
162+
163+ // add a single space after the mention if there isn't one already
164+ BOOL hasSpaceAfter = NO ;
165+ NSUInteger nextCharIndex =
166+ rangeToBeReplaced.location + rangeToBeReplaced.length ;
167+
168+ if (nextCharIndex < self.host .textView .textStorage .string .length ) {
169+ unichar nextChar =
170+ [self .host.textView.textStorage.string characterAtIndex: nextCharIndex];
171+ if ([[NSCharacterSet whitespaceAndNewlineCharacterSet ]
172+ characterIsMember: nextChar]) {
173+ hasSpaceAfter = YES ;
174+ }
175+ }
176+
177+ NSString *newText =
178+ hasSpaceAfter ? text : [NSString stringWithFormat: @" %@ " , text];
179+
164180 [TextInsertionUtils replaceText: newText
165181 at: rangeToBeReplaced
166182 additionalAttributes: nullptr
You can’t perform that action at this time.
0 commit comments