From 291ca7a139d71302a570e535a9355b7e9c324c71 Mon Sep 17 00:00:00 2001 From: Satoshi Nakamoto Date: Wed, 27 Sep 2023 15:48:36 -0400 Subject: [PATCH] quote selected text if any, otherwise quote whole item --- components/action-dropdown.js | 2 +- components/reply.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/components/action-dropdown.js b/components/action-dropdown.js index b922967d1f..497f150d02 100644 --- a/components/action-dropdown.js +++ b/components/action-dropdown.js @@ -8,7 +8,7 @@ export default function ActionDropdown ({ children }) { } return ( - + e.preventDefault()}> diff --git a/components/reply.js b/components/reply.js index 89a862b63c..54db9b9d32 100644 --- a/components/reply.js +++ b/components/reply.js @@ -45,12 +45,14 @@ export default forwardRef(function Reply ({ item, onSuccess, replyOpen, children if (!reply) { setReply(true) } + const selection = window.getSelection() + const textToQuote = selection.isCollapsed ? item.text : selection.toString() let updatedValue if (formInnerRef.current && formInnerRef.current.values && !formInnerRef.current.values.text) { - updatedValue = quote(item.text) + updatedValue = quote(textToQuote) } else if (formInnerRef.current?.values?.text) { // append quote reply text if the input already has content - updatedValue = `${replyInput.current.value}\n${quote(item.text)}` + updatedValue = `${replyInput.current.value}\n${quote(textToQuote)}` } if (updatedValue) { replyInput.current.value = updatedValue