From bb027794ee0dea00f553660bd6f6279b14165409 Mon Sep 17 00:00:00 2001 From: plebeius Date: Mon, 23 Feb 2026 19:33:59 +0800 Subject: [PATCH] fix(reply modal): keep textarea empty when opened from Post a Reply footer button --- src/components/reply-modal/reply-modal.tsx | 5 +++-- src/stores/use-reply-modal-store.ts | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/reply-modal/reply-modal.tsx b/src/components/reply-modal/reply-modal.tsx index c91e1309..3b60137f 100644 --- a/src/components/reply-modal/reply-modal.tsx +++ b/src/components/reply-modal/reply-modal.tsx @@ -50,6 +50,7 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, parentNumber, threa const lastSelectionEndRef = useRef(0); const lastProcessedQuoteInsertRequestIdRef = useRef(0); const { selectedText } = useSelectedTextStore(); + const openEmpty = useReplyModalStore((state) => state.openEmpty); const quoteInsertRequestId = useReplyModalStore((state) => state.quoteInsertRequestId); const quoteInsertNumber = useReplyModalStore((state) => state.quoteInsertNumber); const quoteInsertSelectedText = useReplyModalStore((state) => state.quoteInsertSelectedText); @@ -195,7 +196,7 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, parentNumber, threa useEffect(() => { if (showReplyModal && textRef.current) { textRef.current.spellcheck = false; - textRef.current.value = `${defaultParentQuote}${selectedText || ''}`; + textRef.current.value = openEmpty ? selectedText || '' : `${defaultParentQuote}${selectedText || ''}`; const len = textRef.current.value.length; lastSelectionStartRef.current = len; lastSelectionEndRef.current = len; @@ -209,7 +210,7 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, parentNumber, threa } }, 100); } - }, [showReplyModal, defaultParentQuote, selectedText]); + }, [showReplyModal, openEmpty, defaultParentQuote, selectedText]); const handleContentInput = (e: React.ChangeEvent) => { lastSelectionStartRef.current = e.target.selectionStart ?? e.target.value.length; diff --git a/src/stores/use-reply-modal-store.ts b/src/stores/use-reply-modal-store.ts index 1eb9b1b2..e810adcc 100644 --- a/src/stores/use-reply-modal-store.ts +++ b/src/stores/use-reply-modal-store.ts @@ -3,6 +3,8 @@ import useSelectedTextStore from './use-selected-text-store'; interface ReplyModalState { showReplyModal: boolean; + /** True when opened via "Post a Reply" footer button — textarea should be empty, no quote. */ + openEmpty: boolean; activeCid: string | null; parentNumber: number | null; threadNumber: number | null; @@ -35,6 +37,7 @@ const getQuotedSelection = () => { const useReplyModalStore = create((set, get) => ({ showReplyModal: false, + openEmpty: false, activeCid: null, parentNumber: null, threadNumber: null, @@ -50,6 +53,7 @@ const useReplyModalStore = create((set, get) => ({ useSelectedTextStore.getState().resetSelectedText(); set({ showReplyModal: false, + openEmpty: false, activeCid: null, parentNumber: null, threadNumber: null, @@ -80,6 +84,7 @@ const useReplyModalStore = create((set, get) => ({ const scrollY = isMobile ? window.scrollY : 0; set({ + openEmpty: false, activeCid: postCid, parentNumber: parentNumber ?? null, threadNumber: threadNumber ?? null, @@ -95,6 +100,7 @@ const useReplyModalStore = create((set, get) => ({ const isMobile = window.innerWidth <= 768; const scrollY = isMobile ? window.scrollY : 0; set({ + openEmpty: true, activeCid: postCid, parentNumber: null, threadNumber: threadNumber ?? null,