From 3df9eac5b7798fe6426a79ccceff9034d1406240 Mon Sep 17 00:00:00 2001 From: Dicha Zelianivan Arkana <51877647+elianiva@users.noreply.github.com> Date: Wed, 23 Apr 2025 14:09:29 +0700 Subject: [PATCH] fix(mention): conditionally remove aftercursor content (#2732) --- webview-ui/src/utils/context-mentions.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/webview-ui/src/utils/context-mentions.ts b/webview-ui/src/utils/context-mentions.ts index 9302598bc0..293aa8f74b 100644 --- a/webview-ui/src/utils/context-mentions.ts +++ b/webview-ui/src/utils/context-mentions.ts @@ -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