From aaa0b1891f04a487ef740f7939237623ec5f7b44 Mon Sep 17 00:00:00 2001 From: talksik Date: Wed, 8 Apr 2026 17:32:47 -0700 Subject: [PATCH] fix: focus lost when transitioning from immersive to markdown --- js/src/features/compose/text-compose-step.tsx | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/js/src/features/compose/text-compose-step.tsx b/js/src/features/compose/text-compose-step.tsx index 16ddf5c..1eab691 100644 --- a/js/src/features/compose/text-compose-step.tsx +++ b/js/src/features/compose/text-compose-step.tsx @@ -30,8 +30,8 @@ interface TextComposeStepProps { const IMMERSIVE_CHAR_LIMIT = 120; function getImmersiveTextStyle(length: number) { - if (length < 30) return { size: "text-5xl", weight: "font-semibold" }; - if (length < 70) return { size: "text-3xl", weight: "font-semibold" }; + if (length < 70) return { size: "text-5xl", weight: "font-semibold" }; + if (length < 130) return { size: "text-3xl", weight: "font-semibold" }; return { size: "text-2xl", weight: "font-normal" }; } @@ -118,13 +118,22 @@ export function TextComposeStep({ }, [textContent]); const linkPreviews = useAllLinkMetadata(debouncedText); + const hasEnrichments = attachments.length > 0 || linkPreviews.length > 0; + const immersive = textContent.length < IMMERSIVE_CHAR_LIMIT && !hasEnrichments && !forceCardMode; + useEffect(() => { if (!previewMode) { // Small timeout so the textarea is mounted before focusing - const t = setTimeout(() => textareaRef.current?.focus(), 0); + const t = setTimeout(() => { + const el = textareaRef.current; + if (el) { + el.focus(); + el.selectionStart = el.selectionEnd = el.value.length; + } + }, 0); return () => clearTimeout(t); } - }, [previewMode, forceCardMode]); + }, [previewMode, forceCardMode, immersive]); useEffect(() => { textareaRef.current?.focus(); @@ -146,9 +155,6 @@ export function TextComposeStep({ [onCancel, onAdvance, textContent], ); - const hasEnrichments = attachments.length > 0 || linkPreviews.length > 0; - const immersive = textContent.length < IMMERSIVE_CHAR_LIMIT && !hasEnrichments && !forceCardMode; - const strip = (