@@ -1271,8 +1271,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
12711271 detectComposerTrigger ( prompt , prompt . length ) ,
12721272 ) ;
12731273 const [ composerHighlightedItemId , setComposerHighlightedItemId ] = useState < string | null > ( null ) ;
1274- // Active ArrowUp recall. Stale positions (edited text, another thread) fail
1275- // to resolve on the next step, so nothing has to clear this.
1274+ // Active ArrowUp recall. Cleared on edit and on thread switch.
12761275 const promptHistoryPositionRef = useRef < ComposerPromptHistoryPosition | null > ( null ) ;
12771276 const [ composerHighlightedSearchKey , setComposerHighlightedSearchKey ] = useState < string | null > (
12781277 null ,
@@ -1954,6 +1953,12 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
19541953 }
19551954 promptRef . current = nextPrompt ;
19561955 setPrompt ( nextPrompt ) ;
1956+ // Any edit ends browsing, even one later undone by hand: typing a
1957+ // character and deleting it leaves the text equal to the recall, and
1958+ // ArrowDown must move the caret then, not clear the composer.
1959+ if ( promptHistoryPositionRef . current ?. recalled !== nextPrompt ) {
1960+ promptHistoryPositionRef . current = null ;
1961+ }
19571962 if ( ! terminalContextIdListsEqual ( composerTerminalContexts , terminalContextIds ) ) {
19581963 setComposerDraftTerminalContexts (
19591964 composerDraftTarget ,
@@ -2358,6 +2363,14 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
23582363 const promptHistoryMessagesRef = useRef ( promptHistoryMessages ) ;
23592364 promptHistoryMessagesRef . current = promptHistoryMessages ;
23602365
2366+ // The composer persists across threads. A recall from thread A must not
2367+ // be treated as active in thread B, where the text-match fallback could
2368+ // otherwise turn B's own draft into a browsing position.
2369+ const promptHistoryTargetKey = composerTargetKey ( composerDraftTarget ) ;
2370+ useEffect ( ( ) => {
2371+ promptHistoryPositionRef . current = null ;
2372+ } , [ promptHistoryTargetKey ] ) ;
2373+
23612374 const replacePromptFromHistory = useCallback (
23622375 ( nextPrompt : string ) => {
23632376 promptRef . current = nextPrompt ;
0 commit comments