@@ -213,7 +213,6 @@ import {
213213 resetComposerScrollGesture ,
214214 suppressActiveComposerScrollGesture ,
215215} from "./composerScrollGesture" ;
216- import { selectionHoldsComposerOpen } from "./composerSelectionHold" ;
217216import { prepareVideoFirstFrame } from "../../lib/videoFirstFrame" ;
218217
219218function ComposerVideoThumbnail ( { file } : { file : File } ) {
@@ -1813,7 +1812,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
18131812 isComposerScrollCollapsed,
18141813 setIsComposerScrollCollapsed,
18151814 restoreAfterTimelineReachedEnd,
1816- } = useComposerFocusState ( isMobileViewport ) ;
1815+ } = useComposerFocusState ( ) ;
18171816 const [ composerSubmissionError , setComposerSubmissionError ] = useState < string | null > ( null ) ;
18181817 const [ providerInputSubmissionError , setProviderInputSubmissionError ] = useState < string | null > (
18191818 null ,
@@ -1847,8 +1846,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
18471846 const mobileComposerExpandFrameRef = useRef < number | null > ( null ) ;
18481847 const mobileComposerExpandReleaseFrameRef = useRef < number | null > ( null ) ;
18491848 const mobileComposerExpandInFlightRef = useRef ( false ) ;
1850- const desktopOutsidePointerInFlightRef = useRef ( false ) ;
1851- const desktopOutsidePointerReleaseTimeoutRef = useRef < number | null > ( null ) ;
18521849 const composerScrollCollapseTimeoutRef = useRef < number | null > ( null ) ;
18531850 const composerScrollCollapseEligibleRef = useRef ( false ) ;
18541851 const windowRefocusInFlightRef = useRef ( false ) ;
@@ -3716,10 +3713,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
37163713 const isComposerResting = shouldUseRestingComposerLayout ( {
37173714 isExistingThread : routeKind === "server" && activeThreadId !== null ,
37183715 isMobileViewport,
3719- isFocused : isComposerFocused ,
37203716 isScrollCollapsed : isComposerScrollCollapsed ,
37213717 hasExpandedChrome : composerHasExpandedChrome ,
3722- collapseOnBlur : settings . composerCollapseOnBlur ,
37233718 timelineOverflows,
37243719 } ) ;
37253720 // The relocated controls live in the context strip whenever the composer is
@@ -3804,9 +3799,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
38043799 settings . composerCollapseOnScroll &&
38053800 ! composerHasExpandedChrome &&
38063801 ! showInlineTasksBadge ;
3807- // Scrolling only has something to collapse while the composer is expanded.
3808- // With blur collapse off that includes an unfocused composer, so the wheel
3809- // handler keys off this rather than editor focus.
3802+ // Scrolling only has something to collapse while the composer is expanded,
3803+ // focused or not, so the wheel handler keys off the resting state rather
3804+ // than editor focus.
38103805 composerScrollCollapseEligibleRef . current = canScrollCollapseComposer && ! isComposerResting ;
38113806
38123807 useEffect ( ( ) => {
@@ -4455,19 +4450,18 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
44554450 const handleImplementPlanInNewThreadPrimaryAction = useCallback ( ( ) => {
44564451 void onImplementPlanInNewThread ( ) ;
44574452 } , [ onImplementPlanInNewThread ] ) ;
4453+ // The phone composer collapses when the editor loses focus. Desktop only
4454+ // rests on a timeline scroll, so losing focus there changes nothing.
44584455 const scheduleComposerCollapseCheck = useCallback ( ( ) => {
4459- if ( isMobileViewport && mobileComposerExpandInFlightRef . current ) {
4456+ if ( ! isMobileViewport || mobileComposerExpandInFlightRef . current ) {
44604457 return ;
44614458 }
44624459 if ( composerBlurFrameRef . current !== null ) {
44634460 window . cancelAnimationFrame ( composerBlurFrameRef . current ) ;
44644461 }
44654462 composerBlurFrameRef . current = window . requestAnimationFrame ( ( ) => {
44664463 composerBlurFrameRef . current = null ;
4467- if ( isMobileViewport && mobileComposerExpandInFlightRef . current ) {
4468- return ;
4469- }
4470- if ( ! isMobileViewport && desktopOutsidePointerInFlightRef . current ) {
4464+ if ( mobileComposerExpandInFlightRef . current ) {
44714465 return ;
44724466 }
44734467 const composerSurface = composerSurfaceRef . current ;
@@ -4483,108 +4477,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
44834477 ) {
44844478 return ;
44854479 }
4486- if (
4487- ! isMobileViewport &&
4488- selectionHoldsComposerOpen ( window . getSelection ( ) , getTimelineScrollableNode ( ) )
4489- ) {
4490- // The check runs again once the selection clears.
4491- return ;
4492- }
44934480 setIsComposerFocused ( false ) ;
44944481 } ) ;
4495- } , [ getTimelineScrollableNode , isMobileViewport , setIsComposerFocused ] ) ;
4496-
4497- // A held collapse settles when the selection goes away, whether the user
4498- // clicked elsewhere, pressed Escape, or used the selection toolbar.
4499- useEffect ( ( ) => {
4500- if ( isMobileViewport || ! isComposerFocused ) return ;
4501- let wasHolding = false ;
4502- const handleSelectionChange = ( ) => {
4503- const holding = selectionHoldsComposerOpen (
4504- window . getSelection ( ) ,
4505- getTimelineScrollableNode ( ) ,
4506- ) ;
4507- if ( wasHolding && ! holding ) {
4508- scheduleComposerCollapseCheck ( ) ;
4509- }
4510- wasHolding = holding ;
4511- } ;
4512- document . addEventListener ( "selectionchange" , handleSelectionChange ) ;
4513- return ( ) => {
4514- document . removeEventListener ( "selectionchange" , handleSelectionChange ) ;
4515- } ;
4516- } , [
4517- getTimelineScrollableNode ,
4518- isComposerFocused ,
4519- isMobileViewport ,
4520- scheduleComposerCollapseCheck ,
4521- ] ) ;
4522-
4523- useEffect ( ( ) => {
4524- if ( isMobileViewport || ! isComposerFocused ) return ;
4525-
4526- const isInsideDesktopComposerFocusScope = ( target : EventTarget | null ) =>
4527- Boolean (
4528- target instanceof Node &&
4529- ( composerFormRef . current ?. contains ( target ) || isInsideRestingComposerControlScope ( target ) ) ,
4530- ) ;
4531- const handleFocusIn = ( event : FocusEvent ) => {
4532- if ( ! isInsideDesktopComposerFocusScope ( event . target ) ) {
4533- if ( desktopOutsidePointerInFlightRef . current ) {
4534- return ;
4535- }
4536- setIsComposerFocused ( false ) ;
4537- }
4538- } ;
4539- const handlePointerDown = ( event : PointerEvent ) => {
4540- if ( ! isInsideDesktopComposerFocusScope ( event . target ) ) {
4541- desktopOutsidePointerInFlightRef . current = true ;
4542- if ( desktopOutsidePointerReleaseTimeoutRef . current !== null ) {
4543- window . clearTimeout ( desktopOutsidePointerReleaseTimeoutRef . current ) ;
4544- desktopOutsidePointerReleaseTimeoutRef . current = null ;
4545- }
4546- }
4547- } ;
4548- const finishOutsidePointerInteraction = ( ) => {
4549- desktopOutsidePointerInFlightRef . current = false ;
4550- if ( desktopOutsidePointerReleaseTimeoutRef . current !== null ) {
4551- window . clearTimeout ( desktopOutsidePointerReleaseTimeoutRef . current ) ;
4552- desktopOutsidePointerReleaseTimeoutRef . current = null ;
4553- }
4554- scheduleComposerCollapseCheck ( ) ;
4555- } ;
4556- const handlePointerUp = ( ) => {
4557- if ( ! desktopOutsidePointerInFlightRef . current ) return ;
4558- desktopOutsidePointerReleaseTimeoutRef . current = window . setTimeout ( ( ) => {
4559- if ( desktopOutsidePointerInFlightRef . current ) {
4560- finishOutsidePointerInteraction ( ) ;
4561- }
4562- } , 0 ) ;
4563- } ;
4564- const handleClick = ( ) => {
4565- if ( desktopOutsidePointerInFlightRef . current ) {
4566- finishOutsidePointerInteraction ( ) ;
4567- }
4568- } ;
4569-
4570- document . addEventListener ( "focusin" , handleFocusIn , true ) ;
4571- document . addEventListener ( "pointerdown" , handlePointerDown , true ) ;
4572- document . addEventListener ( "pointerup" , handlePointerUp , true ) ;
4573- document . addEventListener ( "pointercancel" , handlePointerUp , true ) ;
4574- document . addEventListener ( "click" , handleClick ) ;
4575- return ( ) => {
4576- document . removeEventListener ( "focusin" , handleFocusIn , true ) ;
4577- document . removeEventListener ( "pointerdown" , handlePointerDown , true ) ;
4578- document . removeEventListener ( "pointerup" , handlePointerUp , true ) ;
4579- document . removeEventListener ( "pointercancel" , handlePointerUp , true ) ;
4580- document . removeEventListener ( "click" , handleClick ) ;
4581- if ( desktopOutsidePointerReleaseTimeoutRef . current !== null ) {
4582- window . clearTimeout ( desktopOutsidePointerReleaseTimeoutRef . current ) ;
4583- desktopOutsidePointerReleaseTimeoutRef . current = null ;
4584- }
4585- desktopOutsidePointerInFlightRef . current = false ;
4586- } ;
4587- } , [ isComposerFocused , isMobileViewport , scheduleComposerCollapseCheck , setIsComposerFocused ] ) ;
4482+ } , [ isMobileViewport , setIsComposerFocused ] ) ;
45884483
45894484 useEffect ( ( ) => {
45904485 return ( ) => {
@@ -4790,10 +4685,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
47904685
47914686 setIsComposerScrollCollapsed ( false ) ;
47924687 if ( isComposerResting && ! target . closest ( '[data-testid="composer-editor"]' ) ) {
4793- // Clicking resting-surface padding would otherwise blur the still
4794- // focused editor after pointerdown: expansion starts, the blur check
4795- // runs, and it immediately collapses again. Treat that padding like
4796- // the editor without stealing native caret placement from text.
4688+ // Clicking resting-surface padding would otherwise blur the editor.
4689+ // Treat that padding like the editor without stealing native caret
4690+ // placement from text.
47974691 event . preventDefault ( ) ;
47984692 setIsComposerFocused ( true ) ;
47994693 scheduleComposerFocus ( ) ;
0 commit comments