fix(reply modal): keep textarea empty when opened from Post a Reply footer button

This commit is contained in:
plebeius
2026-02-23 19:33:59 +08:00
parent 0fbb3bef38
commit bb027794ee
2 changed files with 9 additions and 2 deletions
+3 -2
View File
@@ -50,6 +50,7 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, parentNumber, threa
const lastSelectionEndRef = useRef(0); const lastSelectionEndRef = useRef(0);
const lastProcessedQuoteInsertRequestIdRef = useRef(0); const lastProcessedQuoteInsertRequestIdRef = useRef(0);
const { selectedText } = useSelectedTextStore(); const { selectedText } = useSelectedTextStore();
const openEmpty = useReplyModalStore((state) => state.openEmpty);
const quoteInsertRequestId = useReplyModalStore((state) => state.quoteInsertRequestId); const quoteInsertRequestId = useReplyModalStore((state) => state.quoteInsertRequestId);
const quoteInsertNumber = useReplyModalStore((state) => state.quoteInsertNumber); const quoteInsertNumber = useReplyModalStore((state) => state.quoteInsertNumber);
const quoteInsertSelectedText = useReplyModalStore((state) => state.quoteInsertSelectedText); const quoteInsertSelectedText = useReplyModalStore((state) => state.quoteInsertSelectedText);
@@ -195,7 +196,7 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, parentNumber, threa
useEffect(() => { useEffect(() => {
if (showReplyModal && textRef.current) { if (showReplyModal && textRef.current) {
textRef.current.spellcheck = false; textRef.current.spellcheck = false;
textRef.current.value = `${defaultParentQuote}${selectedText || ''}`; textRef.current.value = openEmpty ? selectedText || '' : `${defaultParentQuote}${selectedText || ''}`;
const len = textRef.current.value.length; const len = textRef.current.value.length;
lastSelectionStartRef.current = len; lastSelectionStartRef.current = len;
lastSelectionEndRef.current = len; lastSelectionEndRef.current = len;
@@ -209,7 +210,7 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, parentNumber, threa
} }
}, 100); }, 100);
} }
}, [showReplyModal, defaultParentQuote, selectedText]); }, [showReplyModal, openEmpty, defaultParentQuote, selectedText]);
const handleContentInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => { const handleContentInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
lastSelectionStartRef.current = e.target.selectionStart ?? e.target.value.length; lastSelectionStartRef.current = e.target.selectionStart ?? e.target.value.length;
+6
View File
@@ -3,6 +3,8 @@ import useSelectedTextStore from './use-selected-text-store';
interface ReplyModalState { interface ReplyModalState {
showReplyModal: boolean; showReplyModal: boolean;
/** True when opened via "Post a Reply" footer button — textarea should be empty, no quote. */
openEmpty: boolean;
activeCid: string | null; activeCid: string | null;
parentNumber: number | null; parentNumber: number | null;
threadNumber: number | null; threadNumber: number | null;
@@ -35,6 +37,7 @@ const getQuotedSelection = () => {
const useReplyModalStore = create<ReplyModalState>((set, get) => ({ const useReplyModalStore = create<ReplyModalState>((set, get) => ({
showReplyModal: false, showReplyModal: false,
openEmpty: false,
activeCid: null, activeCid: null,
parentNumber: null, parentNumber: null,
threadNumber: null, threadNumber: null,
@@ -50,6 +53,7 @@ const useReplyModalStore = create<ReplyModalState>((set, get) => ({
useSelectedTextStore.getState().resetSelectedText(); useSelectedTextStore.getState().resetSelectedText();
set({ set({
showReplyModal: false, showReplyModal: false,
openEmpty: false,
activeCid: null, activeCid: null,
parentNumber: null, parentNumber: null,
threadNumber: null, threadNumber: null,
@@ -80,6 +84,7 @@ const useReplyModalStore = create<ReplyModalState>((set, get) => ({
const scrollY = isMobile ? window.scrollY : 0; const scrollY = isMobile ? window.scrollY : 0;
set({ set({
openEmpty: false,
activeCid: postCid, activeCid: postCid,
parentNumber: parentNumber ?? null, parentNumber: parentNumber ?? null,
threadNumber: threadNumber ?? null, threadNumber: threadNumber ?? null,
@@ -95,6 +100,7 @@ const useReplyModalStore = create<ReplyModalState>((set, get) => ({
const isMobile = window.innerWidth <= 768; const isMobile = window.innerWidth <= 768;
const scrollY = isMobile ? window.scrollY : 0; const scrollY = isMobile ? window.scrollY : 0;
set({ set({
openEmpty: true,
activeCid: postCid, activeCid: postCid,
parentNumber: null, parentNumber: null,
threadNumber: threadNumber ?? null, threadNumber: threadNumber ?? null,