fix @ input problem

This commit is contained in:
hjlarry 2025-10-04 13:39:00 +08:00
parent 827a1b181b
commit 37ecd4a0bc
2 changed files with 6 additions and 3 deletions

View File

@ -223,7 +223,10 @@ export const MentionInput: FC<MentionInputProps> = memo(({
const beforeMention = value.slice(0, mentionPosition)
const afterMention = value.slice(textarea.selectionStart || 0)
const newContent = `${beforeMention}@${user.name} ${afterMention}`
const needsSpaceBefore = mentionPosition > 0 && !/\s/.test(value[mentionPosition - 1])
const prefix = needsSpaceBefore ? ' ' : ''
const newContent = `${beforeMention}${prefix}@${user.name} ${afterMention}`
onChange(newContent)
setShowMentionDropdown(false)
@ -232,7 +235,8 @@ export const MentionInput: FC<MentionInputProps> = memo(({
setMentionedUserIds(newMentionedUserIds)
setTimeout(() => {
const newCursorPos = mentionPosition + user.name.length + 2 // @ + name + space
const extraSpace = needsSpaceBefore ? 1 : 0
const newCursorPos = mentionPosition + extraSpace + user.name.length + 2 // (space) + @ + name + space
textarea.setSelectionRange(newCursorPos, newCursorPos)
textarea.focus()
}, 0)

View File

@ -377,7 +377,6 @@ export const CommentThread: FC<CommentThreadProps> = memo(({
placeholder={t('workflow.comments.placeholder.reply')}
disabled={loading}
loading={loading}
className='px-2'
/>
</div>
</div>