Skip to content

Commit 5059636

Browse files
elianivacte
authored andcommitted
fix(mention): conditionally remove aftercursor content (#2732)
1 parent 4563b53 commit 5059636

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

webview-ui/src/utils/context-mentions.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ export function insertMention(
3333
if (lastAtIndex !== -1) {
3434
// If there's an '@' symbol, replace everything after it with the new mention
3535
const beforeMention = text.slice(0, lastAtIndex)
36-
newValue = beforeMention + "@" + value + " " + afterCursor.replace(/^[^\s]*/, "")
36+
// Only replace if afterCursor is all alphanumerical
37+
// This is required to handle languages that don't use space as a word separator (chinese, japanese, korean, etc)
38+
const afterCursorContent = /^[a-zA-Z0-9\s]*$/.test(afterCursor)
39+
? afterCursor.replace(/^[^\s]*/, "")
40+
: afterCursor
41+
newValue = beforeMention + "@" + value + " " + afterCursorContent
3742
mentionIndex = lastAtIndex
3843
} else {
3944
// If there's no '@' symbol, insert the mention at the cursor position

0 commit comments

Comments
 (0)