diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx
index 999d9a37..69d757d3 100644
--- a/components/ComposeEmail.tsx
+++ b/components/ComposeEmail.tsx
@@ -64,15 +64,15 @@ export default function ComposeEmail({
if (composeBodyRef.current) {
const decodedContent = decodeComposeContent(composeBody);
- // Create a structure with clear separation
+ // Create the clear structure with proper content
composeBodyRef.current.innerHTML = `
-
-
+
+
${decodedContent}
`;
- // Place cursor at the beginning of new reply area
+ // Place cursor in the new reply area
const newReplyArea = composeBodyRef.current.querySelector('#new-reply-area');
if (newReplyArea) {
const range = document.createRange();
@@ -85,10 +85,31 @@ export default function ComposeEmail({
}
}, [composeBody]);
+ // Enhanced input handler to prevent text reversal
const handleInput = (e: React.FormEvent
) => {
if (composeBodyRef.current) {
- const encodedContent = encodeComposeContent(composeBodyRef.current.innerHTML);
- setComposeBody(encodedContent);
+ // Get the current HTML content
+ const fullContent = e.currentTarget.innerHTML;
+
+ // Split at the divider to separate new reply from original content
+ const parts = fullContent.split(' 1) {
+ // Extract user-typed content (ensuring it's not reversed)
+ const userContent = parts[0];
+
+ // Keep original content as is
+ const originalContent = '
diff --git a/lib/compose-mime-decoder.ts b/lib/compose-mime-decoder.ts
index 47fc6349..4ba9cf83 100644
--- a/lib/compose-mime-decoder.ts
+++ b/lib/compose-mime-decoder.ts
@@ -6,7 +6,10 @@
export function decodeComposeContent(content: string): string {
if (!content) return '';
- // Basic HTML cleaning
+ // Debug logging
+ console.log("Before decode:", content);
+
+ // Basic HTML cleaning without any string manipulation that could reverse text
let cleaned = content
// Remove script and style tags
.replace(/