From d9833eb8195d1050d4b7da197b984e7b7babe742 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 27 Feb 2024 21:33:53 +0700 Subject: [PATCH] fix: logic get sign index suggestion mention --- .../home/report/ReportActionCompose/SuggestionMention.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/SuggestionMention.js b/src/pages/home/report/ReportActionCompose/SuggestionMention.js index 6bdea2cb4a27..6345ebf89185 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionMention.js +++ b/src/pages/home/report/ReportActionCompose/SuggestionMention.js @@ -203,8 +203,8 @@ function SuggestionMention({ suggestionEndIndex = indexOfFirstSpecialCharOrEmojiAfterTheCursor + selectionEnd; } - const newLineIndex = value.lastIndexOf('\n', selectionEnd - 1); - const leftString = value.substring(newLineIndex + 1, suggestionEndIndex); + const afterLastBreakLineIndex = value.lastIndexOf('\n', selectionEnd - 1) + 1; + const leftString = value.substring(afterLastBreakLineIndex, suggestionEndIndex); const words = leftString.split(CONST.REGEX.SPACE_OR_EMOJI); const lastWord = _.last(words); const secondToLastWord = words[words.length - 3]; @@ -215,12 +215,12 @@ function SuggestionMention({ // 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); + atSignIndex = leftString.lastIndexOf(lastWord) + afterLastBreakLineIndex; suggestionWord = lastWord; prefix = suggestionWord.substring(1); } else if (secondToLastWord && secondToLastWord.startsWith('@') && secondToLastWord.length > 1) { - atSignIndex = leftString.lastIndexOf(secondToLastWord); + atSignIndex = leftString.lastIndexOf(secondToLastWord) + afterLastBreakLineIndex; suggestionWord = `${secondToLastWord} ${lastWord}`; prefix = suggestionWord.substring(1);