Browse Source

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

Dicha Zelianivan Arkana 10 months ago
parent
commit
3df9eac5b7
1 changed files with 6 additions and 1 deletions
  1. 6 1
      webview-ui/src/utils/context-mentions.ts

+ 6 - 1
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