fix(Input): fix mention formation on rewriting a mention

Fixes #2325
This commit is contained in:
Jonathan Rainville 2021-05-05 13:54:35 -04:00 committed by Iuri Matias
parent 521d2372f3
commit d2b6bf9310
1 changed files with 14 additions and 5 deletions

View File

@ -564,18 +564,27 @@ Rectangle {
let nameLen = aliasName.length + 2 // We're doing a +2 here because of the `@` and the trailing whitespace
let position = 0;
let text = ""
let cursorPositionMention = 0
const spanPlusAlias = `${Constants.mentionSpanTag}@${aliasName}</span> `
if (currentText === "@") {
position = nameLen
text = spanPlusAlias
} else {
let left = currentText.substring(0, lastAtPosition)
// If there is an odd number of mentions, it means we are rewritting an old mention
let matches = left.match(/[[mention]]/g)
if (!!matches && matches.length % 2 === 1) {
let index = left.lastIndexOf('[[mention]]')
left = left.substring(0, index)
cursorPositionMention = lastAtPosition - index
}
let right = currentText.substring(hasEmoji ? lastCursorPosition + 2 : lastCursorPosition)
text = `${left} ${spanPlusAlias}${right}`
}
messageInputField.text = parseBackText(text)
messageInputField.cursorPosition = lastAtPosition + aliasName.length + 2
messageInputField.cursorPosition = lastAtPosition + aliasName.length + 2 - cursorPositionMention
if (messageInputField.cursorPosition === 0) {
// It reset to 0 for some reason, go back to the end
messageInputField.cursorPosition = messageInputField.length