From f9244f5a20d754b39ecc2ab2a84b31e6ae93b9e0 Mon Sep 17 00:00:00 2001 From: alma Date: Thu, 1 May 2025 16:25:56 +0200 Subject: [PATCH] courrier preview --- lib/utils/email-utils.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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 + } }