@@ -37,6 +37,7 @@ import {
3737 useState ,
3838} from "react" ;
3939import {
40+ Alert ,
4041 AppState ,
4142 Keyboard ,
4243 Platform ,
@@ -67,6 +68,8 @@ import type { StatusTone } from "../../components/StatusPill";
6768import type { DraftComposerAttachment } from "../../lib/composerImages" ;
6869import { CHAT_CONTENT_MAX_WIDTH , type LayoutVariant } from "../../lib/layout" ;
6970import { IOS_NAV_BAR_HEIGHT } from "../../lib/layoutMetrics" ;
71+ import { editPendingThreadMessage } from "../../state/edit-pending-thread-message" ;
72+ import type { QueuedThreadMessage } from "../../state/thread-outbox-model" ;
7073import { scopedThreadKey } from "../../lib/scopedEntities" ;
7174import type {
7275 PendingApproval ,
@@ -127,6 +130,8 @@ export interface ThreadDetailScreenProps {
127130 readonly projectWorkspaceRoot : string | null ;
128131 readonly threadCwd : string | null ;
129132 readonly selectedThreadQueueCount : number ;
133+ readonly queuedMessages : ReadonlyArray < QueuedThreadMessage > ;
134+ readonly dispatchingMessageId : MessageId | null ;
130135 readonly serverConfig : T3ServerConfig | null ;
131136 readonly layoutVariant ?: LayoutVariant ;
132137 readonly usesAutomaticContentInsets ?: boolean ;
@@ -348,6 +353,15 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
348353 return null ;
349354 } ) ( ) ;
350355 const showWorkingControl = floatingStatus !== null ;
356+ // Connection and working status occupy the same space. Keep the feed inset
357+ // stable when reconnecting hands off to syncing and then to a running turn.
358+ const showFloatingStatus =
359+ showWorkingControl ||
360+ props . connectionStateLabel !== "connected" ||
361+ props . queuedMessages . length > 0 ||
362+ props . selectedThreadFeed . some (
363+ ( entry ) => "acknowledged" in entry && entry . acknowledged === true ,
364+ ) ;
351365 const selectedThreadFeed = props . selectedThreadFeed ;
352366 const hasCompactableConversation =
353367 selectedThreadFeed . some (
@@ -487,14 +501,14 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
487501 const userInputInsetProgress = useSharedValue ( 1 ) ;
488502 const userInputCardCoverage = useSharedValue ( 0 ) ;
489503 const floatingControlCoverage = useSharedValue (
490- showWorkingControl ? FLOATING_WORKING_CONTROL_COVERAGE : 0 ,
504+ showFloatingStatus ? FLOATING_WORKING_CONTROL_COVERAGE : 0 ,
491505 ) ;
492506 useEffect ( ( ) => {
493507 floatingControlCoverage . value = withTiming (
494- showWorkingControl ? FLOATING_WORKING_CONTROL_COVERAGE : 0 ,
508+ showFloatingStatus ? FLOATING_WORKING_CONTROL_COVERAGE : 0 ,
495509 { duration : 180 , reduceMotion : ReduceMotion . System } ,
496510 ) ;
497- } , [ floatingControlCoverage , showWorkingControl ] ) ;
511+ } , [ floatingControlCoverage , showFloatingStatus ] ) ;
498512 // Android renders the expanded card in-flow (it cannot hit-test the iOS
499513 // overlay outside the bar's bounds), so its measured overlay height already
500514 // includes the card — the coverage extra is iOS-only.
@@ -554,20 +568,20 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
554568 useEffect ( ( ) => {
555569 const previous = previousWorkingControlStateRef . current ;
556570 const threadChanged = previous . threadKey !== selectedThreadKey ;
557- const visibilityChanged = previous . visible !== showWorkingControl ;
571+ const visibilityChanged = previous . visible !== showFloatingStatus ;
558572 previousWorkingControlStateRef . current = {
559573 threadKey : selectedThreadKey ,
560- visible : showWorkingControl ,
574+ visible : showFloatingStatus ,
561575 } ;
562- if ( ( ! threadChanged && ! visibilityChanged ) || ( threadChanged && ! showWorkingControl ) ) {
576+ if ( ( ! threadChanged && ! visibilityChanged ) || ( threadChanged && ! showFloatingStatus ) ) {
563577 return ;
564578 }
565579 // LegendList applies the larger inset but does not re-anchor short
566580 // followed conversations when this floating coverage changes after the
567581 // initial load. Re-pin after the finite inset transition; the callback
568582 // checks follow state again so a user who scrolled up stays put.
569583 scheduleOverlayRepin ( 230 ) ;
570- } , [ scheduleOverlayRepin , selectedThreadKey , showWorkingControl ] ) ;
584+ } , [ scheduleOverlayRepin , selectedThreadKey , showFloatingStatus ] ) ;
571585 const handleToggleUserInputCollapsed = useCallback ( ( ) => {
572586 if ( activeUserInputRequestId === null ) {
573587 return ;
@@ -634,11 +648,13 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
634648 useEffect ( ( ) => {
635649 if (
636650 submittedMessageId === null ||
651+ anchorMessageId !== submittedMessageId ||
637652 lastScrolledSubmittedMessageIdRef . current === submittedMessageId ||
638653 contentPresentationKind !== "ready" ||
639- ! selectedThreadFeed . some (
654+ ( ! selectedThreadFeed . some (
640655 ( entry ) => entry . type === "message" && entry . id === submittedMessageId ,
641- )
656+ ) &&
657+ ! props . queuedMessages . some ( ( message ) => message . messageId === submittedMessageId ) )
642658 ) {
643659 return ;
644660 }
@@ -677,9 +693,11 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
677693 } ) ;
678694 return ( ) => cancelAnimationFrame ( frame ) ;
679695 } , [
696+ anchorMessageId ,
680697 submittedMessageId ,
681698 freeze ,
682699 contentPresentationKind ,
700+ props . queuedMessages ,
683701 selectedThreadFeed ,
684702 scrollMessageToEnd ,
685703 selectedThreadKey ,
@@ -720,6 +738,22 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
720738 selectedThreadKey ,
721739 ] ) ;
722740
741+ const handleEditPendingMessage = useCallback ( async ( message : QueuedThreadMessage ) => {
742+ try {
743+ if (
744+ ( await editPendingThreadMessage ( message ) ) &&
745+ selectedThreadKeyRef . current === scopedThreadKey ( message . environmentId , message . threadId )
746+ ) {
747+ composerEditorRef . current ?. focus ( ) ;
748+ }
749+ } catch ( error ) {
750+ Alert . alert (
751+ "Could not edit message" ,
752+ error instanceof Error ? error . message : "Please try again." ,
753+ ) ;
754+ }
755+ } , [ ] ) ;
756+
723757 const collapseComposer = useCallback ( ( ) => {
724758 composerEditorRef . current ?. blur ( ) ;
725759 } , [ ] ) ;
@@ -797,6 +831,9 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
797831 threadId = { props . selectedThread . id }
798832 workspaceRoot = { props . threadCwd }
799833 feed = { props . selectedThreadFeed }
834+ queuedMessages = { props . queuedMessages }
835+ dispatchingMessageId = { props . dispatchingMessageId }
836+ onEditPendingMessage = { handleEditPendingMessage }
800837 contentPresentation = { props . contentPresentation }
801838 agentLabel = { agentLabel }
802839 latestTurn = { props . selectedThread . latestTurn }
@@ -808,7 +845,7 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
808845 contentInsetEndAdjustment = { combinedContentInsetEndAdjustment }
809846 contentTopInset = { 0 }
810847 contentBottomInset = {
811- estimatedOverlayHeight + ( showWorkingControl ? FLOATING_WORKING_CONTROL_COVERAGE : 0 )
848+ estimatedOverlayHeight + ( showFloatingStatus ? FLOATING_WORKING_CONTROL_COVERAGE : 0 )
812849 }
813850 contentMaxWidth = { contentMaxWidth }
814851 layoutVariant = { layoutVariant }
0 commit comments