Skip to content

Commit 134338c

Browse files
committed
fix: auto-insert space before @mentions when needed
- Auto-insert space before @ when dragging/dropping files after text - Auto-insert space before @ when using mention insertion after text - Maintains regex restriction from PR #7876 to prevent parsing in pasted logs - Added comprehensive tests for the new behavior Fixes #8063
1 parent dcc6db0 commit 134338c

File tree

3 files changed

+192
-517
lines changed

3 files changed

+192
-517
lines changed

webview-ui/src/components/chat/ChatTextArea.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,15 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
790790
let newValue = inputValue.slice(0, cursorPosition)
791791
let totalLength = 0
792792

793+
// Check if we need to add a space before the first mention
794+
const textBefore = inputValue.slice(0, cursorPosition)
795+
const needsSpaceBefore =
796+
textBefore.length > 0 && !textBefore.endsWith(" ") && !textBefore.endsWith("\n")
797+
if (needsSpaceBefore) {
798+
newValue += " "
799+
totalLength += 1
800+
}
801+
793802
// Using a standard for loop instead of forEach for potential performance gains.
794803
for (let i = 0; i < lines.length; i++) {
795804
const line = lines[i]

0 commit comments

Comments
 (0)