diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx index 9fa26389..92847375 100644 --- a/components/ComposeEmail.tsx +++ b/components/ComposeEmail.tsx @@ -95,14 +95,13 @@ export default function ComposeEmail({ return; } - // Create initial content immediately - const initialContent = ` -
- ${data.html || data.text || 'No content available'} ++ ${emailContent}`; - // Set the content in the compose area + // Set the content in the compose area with proper structure + const formattedContent = ` +++ `; + if (composeBodyRef.current) { - const formattedContent = ` -+ ${quotedContent} +-- `; composeBodyRef.current.innerHTML = formattedContent; - // Place cursor at the beginning + // Place cursor at the beginning before the quoted content const selection = window.getSelection(); const range = document.createRange(); - range.setStart(composeBodyRef.current.firstChild || composeBodyRef.current, 0); - range.collapse(true); - selection?.removeAllRanges(); - selection?.addRange(range); + const firstDiv = composeBodyRef.current.querySelector('div[style*="min-height: 20px;"]'); + if (firstDiv) { + range.setStart(firstDiv, 0); + range.collapse(true); + selection?.removeAllRanges(); + selection?.addRange(range); + (firstDiv as HTMLElement).focus(); + } // Update compose state setComposeBody(formattedContent); @@ -165,7 +172,7 @@ export default function ComposeEmail({ console.error('Error initializing compose content:', error); if (composeBodyRef.current) { const errorContent = ` -
- ${quotedContent} -+@@ -184,10 +191,7 @@ export default function ComposeEmail({ const handleInput = (e: React.FormEvent
Error loading original message.) => { if (!composeBodyRef.current) return; - const composeArea = composeBodyRef.current.querySelector('.compose-area'); - if (!composeArea) return; - - const content = composeArea.innerHTML; + const content = composeBodyRef.current.innerHTML; if (!content.trim()) { setLocalContent(''); setComposeBody('');