Skip to content

Commit bb7783e

Browse files
t3dotggclaude
andauthored
feat(search): Cmd+K finds the right thread first, with indexed message search (#24343)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent fef851b commit bb7783e

69 files changed

Lines changed: 5797 additions & 718 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/src/features/archive/archivedThreadList.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import {
55
type EnvironmentProject,
66
type EnvironmentThreadShell,
77
} from "@t3tools/client-runtime/state/shell";
8+
import { threadSearchSubject } from "@t3tools/client-runtime/state/thread-search";
89
import type { EnvironmentId } from "@t3tools/contracts";
10+
import { foldSearchQuery, rankSearchItems, scoreThreadSearch } from "@t3tools/shared/paletteSearch";
911
import * as Arr from "effect/Array";
1012
import * as Order from "effect/Order";
1113

@@ -36,6 +38,7 @@ export function buildArchivedThreadGroups(input: {
3638
readonly sortOrder: ArchivedThreadSortOrder;
3739
}): ReadonlyArray<ArchivedThreadGroup> {
3840
const query = input.searchQuery.trim().toLocaleLowerCase();
41+
const foldedQuery = foldSearchQuery(input.searchQuery);
3942
const groups: ArchivedThreadGroup[] = [];
4043

4144
for (const entry of input.snapshots) {
@@ -62,11 +65,15 @@ export function buildArchivedThreadGroups(input: {
6265
matchesQuery(project.title, query) ||
6366
matchesQuery(project.workspaceRoot, query) ||
6467
matchesQuery(environmentLabel, query);
68+
// Threads match as in every other thread search; the list keeps its own order.
6569
const matchingThreads = groupMatches
6670
? projectThreads
67-
: projectThreads.filter(
68-
(thread) => matchesQuery(thread.title, query) || matchesQuery(thread.branch, query),
69-
);
71+
: rankSearchItems(projectThreads, (thread, options) =>
72+
scoreThreadSearch(foldedQuery, threadSearchSubject(thread, null), 0, {
73+
...options,
74+
picks: false,
75+
}),
76+
).map(({ item }) => item);
7077

7178
if (matchingThreads.length === 0) {
7279
continue;

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ import {
5252
import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
5353
import { useNativeWorkspaceColumnsSupported } from "../../native/NativeWorkspaceColumns";
5454
import { useThreadSearch } from "../../state/queries";
55+
import { requestThreadMessageJump } from "../threads/threadMessageJump";
56+
import { useThreadListSearchMatches } from "../threads/useThreadListSearchMatches";
5557
import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts";
5658
import { usePendingThreadOrder } from "../../state/thread-order";
5759
import { 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

Comments
 (0)