diff --git a/lib/utils/email-utils.ts b/lib/utils/email-utils.ts index bc7c0343..82b8b8c4 100644 --- a/lib/utils/email-utils.ts +++ b/lib/utils/email-utils.ts @@ -667,4 +667,34 @@ export function formatEmailForReplyOrForward( } else { return formatReplyEmail(email, type as 'reply' | 'reply-all'); } +} + +// First check if Quill is fully initialized and ready +if (quillRef.current && + quillRef.current.format && + typeof quillRef.current.format === 'function' && + quillRef.current.root && + quillRef.current.root.innerHTML && + quillRef.current.root.innerHTML.trim().length > 0) { + + // Wrap formatting operations in try/catch to prevent errors from crashing the app + try { + // Delay the formatting to ensure Quill is fully ready + setTimeout(() => { + if (quillRef.current) { + // Set the direction for the content + quillRef.current.format('direction', direction); + + if (direction === 'rtl') { + quillRef.current.format('align', 'right'); + } + + // Set selection to beginning + quillRef.current.setSelection(0, 0); + } + }, 100); + } catch (formatError) { + console.error('Error applying formatting:', formatError); + // Continue without formatting if there's an error + } }