Skip to content

Commit

Permalink
Merge pull request Expensify#30930 from abzokhattab/refactoring-menti…
Browse files Browse the repository at this point in the history
…on-replacer-logic

Refactoring mention replacer logic
  • Loading branch information
marcochavezf authored Nov 10, 2023
2 parents 2625721 + 6114b15 commit c94bec8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
5 changes: 0 additions & 5 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1352,11 +1352,6 @@ const CONST = {
return new RegExp(`[\\n\\s]|${this.SPECIAL_CHAR.source}|${this.EMOJI.source}`, 'gu');
},

// Define the regular expression pattern to match a string starting with an at sign and ending with a space or newline character
get MENTION_REPLACER() {
return new RegExp(`^@[^\\n\\r]*?(?=$|\\s|${this.SPECIAL_CHAR.source}|${this.EMOJI.source})`, 'u');
},

MERGED_ACCOUNT_PREFIX: /^(MERGED_\d+@)/,

ROUTES: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ function SuggestionMention({
const commentBeforeAtSign = value.slice(0, suggestionValues.atSignIndex);
const mentionObject = suggestionValues.suggestedMentions[highlightedMentionIndexInner];
const mentionCode = mentionObject.text === CONST.AUTO_COMPLETE_SUGGESTER.HERE_TEXT ? CONST.AUTO_COMPLETE_SUGGESTER.HERE_TEXT : `@${mentionObject.alternateText}`;
const commentAfterAtSignWithMentionRemoved = value.slice(suggestionValues.atSignIndex).replace(CONST.REGEX.MENTION_REPLACER, '');
const commentAfterMention = value.slice(suggestionValues.atSignIndex + suggestionValues.mentionPrefix.length + 1);

updateComment(`${commentBeforeAtSign}${mentionCode} ${SuggestionsUtils.trimLeadingSpace(commentAfterAtSignWithMentionRemoved)}`, true);
updateComment(`${commentBeforeAtSign}${mentionCode} ${SuggestionsUtils.trimLeadingSpace(commentAfterMention)}`, true);
setSelection({
start: suggestionValues.atSignIndex + mentionCode.length + CONST.SPACE_LENGTH,
end: suggestionValues.atSignIndex + mentionCode.length + CONST.SPACE_LENGTH,
Expand All @@ -87,7 +87,7 @@ function SuggestionMention({
suggestedMentions: [],
}));
},
[value, suggestionValues.atSignIndex, suggestionValues.suggestedMentions, updateComment, setSelection],
[value, suggestionValues.atSignIndex, suggestionValues.suggestedMentions, suggestionValues.mentionPrefix, updateComment, setSelection],
);

/**
Expand Down

0 comments on commit c94bec8

Please sign in to comment.