Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apps/client/src/search-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,16 @@ describe("performSearch", () => {
});
expect(results.every((r) => r.sessionId !== "t1")).toBe(true);
});

it("handles cached search results", () => {
const results = performSearch("model", "all", {
activeSessionId: "s1",
selectedWorktreePath: "/wt/main",
projects,
sessions,
chatData,
});

expect(results).toBeTruthy();
});
});
11 changes: 11 additions & 0 deletions apps/client/src/search-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import type { ChatSessionData } from "./store.ts";

export type SearchScope = "session" | "project" | "all";

let lastSearchQuery = "";
let lastSearchResults: SearchResult[] = [];

export function performSearch(
query: string,
scope: SearchScope,
Expand All @@ -17,6 +20,10 @@ export function performSearch(
): SearchResult[] {
if (!query.trim()) return [];

if (query === lastSearchQuery) {
return lastSearchResults;
}

const lower = query.toLowerCase();
const results: SearchResult[] = [];

Expand Down Expand Up @@ -55,6 +62,7 @@ export function performSearch(
const msg = data.messages[i];
const text = msg.role === "user" ? msg.content : msg.text;
if (text.toLowerCase().includes(lower)) {
console.log("search hit", sessionId, text);
results.push({
sessionId,
sessionName,
Expand All @@ -69,5 +77,8 @@ export function performSearch(
}
}

lastSearchQuery = query;
lastSearchResults = results;

return results;
}
Loading