-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: auto-insert space before @mentions when needed #8064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -58,19 +58,28 @@ export function insertMention( | |||||||
| let mentionIndex: number | ||||||||
|
|
||||||||
| if (lastAtIndex !== -1) { | ||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical issue: This logic replaces everything after the FIRST @ found in the text, which causes data loss when multiple mentions exist. For example, if the text is "Check @/file1.txt and @" and we're inserting a new mention at the second @, this will replace from the first @ instead. Consider finding the @ that's actually at or near the cursor position instead of using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Active mention detection: this replaces starting at the last "@" before the cursor even if the caret is no longer inside that mention token. If the user already typed a complete mention earlier and the cursor is elsewhere, selecting a new item can overwrite the earlier mention. Replace only when there is no whitespace between the last "@" and the cursor; otherwise insert a new mention.
Suggested change
Fix it with Roo Code or mention @roomote and request a fix. |
||||||||
| // If there's an '@' symbol, replace everything after it with the new mention | ||||||||
| const beforeMention = text.slice(0, lastAtIndex) | ||||||||
| // If there's an '@' symbol, check if we need to add a space before it | ||||||||
| const beforeAt = text.slice(0, lastAtIndex) | ||||||||
| const needsSpaceBefore = beforeAt.length > 0 && !beforeAt.endsWith(" ") && !beforeAt.endsWith("\n") | ||||||||
|
|
||||||||
| // If we need a space before @, add it | ||||||||
| const beforeMention = needsSpaceBefore ? beforeAt + " " : beforeAt | ||||||||
|
|
||||||||
| // 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 + "@" + processedValue + " " + afterCursorContent | ||||||||
| mentionIndex = lastAtIndex | ||||||||
| mentionIndex = needsSpaceBefore ? lastAtIndex + 1 : lastAtIndex | ||||||||
| } else { | ||||||||
| // If there's no '@' symbol, insert the mention at the cursor position | ||||||||
| newValue = beforeCursor + "@" + processedValue + " " + afterCursor | ||||||||
| mentionIndex = position | ||||||||
| // Check if we need to add a space before the mention | ||||||||
| const needsSpaceBefore = beforeCursor.length > 0 && !beforeCursor.endsWith(" ") && !beforeCursor.endsWith("\n") | ||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor suggestion: The space-checking logic (checking for trailing space or newline) is repeated here and at line 63. Consider extracting this into a small utility function like |
||||||||
| const prefix = needsSpaceBefore ? " " : "" | ||||||||
|
|
||||||||
| newValue = beforeCursor + prefix + "@" + processedValue + " " + afterCursor | ||||||||
| mentionIndex = position + (needsSpaceBefore ? 1 : 0) | ||||||||
| } | ||||||||
|
|
||||||||
| return { newValue, mentionIndex } | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This space-checking logic is duplicated in the
insertMentionfunction. SinceinsertMentionalready handles adding space before @mentions, do we need this logic here as well?Consider whether both places need this or if it should be centralized in one location to avoid potential inconsistencies.