@@ -52,6 +52,8 @@ import {
5252import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass" ;
5353import { useNativeWorkspaceColumnsSupported } from "../../native/NativeWorkspaceColumns" ;
5454import { useThreadSearch } from "../../state/queries" ;
55+ import { requestThreadMessageJump } from "../threads/threadMessageJump" ;
56+ import { useThreadListSearchMatches } from "../threads/useThreadListSearchMatches" ;
5557import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts" ;
5658import { usePendingThreadOrder } from "../../state/thread-order" ;
5759import { threadListEnvironmentsAtom } from "../../state/server" ;
@@ -297,16 +299,8 @@ export function HomeScreen(props: HomeScreenProps) {
297299 ? [ props . selectedEnvironmentId ]
298300 : [ ] ;
299301 const threadSearch = useThreadSearch ( searchEnvironmentIds , props . searchQuery ) ;
300- const threadSearchMatchByKey = ( ( ) => {
301- const matches = new Map < string , EnvironmentThreadSearchMatch > ( ) ;
302- for ( const match of threadSearch . matches ) {
303- if ( match . source === "user" || match . source === "assistant" ) {
304- matches . set ( threadSearchMatchKey ( match ) , match ) ;
305- }
306- }
307- return matches ;
308- } ) ( ) ;
309- const matchedThreadKeys = new Set ( threadSearch . matches . map ( threadSearchMatchKey ) ) ;
302+ const threadSearchMatchByKey = useThreadListSearchMatches ( props . threads , threadSearch ) ;
303+ const matchedThreadKeys = new Set ( threadSearchMatchByKey . keys ( ) ) ;
310304 const handleSwipeableWillOpen = ( methods : SwipeableMethods ) => {
311305 if ( openSwipeableRef . current !== methods ) {
312306 openSwipeableRef . current ?. close ( ) ;
@@ -561,7 +555,19 @@ export function HomeScreen(props: HomeScreenProps) {
561555 shelfPreferencesLoading : ! shelfPreferencesLoaded ,
562556 } ) ;
563557
564- useThreadJumpShortcuts ( threadListV2Items , props . onSelectThread ) ;
558+ // A row listed for a message match opens the thread at that message, by
559+ // tap or by shortcut.
560+ const selectThread = ( thread : EnvironmentThreadShell ) => {
561+ const key = threadSearchMatchKey ( { environmentId : thread . environmentId , threadId : thread . id } ) ;
562+ const messageId = threadListV2Layout . contentOnlyThreadKeys . has ( key )
563+ ? threadSearchMatchByKey . get ( key ) ?. messageId
564+ : undefined ;
565+ if ( messageId ) {
566+ requestThreadMessageJump ( scopedThreadKey ( thread . environmentId , thread . id ) , messageId ) ;
567+ }
568+ props . onSelectThread ( thread ) ;
569+ } ;
570+ useThreadJumpShortcuts ( threadListV2Items , selectThread ) ;
565571 useEffect ( ( ) => {
566572 if ( swipeEnabled ) activateVisibleRows ( threadListV2Items ) ;
567573 } , [ activateVisibleRows , swipeEnabled , threadListV2Items ] ) ;
@@ -662,14 +668,18 @@ export function HomeScreen(props: HomeScreenProps) {
662668 : null
663669 }
664670 environmentMachine = { machineByEnvironmentId . get ( thread . environmentId ) }
665- searchMatch = { threadSearchMatchByKey . get (
666- threadSearchMatchKey ( {
667- environmentId : thread . environmentId ,
668- threadId : thread . id ,
669- } ) ,
670- ) }
671- searchQuery = { props . searchQuery }
672- onSelectThread = { props . onSelectThread }
671+ searchMatch = {
672+ // Only rows listed for their messages show one and open at it.
673+ threadListV2Layout . contentOnlyThreadKeys . has (
674+ threadSearchMatchKey ( { environmentId : thread . environmentId , threadId : thread . id } ) ,
675+ )
676+ ? threadSearchMatchByKey . get (
677+ threadSearchMatchKey ( { environmentId : thread . environmentId , threadId : thread . id } ) ,
678+ )
679+ : undefined
680+ }
681+ searchQuery = { threadSearch . query }
682+ onSelectThread = { selectThread }
673683 onOpenThreadPullRequests = { handleOpenThreadPullRequests }
674684 onDeleteThread = { handleDeleteThread }
675685 onArchiveThread = { props . onArchiveThread }
0 commit comments