add cid quote insertion logic in ReplyModal

This commit is contained in:
plebeius.eth
2023-06-24 12:38:14 +02:00
parent 91e51f828d
commit 79afa78142
6 changed files with 52 additions and 12 deletions
+17
View File
@@ -14,11 +14,13 @@ const ReplyModal = ({ isOpen, closeModal }) => {
setIsCaptchaOpen,
setPendingComment,
setPendingCommentIndex,
replyQuoteCid,
setResolveCaptchaPromise,
selectedAddress,
selectedParentCid,
selectedShortCid,
selectedStyle,
triggerInsertion,
} = useGeneralStore(state => state);
const account = useAccount();
@@ -53,6 +55,21 @@ const ReplyModal = ({ isOpen, closeModal }) => {
};
const insertAtCursor = (inputElement, valueToInsert) => {
const startPos = inputElement.selectionStart || inputElement.value.length;
const endPos = startPos + valueToInsert.length;
inputElement.setRangeText(valueToInsert, startPos, startPos, 'end');
inputElement.setSelectionRange(endPos, endPos);
}
useEffect(() => {
if (replyQuoteCid && commentRef.current) {
const prefixedReplyQuoteCid = `c/${replyQuoteCid}\n`;
insertAtCursor(commentRef.current, prefixedReplyQuoteCid);
}
}, [triggerInsertion, replyQuoteCid]);
const getSelectedText = useCallback(() => {
const text = document.getSelection().toString();
setSelectedText(text ? `>${text}\n` : '');