diff --git a/web/app/components/workflow/comment/mention-input.tsx b/web/app/components/workflow/comment/mention-input.tsx index 0f9aa1d5a8..4c8e9e079d 100644 --- a/web/app/components/workflow/comment/mention-input.tsx +++ b/web/app/components/workflow/comment/mention-input.tsx @@ -277,6 +277,19 @@ export const MentionInput: FC = memo(({ ) }, [mentionUsers, mentionQuery]) + const shouldDisableMentionButton = useMemo(() => { + if (showMentionDropdown) + return true + + const textarea = textareaRef.current + if (!textarea) + return false + + const cursorPosition = textarea.selectionStart || 0 + const textBeforeCursor = value.slice(0, cursorPosition) + return /@\w*$/.test(textBeforeCursor) + }, [showMentionDropdown, value]) + const dropdownPosition = useMemo(() => { if (!showMentionDropdown || !textareaRef.current) return { x: 0, y: 0, placement: 'bottom' as const } @@ -328,9 +341,20 @@ export const MentionInput: FC = memo(({ e.stopPropagation() const textarea = textareaRef.current - if (!textarea) return + if (!textarea) + return const cursorPosition = textarea.selectionStart || 0 + const textBeforeCursor = value.slice(0, cursorPosition) + + // 🔒 如果已经在 mention 模式,不插入新的 @ + if (showMentionDropdown) + return + + // 🔒 如果光标前已有未完成的 @,不插入新的 @ + if (/@\w*$/.test(textBeforeCursor)) + return + const newContent = `${value.slice(0, cursorPosition)}@${value.slice(cursorPosition)}` onChange(newContent) @@ -352,7 +376,7 @@ export const MentionInput: FC = memo(({ }) } }, 0) - }, [value, onChange, evaluateContentLayout, syncHighlightScroll]) + }, [value, onChange, evaluateContentLayout, syncHighlightScroll, showMentionDropdown]) const insertMention = useCallback((user: UserProfile) => { const textarea = textareaRef.current @@ -500,8 +524,13 @@ export const MentionInput: FC = memo(({ className="absolute bottom-0 right-1 z-20 flex items-end gap-1" >
@@ -522,8 +551,13 @@ export const MentionInput: FC = memo(({ className="absolute bottom-0 left-1 right-1 z-20 flex items-end justify-between" >