mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-21 18:55:16 +02:00
feat(web): add initialText prop to InlineMentionEditor
This commit is contained in:
parent
275fa86ecd
commit
5ab534511c
1 changed files with 12 additions and 0 deletions
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue