From 6430607363419b695487942ec31ea071f4205912 Mon Sep 17 00:00:00 2001 From: "Tom (plebeius.eth)" Date: Mon, 22 Jul 2024 12:29:05 +0200 Subject: [PATCH] fix(reply modal): cursor would move to end of text while replying --- src/components/reply-modal/reply-modal.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/reply-modal/reply-modal.tsx b/src/components/reply-modal/reply-modal.tsx index b4a1a440..c8842b93 100644 --- a/src/components/reply-modal/reply-modal.tsx +++ b/src/components/reply-modal/reply-modal.tsx @@ -86,11 +86,16 @@ const ReplyModal = ({ closeModal, parentCid, scrollY }: ReplyModalProps) => { if (ref) { textRef.current = ref; !isMobile && ref.focus(); - const len = ref.value.length; - ref.setSelectionRange(len, len); } }; + useEffect(() => { + if (textRef.current) { + const len = textRef.current.value.length; + textRef.current.setSelectionRange(len, len); + } + }, []); + const contentPrefix = `c/${parentCid && Plebbit.getShortCid(parentCid)}\n`; const handleContentInput = (e: React.ChangeEvent) => {