xonecas.io
6615
Yc

yoctoselect / commit ded4f9e

feat: word-prefix matching in filter

xonecas2026-03-21 ded4f9e55ef4777639c8f76a375c7fe8fc837424 parent d80b202

3 files changed

package.json+1−1
@@ -1,6 +1,6 @@
11 {
22 "name": "yoctoselect",
3- "version": "0.0.1",
3+ "version": "0.0.2",
44 "module": "src/index.ts",
55 "type": "module",
66 "devDependencies": {
src/filter.test.ts+27−0
@@ -59,4 +59,31 @@ describe("prefixFilter", () => {
5959 ]);
6060 expect(prefixFilter(rich, "\x1b[31m")).toEqual([]);
6161 });
62+
63+ test("matches word prefix in filterText", () => {
64+ const models = normalizeItems([
65+ {
66+ label: "Claude Sonnet 4",
67+ value: "anthropic/claude-sonnet-4",
68+ filterText: "anthropic/claude-sonnet-4 Claude Sonnet 4 anthropic",
69+ },
70+ {
71+ label: "GPT-4o",
72+ value: "openai/gpt-4o",
73+ filterText: "openai/gpt-4o GPT-4o openai",
74+ },
75+ ]);
76+ // "cl" matches "claude-sonnet-4" and "Claude" words
77+ expect(prefixFilter(models, "cl").map((i) => i.value)).toEqual([
78+ "anthropic/claude-sonnet-4",
79+ ]);
80+ // "Son" matches "Sonnet" word
81+ expect(prefixFilter(models, "Son").map((i) => i.value)).toEqual([
82+ "anthropic/claude-sonnet-4",
83+ ]);
84+ // "gpt" matches "gpt-4o" word
85+ expect(prefixFilter(models, "gpt").map((i) => i.value)).toEqual([
86+ "openai/gpt-4o",
87+ ]);
88+ });
6289 });
src/filter.ts+7−1
@@ -25,5 +25,11 @@ export function prefixFilter(
2525 ): NormalizedItem[] {
2626 if (!query) return items;
2727 const q = query.toLowerCase();
28- return items.filter((item) => item.filterText.toLowerCase().startsWith(q));
28+ return items.filter((item) => {
29+ const text = item.filterText.toLowerCase();
30+ if (text.startsWith(q)) return true;
31+ // Also match if any word in filterText starts with the query
32+ const words = text.split(/[\s/]+/);
33+ return words.some((word) => word.startsWith(q));
34+ });
2935 }