From 41511f08586f5603dd8f3eafa98b6f0d8b9a791c Mon Sep 17 00:00:00 2001 From: Abhijay Jain Date: Mon, 28 Sep 2026 01:35:16 +0000 Subject: [PATCH] feat: add quoting action to append selected conversation text to composer (#12536) --- ui/desktop/src/components/BaseChat.tsx | 50 +++++++++++++++++++++++++ ui/desktop/src/components/ChatInput.tsx | 15 ++++++++ 2 files changed, 65 insertions(+) diff --git a/ui/desktop/src/components/BaseChat.tsx b/ui/desktop/src/components/BaseChat.tsx index ce93cb046..cbfa188fa 100644 --- a/ui/desktop/src/components/BaseChat.tsx +++ b/ui/desktop/src/components/BaseChat.tsx @@ -125,6 +125,33 @@ export default function BaseChat({ const { droppedFiles, setDroppedFiles, handleDrop, handleDragOver } = useFileDrop(); const onStreamFinish = useCallback(() => {}, []); + const [pendingQuote, setPendingQuote] = useState(null); + const [quoteButtonPos, setQuoteButtonPos] = useState<{ x: number; y: number } | null>(null); + const conversationRef = useRef(null); + + useEffect(() => { + const handleMouseUp = () => { + const sel = window.getSelection(); + if (!sel || sel.isCollapsed || !sel.toString().trim()) { + setQuoteButtonPos(null); + return; + } + if ( + !conversationRef.current || + !conversationRef.current.contains(sel.anchorNode) + ) { + setQuoteButtonPos(null); + return; + } + const range = sel.getRangeAt(0); + const rect = range.getBoundingClientRect(); + setQuoteButtonPos({ x: rect.left + rect.width / 2, y: rect.top - 8 }); + }; + + document.addEventListener('mouseup', handleMouseUp); + return () => document.removeEventListener('mouseup', handleMouseUp); + }, []); + useEffect(() => subscribeToAcpRecovery(setAcpRecovering), []); const { @@ -521,6 +548,7 @@ export default function BaseChat({ {messages.length > 0 || recipe ? ( <> +
+
@@ -552,6 +581,25 @@ export default function BaseChat({
)} + {quoteButtonPos && ( + + )} + setPendingQuote(null)} {...customChatInputProps} /> diff --git a/ui/desktop/src/components/ChatInput.tsx b/ui/desktop/src/components/ChatInput.tsx index ca9c95bb8..ea9c73eba 100644 --- a/ui/desktop/src/components/ChatInput.tsx +++ b/ui/desktop/src/components/ChatInput.tsx @@ -212,6 +212,8 @@ interface ChatInputProps { nextChatExtensionDraft?: NextChatExtensionDraft; onNextChatExtensionDraftChange?: (draft: NextChatExtensionDraft) => void; liveVoice?: ChatInputLiveVoice; + appendQuote?: string | null; + onAppendQuoteConsumed?: () => void; } export default function ChatInput({ @@ -250,6 +252,8 @@ export default function ChatInput({ nextChatExtensionDraft, onNextChatExtensionDraftChange, liveVoice, + appendQuote, + onAppendQuoteConsumed, }: ChatInputProps) { const [_value, setValue] = useState(initialValue); const [displayValue, setDisplayValue] = useState(initialValue); // For immediate visual feedback @@ -578,6 +582,17 @@ export default function ChatInput({ } }, [initialPrompt, messages.length, textAreaRef]); + useEffect(() => { + if (!appendQuote) return; + const blockquote = appendQuote + .split('\n') + .map((line) => `> ${line}`) + .join('\n'); + applyInputValue((_value ? _value + '\n\n' : '') + blockquote + '\n\n'); + setTimeout(() => textAreaRef.current?.focus(), 0); + onAppendQuoteConsumed?.(); + }, [appendQuote]); // eslint-disable-line react-hooks/exhaustive-deps + const [isComposing, setIsComposing] = useState(false); const [historyIndex, setHistoryIndex] = useState(-1); const [savedInput, setSavedInput] = useState('');