fix(mention): conditionally remove aftercursor content (#2732)

This commit is contained in:
Dicha Zelianivan Arkana 2025-04-23 14:09:29 +07:00 committed by GitHub
parent 33ee5d6c34
commit 3df9eac5b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -33,7 +33,12 @@ export function insertMention(
if (lastAtIndex !== -1) {
// If there's an '@' symbol, replace everything after it with the new mention
const beforeMention = text.slice(0, lastAtIndex)
newValue = beforeMention + "@" + value + " " + afterCursor.replace(/^[^\s]*/, "")
// Only replace if afterCursor is all alphanumerical
// This is required to handle languages that don't use space as a word separator (chinese, japanese, korean, etc)
const afterCursorContent = /^[a-zA-Z0-9\s]*$/.test(afterCursor)
? afterCursor.replace(/^[^\s]*/, "")
: afterCursor
newValue = beforeMention + "@" + value + " " + afterCursorContent
mentionIndex = lastAtIndex
} else {
// If there's no '@' symbol, insert the mention at the cursor position