Skip to content

Commit

Permalink
Merge pull request #31435 from graylewis/mentionSearchWithLastName
Browse files Browse the repository at this point in the history
Mention search with last name
  • Loading branch information
techievivek authored Nov 28, 2023
2 parents 61ed900 + 9433f5c commit fcddbee
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/pages/home/report/ReportActionCompose/SuggestionMention.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,24 +199,38 @@ function SuggestionMention({
const leftString = value.substring(0, suggestionEndIndex);
const words = leftString.split(CONST.REGEX.SPACE_OR_EMOJI);
const lastWord = _.last(words);
const secondToLastWord = words[words.length - 3];

let atSignIndex;
let suggestionWord;
let prefix;

// Detect if the last two words contain a mention (two words are needed to detect a mention with a space in it)
if (lastWord.startsWith('@')) {
atSignIndex = leftString.lastIndexOf(lastWord);
}
suggestionWord = lastWord;

prefix = suggestionWord.substring(1);
} else if (secondToLastWord && secondToLastWord.startsWith('@') && secondToLastWord.length > 1) {
atSignIndex = leftString.lastIndexOf(secondToLastWord);
suggestionWord = `${secondToLastWord} ${lastWord}`;

const prefix = lastWord.substring(1);
prefix = suggestionWord.substring(1);
} else {
prefix = lastWord.substring(1);
}

const nextState = {
suggestedMentions: [],
atSignIndex,
mentionPrefix: prefix,
};

const isCursorBeforeTheMention = valueAfterTheCursor.startsWith(lastWord);
const isCursorBeforeTheMention = valueAfterTheCursor.startsWith(suggestionWord);

if (!isCursorBeforeTheMention && isMentionCode(lastWord)) {
if (!isCursorBeforeTheMention && isMentionCode(suggestionWord)) {
const suggestions = getMentionOptions(personalDetails, prefix);

nextState.suggestedMentions = suggestions;
nextState.shouldShowSuggestionMenu = !_.isEmpty(suggestions);
}
Expand Down

0 comments on commit fcddbee

Please sign in to comment.