feat(web): add initialText prop to InlineMentionEditor

This commit is contained in:
CREDO23 2026-03-20 20:26:33 +02:00
parent 275fa86ecd
commit 5ab534511c

View file

@ -47,6 +47,7 @@ interface InlineMentionEditorProps {
disabled?: boolean; disabled?: boolean;
className?: string; className?: string;
initialDocuments?: MentionedDocument[]; initialDocuments?: MentionedDocument[];
initialText?: string;
} }
// Unique data attribute to identify chip elements // Unique data attribute to identify chip elements
@ -96,6 +97,7 @@ export const InlineMentionEditor = forwardRef<InlineMentionEditorRef, InlineMent
disabled = false, disabled = false,
className, className,
initialDocuments = [], initialDocuments = [],
initialText,
}, },
ref ref
) => { ) => {
@ -115,6 +117,16 @@ export const InlineMentionEditor = forwardRef<InlineMentionEditorRef, InlineMent
} }
}, [initialDocuments]); }, [initialDocuments]);
// Seed editor with initialText on mount (e.g. clipboard content from Electron tray)
const initialTextAppliedRef = useRef(false);
useEffect(() => {
if (!initialText || initialTextAppliedRef.current || !editorRef.current) return;
initialTextAppliedRef.current = true;
editorRef.current.textContent = initialText;
setIsEmpty(false);
onChange?.(initialText, Array.from(mentionedDocs.values()));
}, [initialText]); // eslint-disable-line react-hooks/exhaustive-deps
// Focus at the end of the editor // Focus at the end of the editor
const focusAtEnd = useCallback(() => { const focusAtEnd = useCallback(() => {
if (!editorRef.current) return; if (!editorRef.current) return;