Skip to content

The agent that grows with you

fix(desktop): scope separator highlighting to model searches

Teknium50d7a756d8fe
diff --git a/apps/desktop/DESIGN.md b/apps/desktop/DESIGN.md
index de6846536c7..6c82771ee40 100644
--- a/apps/desktop/DESIGN.md
+++ b/apps/desktop/DESIGN.md
@@ -148,6 +148,8 @@ on its own longer delay (list titles must not trail while scanning).
**Slash descriptions.** Keep autocomplete rows single-line and ellipsized, but reveal the complete catalog description in the shared themed tooltip when hovering anywhere on a slash row. Size that tooltip to the window with collision padding and word wrapping; it must not intercept row selection. Catalog and completion producers preserve the full author-supplied description.
+**Model search.** Model filters and their highlighted labels treat hyphens, dots, underscores and spaces equivalently. Preserve original label spelling inside marks. The shared highlighter remains literal for other surfaces such as the command palette; model callers explicitly opt in. Model identifier search does not use dictionary spellcheck.
+
**Keybind hints in tooltips.** On a tipped button bound to a rebindable hotkey,
use `<TipKeybindLabel actionId="..." />` — it reads the i18n label and the
current combo from `$bindings`. Pass `text={...}` only when the label is
diff --git a/apps/desktop/src/app/shell/model-catalog-menu.search-fold.test.tsx b/apps/desktop/src/app/shell/model-catalog-menu.search-fold.test.tsx
index 5473a1fdeea..41cda53d03f 100644
--- a/apps/desktop/src/app/shell/model-catalog-menu.search-fold.test.tsx
+++ b/apps/desktop/src/app/shell/model-catalog-menu.search-fold.test.tsx
@@ -1,6 +1,6 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
-import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
+import { afterEach, beforeAll, beforeEach, expect, it, vi } from 'vitest'
import { DropdownMenu, DropdownMenuContent } from '@/components/ui/dropdown-menu'
import { $localModelsEnabled } from '@/store/local-models-flag'
@@ -62,47 +62,15 @@ function renderMenu() {
}
+it('matches and highlights separator-equivalent queries without revealing unrelated models', async () => {
+ renderMenu()
+ await screen.findByText(/Qwen3\.8 Flash/i)
-
-// The row label span (class "truncate") carries the full label text plus the
-// meta suffix ("High"/"Min"), so match by prefix. Works for both the plain
-// and the <mark>-split rendering.
-function rowTruncateSpan(prefix: string) {
- return screen.queryByText((_, element) =>
- Boolean(element?.classList.contains('truncate') && (element?.textContent ?? '').startsWith(prefix))
- )
-}
-
-// The search filter and the highlight must agree: whatever a query reveals,
-// the row's label marks the query (separator-folded equivalence). Pre-fix,
-// hyphen queries revealed rows with zero marks, and space queries matched
-// only via the display segment - both polarity failures covered here.
-describe('model catalog search: fold between filter and highlight', () => {
- it('HYPHEN query both filters and highlights the SPACED label (the reported defect - fails pre-fix)', async () => {
- renderMenu()
- await screen.findByText(/Qwen3\.8 Flash/i)
-
- fireEvent.change(screen.getByRole('textbox', { name: 'Search models' }), { target: { value: 'qwen3.8-flash' } })
-
- await vi.waitFor(() => {
- // Whole label matches contiguously -> renders as a single <mark>.
- expect(screen.getByText('Qwen3.8 Flash', { selector: 'mark' })).toBeDefined()
- })
- })
-
- it('SPACE query finds the HYPHENATED id (superset guarantee) and highlights', async () => {
- renderMenu()
- await screen.findByText(/Qwen3\.8 Flash/i)
-
- fireEvent.change(screen.getByRole('textbox', { name: 'Search models' }), { target: { value: 'qwen3 8' } })
-
+ for (const [query, marked] of [['qwen3.8-flash', 'Qwen3.8 Flash'], ['qwen3 8', 'Qwen3.8']]) {
+ fireEvent.change(screen.getByRole('textbox', { name: 'Search models' }), { target: { value: query } })
await vi.waitFor(() => {
- // Partial label match -> <mark>Qwen3.8</mark> + ' Flash'.
- expect(screen.getByText('Qwen3.8', { selector: 'mark' })).toBeDefined()
- // The row label (before the meta suffix) is intact.
- expect(rowTruncateSpan('Qwen3.8 Flash')).toBeDefined()
- // The fold must not over-match: a qwen query still hides GPT rows.
- expect(rowTruncateSpan('GPT-5.1')).toBeNull()
+ expect(screen.getByText(marked, { selector: 'mark' })).not.toBeNull()
+ expect(screen.queryByText(/GPT-5\.1/i)).toBeNull()
})
- })
+ }
})
diff --git a/apps/desktop/src/app/shell/model-catalog-menu.tsx b/apps/desktop/src/app/shell/model-catalog-menu.tsx
index 78c563ddea7..0feee4f7ecb 100644
--- a/apps/desktop/src/app/shell/model-catalog-menu.tsx
+++ b/apps/desktop/src/app/shell/model-catalog-menu.tsx
@@ -481,7 +481,7 @@ export function ModelCatalogMenu({
textValue=""
>
<span className="truncate">
- <HighlightMatches query={search} text={group.provider.name} />
+ <HighlightMatches foldSeparators query={search} text={group.provider.name} />
</span>
<DisclosureCaret
className="shrink-0 text-(--ui-text-tertiary) opacity-0 transition group-hover/label:opacity-100"
@@ -554,7 +554,7 @@ export function ModelCatalogMenu({
{...kbRowProps(`${group.provider.slug}:${family.id}`)}
>
<span className="min-w-0 flex-1 truncate">
- <HighlightMatches query={search} text={name} />
+ <HighlightMatches foldSeparators query={search} text={name} />
{meta ? <span className="text-(--ui-text-tertiary)"> {meta}</span> : null}
</span>
{loadProgress ? (
@@ -640,7 +640,7 @@ export function ModelCatalogMenu({
{...kbRowProps(`moa:${preset}`)}
>
<span className="min-w-0 flex-1 truncate">
- MoA: <HighlightMatches query={search} text={preset} />
+ MoA: <HighlightMatches foldSeparators query={search} text={preset} />
</span>
{isCurrentMoa ? <Codicon className="ml-auto text-foreground" name="check" size="0.75rem" /> : null}
</DropdownMenuItem>
diff --git a/apps/desktop/src/components/model-picker.tsx b/apps/desktop/src/components/model-picker.tsx
index ade0de19e93..3beaa8428d8 100644
--- a/apps/desktop/src/components/model-picker.tsx
+++ b/apps/desktop/src/components/model-picker.tsx
@@ -337,7 +337,7 @@ function ModelResults({
value={`${provider.slug}:${model}`}
>
<span className="min-w-0 flex-1 truncate">
- <HighlightMatches query={search} text={model} />
+ <HighlightMatches foldSeparators query={search} text={model} />
</span>
{loadProgress && (
<span className="flex shrink-0 items-center gap-1.5" title={copy.loadingIntoMemory}>
diff --git a/apps/desktop/src/components/model-visibility-dialog.tsx b/apps/desktop/src/components/model-visibility-dialog.tsx
index 626d5c59c9a..ffde6f2f6cd 100644
--- a/apps/desktop/src/components/model-visibility-dialog.tsx
+++ b/apps/desktop/src/components/model-visibility-dialog.tsx
@@ -129,7 +129,7 @@ export function ModelVisibilityDialog({
type="button"
>
<span className="min-w-0 truncate">
- <HighlightMatches query={search} text={provider.name} />
+ <HighlightMatches foldSeparators query={search} text={provider.name} />
</span>
<DisclosureCaret
className="shrink-0 opacity-0 transition group-hover/label:opacity-100"
@@ -153,7 +153,7 @@ export function ModelVisibilityDialog({
key={key}
>
<span className="min-w-0 flex-1 truncate">
- <HighlightMatches query={search} text={name} />
+ <HighlightMatches foldSeparators query={search} text={name} />
{tag ? <span className="text-(--ui-text-tertiary)"> {tag}</span> : null}
</span>
<Switch
diff --git a/apps/desktop/src/components/ui/highlight-matches-model.test.tsx b/apps/desktop/src/components/ui/highlight-matches-model.test.tsx
new file mode 100644
index 00000000000..37a451e71d5
--- /dev/null
+++ b/apps/desktop/src/components/ui/highlight-matches-model.test.tsx
@@ -0,0 +1,23 @@
+import { cleanup, render } from '@testing-library/react'
+import { afterEach, expect, it } from 'vitest'
+
+import { foldIncludes } from '@/lib/text'
+
+import { HighlightMatches } from './highlight-matches'
+
+afterEach(cleanup)
+
+it('folds separators only for model filters and preserves the original marked text', () => {
+ for (const query of ['fixture-model', 'fixture_model', 'fixture.model', 'fixture model']) {
+ const text = 'Fixture Model'
+ expect(foldIncludes(text, query)).toBe(true)
+ const { container, unmount } = render(<HighlightMatches foldSeparators query={query} text={text} />)
+ expect(container.querySelector('mark')?.textContent).toBe(text)
+ expect(container.textContent).toBe(text)
+ unmount()
+ }
+
+ const { container } = render(<HighlightMatches query={['fixture-model']} text="Fixture Model" />)
+ expect(container.querySelector('mark')).toBeNull()
+ expect(foldIncludes('Another model', 'fixture-model')).toBe(false)
+})
diff --git a/apps/desktop/src/components/ui/highlight-matches.test.tsx b/apps/desktop/src/components/ui/highlight-matches.test.tsx
index d993998860a..2747fc74d81 100644
--- a/apps/desktop/src/components/ui/highlight-matches.test.tsx
+++ b/apps/desktop/src/components/ui/highlight-matches.test.tsx
@@ -5,43 +5,41 @@ import { HighlightMatches } from './highlight-matches'
const marksOf = (container: HTMLElement) => Array.from(container.querySelectorAll('mark')).map(m => m.textContent)
-describe('HighlightMatches with separator folding', () => {
- it('HYPHEN query marks the SPACED label (the reported defect — fails pre-fix)', () => {
- const { container } = render(<HighlightMatches query="qwen3.8-flash" text="Qwen3.8 Flash" />)
+describe('HighlightMatches', () => {
+ it('wraps every case-insensitive occurrence in a <mark> without altering the text', () => {
+ const { container } = render(<HighlightMatches query="ro" text="Grok 4.5 Retro" />)
- expect(marksOf(container)).toEqual(['Qwen3.8 Flash'])
+ expect(container.textContent).toBe('Grok 4.5 Retro')
+ expect(marksOf(container)).toEqual(['ro', 'ro'])
})
- it('SPACE query marks the HYPHENATED text (model-picker polarity)', () => {
- const { container } = render(<HighlightMatches query="qwen3 8 flash" text="qwen3.8-flash" />)
+ it('renders plain text when the query is empty or does not occur in this label', () => {
+ // Non-occurrence matters: rows can match the filter on id/slug while the
+ // display label contains no occurrence — must not crash or mis-mark.
+ for (const query of ['', ' ', 'zzz']) {
+ const { container } = render(<HighlightMatches query={query} text="Fable 5" />)
- expect(marksOf(container)).toEqual(['qwen3.8-flash'])
+ expect(container.textContent).toBe('Fable 5')
+ expect(container.querySelector('mark')).toBeNull()
+ }
})
- it('folding must not shift mark indices: slices return the ORIGINAL characters', () => {
- const { container } = render(<HighlightMatches query="gpt 5" text="GPT-5 Turbo" />)
+ it('normalizes the query the same way the pickers filter (trim + lowercase)', () => {
+ const { container } = render(<HighlightMatches query=" GROK " text="grok-4.5" />)
- // mark covers "GPT-5" exactly — original characters, not folded ones.
- expect(marksOf(container)).toEqual(['GPT-5'])
- expect(container.textContent).toBe('GPT-5 Turbo')
+ expect(marksOf(container)).toEqual(['grok'])
})
- it('literal spaces in the label are marked as part of the range', () => {
- const { container } = render(<HighlightMatches query="3 8 f" text="Qwen3.8 Flash" />)
+ it('marks every term of a multi-term query (palette AND semantics)', () => {
+ const { container } = render(<HighlightMatches query={['open', 'set']} text="Open Settings" />)
- expect(marksOf(container)).toEqual(['3.8 F'])
+ expect(container.textContent).toBe('Open Settings')
+ expect(marksOf(container)).toEqual(['Open', 'Set'])
})
- it('prefix queries still mark (existing contract intact)', () => {
- const { container } = render(<HighlightMatches query="qwen3.8" text="Qwen3.8 Flash" />)
+ it('merges overlapping and adjacent term ranges into one mark', () => {
+ const { container } = render(<HighlightMatches query={['gro', 'rok']} text="Grok" />)
- expect(marksOf(container)).toEqual(['Qwen3.8'])
+ expect(marksOf(container)).toEqual(['Grok'])
})
-
- it('non-matching queries render plain text', () => {
- const { container } = render(<HighlightMatches query="zzz-9" text="Qwen3.8 Flash" />)
-
- expect(container.querySelector('mark')).toBeNull()
- expect(container.textContent).toBe('Qwen3.8 Flash')
- })
-})
+})
\ No newline at end of file
diff --git a/apps/desktop/src/components/ui/highlight-matches.tsx b/apps/desktop/src/components/ui/highlight-matches.tsx
index 1e685d2d67d..849f656a110 100644
--- a/apps/desktop/src/components/ui/highlight-matches.tsx
+++ b/apps/desktop/src/components/ui/highlight-matches.tsx
@@ -12,22 +12,19 @@ import { cn } from '@/lib/utils'
*
* The query must mirror the surface's OWN filter semantics, or the emphasis
* lies about why a row matched:
- * - a string for literal-substring filters (the model pickers) — spaces and
- * all, exactly what the filter saw, after the shared `searchFold` runs on
- * BOTH sides (separators -_. and case stop mattering, mirroring
- * `foldIncludes` — a hyphen query must light up the spaced label);
- * - a string[] for per-term AND matchers (the command palette) — every term
- * is marked wherever it occurs, overlapping/adjacent ranges merged.
- *
- * The fold is length-preserving, so ranges found in the folded text index
- * the original unchanged — marks slice the original characters.
+ * - literal matching by default, including per-term string[] queries in the
+ * command palette;
+ * - `foldSeparators` only for model surfaces whose filter uses `foldIncludes`.
+ * Replacing separators one-for-one keeps ranges aligned with the label.
*/
export function HighlightMatches({
className,
+ foldSeparators = false,
query,
text
}: {
className?: string
+ foldSeparators?: boolean
query: string | string[]
text: string
}) {
@@ -37,7 +34,9 @@ export function HighlightMatches({
return <>{text}</>
}
- const ranges = matchRanges(searchFold(text), terms.map(searchFold))
+ const ranges = foldSeparators
+ ? matchRanges(searchFold(text), terms.map(searchFold))
+ : matchRanges(text.toLowerCase(), terms)
if (ranges.length === 0) {
// No occurrence (the row matched on its id/slug/keywords, not this label).
diff --git a/apps/desktop/src/lib/text.test.ts b/apps/desktop/src/lib/text.test.ts
deleted file mode 100644
index c34b4a3ae07..00000000000
--- a/apps/desktop/src/lib/text.test.ts
+++ /dev/null
@@ -1,45 +0,0 @@
-import { describe, expect, it } from 'vitest'
-
-import { foldIncludes, searchFold } from './text'
-
-describe('searchFold', () => {
- it('folds separator characters to spaces, both directions equivalent', () => {
- expect(searchFold('qwen3.8-flash')).toBe('qwen3 8 flash')
- expect(searchFold('Qwen3.8 Flash')).toBe('qwen3 8 flash')
- expect(searchFold('GPT-5')).toBe('gpt 5')
- expect(searchFold('gpt 5')).toBe('gpt 5')
- expect(searchFold('Q4_K_XL')).toBe('q4 k xl')
- })
-
- it('is length-preserving (1 char in, 1 char out) so highlight indices survive', () => {
- for (const text of ['qwen3.8-flash', 'GPT-5', 'a--b__c..d', 'Grok 4.5 Retro', '']) {
- expect(searchFold(text).length).toBe(text.length)
- }
- })
-
- it('already-folded text is unchanged (idempotent)', () => {
- expect(searchFold('qwen3 8 flash')).toBe('qwen3 8 flash')
- })
-})
-
-describe('foldIncludes', () => {
- it('matches across the hyphen/space/dot/underscore separator difference', () => {
- expect(foldIncludes('Qwen3.8 Flash', 'qwen3.8-flash')).toBe(true)
- expect(foldIncludes('qwen3.8-flash', 'qwen3 8 flash')).toBe(true)
- expect(foldIncludes('GPT-5', 'gpt 5')).toBe(true)
- expect(foldIncludes('gpt-5', 'GPT.5')).toBe(true)
- expect(foldIncludes('Q4_K_XL', 'q4 k xl')).toBe(true)
- })
-
- it('is a superset of the plain-lowercase includes it replaces', () => {
- // Any query that matched before must still match.
- expect(foldIncludes('qwen3.8-flash', 'qwen3.8')).toBe(true)
- expect(foldIncludes('Qwen3.8 Flash', 'flash')).toBe(true)
- expect(foldIncludes('nous-portal', 'nous')).toBe(true)
- })
-
- it('still rejects genuinely different text', () => {
- expect(foldIncludes('Gemini Flash', 'qwen')).toBe(false)
- expect(foldIncludes('gpt-5', 'gpt-6')).toBe(false)
- })
-})