fix(reply modal): restore multiline quote insertion

This commit is contained in:
plebeius
2026-02-10 15:51:58 +08:00
parent 8a192b41b4
commit db70a9148b
2 changed files with 35 additions and 7 deletions
+23 -4
View File
@@ -11,10 +11,26 @@ interface ReplyModalState {
scrollY: number;
quoteInsertRequestId: number;
quoteInsertNumber: number | null;
quoteInsertSelectedText: string | null;
closeModal: () => void;
openReplyModal: (parentCid: string, parentNumber: number | undefined, postCid: string, threadNumber: number | undefined, subplebbitAddress: string) => void;
}
const getQuotedSelection = () => {
const text = document.getSelection()?.toString();
if (!text) return '';
// Keep each selected line as 5chan greentext and normalize newlines.
const normalizedText = text.replace(/\r\n/g, '\n').replace(/\n+$/g, '');
if (!normalizedText) return '';
return normalizedText
.split('\n')
.map((line) => `>${line}`)
.join('\n');
};
const useReplyModalStore = create<ReplyModalState>((set, get) => ({
showReplyModal: false,
activeCid: null,
@@ -25,6 +41,7 @@ const useReplyModalStore = create<ReplyModalState>((set, get) => ({
scrollY: 0,
quoteInsertRequestId: 0,
quoteInsertNumber: null,
quoteInsertSelectedText: null,
closeModal: () => {
// Reset selected text if you're using that store
@@ -35,23 +52,25 @@ const useReplyModalStore = create<ReplyModalState>((set, get) => ({
parentNumber: null,
threadNumber: null,
quoteInsertNumber: null,
quoteInsertSelectedText: null,
});
},
openReplyModal: (parentCid, parentNumber, postCid, threadNumber, subplebbitAddress) => {
const quotedSelection = getQuotedSelection();
// If the reply modal is already open, insert this quote in the current textarea at caret.
if (get().showReplyModal) {
set((state) => ({
quoteInsertRequestId: state.quoteInsertRequestId + 1,
quoteInsertNumber: parentNumber ?? null,
quoteInsertSelectedText: quotedSelection || null,
}));
return;
}
// Get selected text
const text = document.getSelection()?.toString();
if (text) {
useSelectedTextStore.getState().setSelectedText(`>${text}\n`);
if (quotedSelection) {
useSelectedTextStore.getState().setSelectedText(`${quotedSelection}\n`);
}
// Handle mobile scrollY