From 37ecd4a0bc5ebd525ea3412fbe8c0848db290511 Mon Sep 17 00:00:00 2001 From: hjlarry Date: Sat, 4 Oct 2025 13:39:00 +0800 Subject: [PATCH] fix @ input problem --- web/app/components/workflow/comment/mention-input.tsx | 8 ++++++-- web/app/components/workflow/comment/thread.tsx | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/web/app/components/workflow/comment/mention-input.tsx b/web/app/components/workflow/comment/mention-input.tsx index 8fa43d47a9..8f775b46cf 100644 --- a/web/app/components/workflow/comment/mention-input.tsx +++ b/web/app/components/workflow/comment/mention-input.tsx @@ -223,7 +223,10 @@ export const MentionInput: FC = 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 = 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) diff --git a/web/app/components/workflow/comment/thread.tsx b/web/app/components/workflow/comment/thread.tsx index 2295eecac9..e20a649664 100644 --- a/web/app/components/workflow/comment/thread.tsx +++ b/web/app/components/workflow/comment/thread.tsx @@ -377,7 +377,6 @@ export const CommentThread: FC = memo(({ placeholder={t('workflow.comments.placeholder.reply')} disabled={loading} loading={loading} - className='px-2' />