Skip to content
Open
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
4 changes: 2 additions & 2 deletions apps/web/src/components/CommandPalette.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe("buildThreadActionItems", () => {
]);
});

it("preserves thread project-name matches when there is no stronger title match", () => {
it("preserves queries spanning thread and project search terms", () => {
const group: CommandPaletteGroup = {
value: "threads-search",
label: "Threads",
Expand All @@ -262,7 +262,7 @@ describe("buildThreadActionItems", () => {

const groups = filterCommandPaletteGroups({
activeGroups: [group],
query: "project",
query: "spacing project",
isInSubmenu: false,
projectSearchItems: [],
threadSearchItems: [],
Expand Down
11 changes: 8 additions & 3 deletions apps/web/src/components/CommandPalette.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from "@t3tools/contracts";
import { filterFilesystemBrowseEntries } from "@t3tools/client-runtime/state/filesystem";
import type { SidebarThreadSortOrder } from "@t3tools/contracts/settings";
import { scoreSubsequenceMatch } from "@t3tools/shared/searchRanking";
import * as Arr from "effect/Array";
import * as Result from "effect/Result";
import { type ReactNode } from "react";
Expand Down Expand Up @@ -257,7 +258,10 @@ export function buildThreadActionItems<TThread extends BuildThreadActionItemsThr

function rankSearchFieldMatch(field: string, normalizedQuery: string): number {
const normalizedField = normalizeSearchText(field);
if (normalizedField.length === 0 || !normalizedField.includes(normalizedQuery)) {
if (
normalizedField.length === 0 ||
scoreSubsequenceMatch(normalizedField, normalizedQuery) === null
) {
return Number.NEGATIVE_INFINITY;
}
if (normalizedField === normalizedQuery) {
Expand Down Expand Up @@ -333,15 +337,16 @@ export function filterCommandPaletteGroups(input: {

return searchableGroups.flatMap((group) => {
const items = Arr.filterMap(group.items, (item, index) => {
const rank = rankCommandPaletteItemMatch(item, normalizedQuery);
const haystack = normalizeSearchText(item.searchTerms.join(" "));
if (!haystack.includes(normalizedQuery)) {
if (rank === 0 && !haystack.includes(normalizedQuery)) {
return Result.failVoid;
}
Comment thread
macroscopeapp[bot] marked this conversation as resolved.

return Result.succeed({
item,
index,
rank: rankCommandPaletteItemMatch(item, normalizedQuery),
rank,
});
})
.toSorted((left, right) => right.rank - left.rank || left.index - right.index)
Expand Down
Loading