diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx
index 7eae1be5..840281d6 100644
--- a/components/ComposeEmail.tsx
+++ b/components/ComposeEmail.tsx
@@ -82,59 +82,42 @@ export default function ComposeEmail({
useEffect(() => {
if (composeBodyRef.current) {
- // Initialize the content structure
- const originalContent = replyTo || forwardFrom ? `
-
+ // Initialize the content structure with both new reply area and original content in a single contentEditable div
+ const content = replyTo || forwardFrom ? `
+
+
+ ${forwardFrom ? `
+ ---------- Forwarded message ---------
+ From: ${forwardFrom.from}
+ Date: ${new Date(forwardFrom.date).toLocaleString()}
+ Subject: ${forwardFrom.subject}
+ To: ${forwardFrom.to}
+ ${forwardFrom.cc ? `Cc: ${forwardFrom.cc}
` : ''}
+
+ ` : `
+ On ${new Date(replyTo?.date || '').toLocaleString()}, ${replyTo?.from} wrote:
+ `}
+
${composeBody}
-
- ` : composeBody;
+
+ ` : '';
- composeBodyRef.current.innerHTML = originalContent;
+ composeBodyRef.current.innerHTML = content;
- // Place cursor at the beginning of new reply area
- const newReplyArea = composeBodyRef.current.querySelector('#new-reply-area');
- if (newReplyArea) {
- const range = document.createRange();
- const sel = window.getSelection();
- range.setStart(newReplyArea, 0);
- range.collapse(true);
- sel?.removeAllRanges();
- sel?.addRange(range);
- }
+ // Place cursor at the beginning
+ const range = document.createRange();
+ const sel = window.getSelection();
+ range.setStart(composeBodyRef.current, 0);
+ range.collapse(true);
+ sel?.removeAllRanges();
+ sel?.addRange(range);
}
}, [composeBody, replyTo, forwardFrom]);
- // Modified input handler to prevent nested structures
+ // Modified input handler to work with the single contentEditable area
const handleInput = (e: React.FormEvent