Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mention search with last name #31435

Merged
merged 11 commits into from
Nov 28, 2023
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 @@ -198,24 +198,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
Loading