diff --git a/src/uix/soma/components/command/score.ts b/src/libs/strings/fuzzy-score.ts similarity index 96% rename from src/uix/soma/components/command/score.ts rename to src/libs/strings/fuzzy-score.ts index 43a49f255..5d49af801 100644 --- a/src/uix/soma/components/command/score.ts +++ b/src/libs/strings/fuzzy-score.ts @@ -75,10 +75,10 @@ function normalize(s: string): string { } /** - * Default scorer. Returns a float in [0, 1]; 0 means no match. + * Default fuzzy scorer. Returns a float in [0, 1]; 0 means no match. * Keywords are joined with the value and scored as a single string. */ -export function computeCommandScore( +export function computeFuzzyScore( value: string, search: string, keywords?: readonly string[] diff --git a/src/libs/strings/index.ts b/src/libs/strings/index.ts index 521caef81..520c50ae6 100644 --- a/src/libs/strings/index.ts +++ b/src/libs/strings/index.ts @@ -1 +1,2 @@ export * from './utilities'; +export * from './fuzzy-score'; diff --git a/src/uix/soma/components/command/command-provider.svelte.test.ts b/src/uix/soma/components/command/command-provider.svelte.test.ts index d0d1ce72a..ad3c7c9c2 100644 --- a/src/uix/soma/components/command/command-provider.svelte.test.ts +++ b/src/uix/soma/components/command/command-provider.svelte.test.ts @@ -10,7 +10,7 @@ import { Soma } from '$soma/core/soma.svelte'; import { createSomaRuntime, type SomaRuntimeSources } from '$soma/runtime.svelte'; import { CommandProvider } from './command-provider.svelte'; -import { computeCommandScore } from './score'; +import { computeFuzzyScore } from '$libs/strings'; function withEffectRoot(fn: () => T): { result: T; cleanup: () => void } { let result!: T; @@ -46,7 +46,7 @@ function createCommandOpts() { search: state(''), label: state('Commands'), shouldFilter: state(true), - filter: state(computeCommandScore), + filter: state(computeFuzzyScore), loop: state(false), vimBindings: state(false), columns: state(1), diff --git a/src/uix/soma/components/command/command-provider.svelte.ts b/src/uix/soma/components/command/command-provider.svelte.ts index 0d777af5c..2f8bbdf05 100644 --- a/src/uix/soma/components/command/command-provider.svelte.ts +++ b/src/uix/soma/components/command/command-provider.svelte.ts @@ -15,7 +15,6 @@ function dbg(_label: string, _payload?: unknown): void {} import { Soma } from '../../core/soma.svelte'; import { COMMAND_LANGS } from './langs'; -import { computeCommandScore } from './score'; import type { CommandFilterFn, CommandSnippetProps } from './types'; import { commandMorfo } from '../../../morfo/components/command'; diff --git a/src/uix/soma/components/command/components/command-dialog.svelte b/src/uix/soma/components/command/components/command-dialog.svelte index cadb8fef5..414de6b7f 100644 --- a/src/uix/soma/components/command/components/command-dialog.svelte +++ b/src/uix/soma/components/command/components/command-dialog.svelte @@ -3,7 +3,7 @@ import * as Dialog from '../../dialog'; import Portal from '../../internal/portal.svelte'; import Command from './command.svelte'; - import { computeCommandScore } from '../score'; + import { computeFuzzyScore } from '$libs/strings'; import type { CommandFilterFn, CommandSnippetProps } from '../types'; import type { OnChangeFn } from '../../../types'; @@ -47,7 +47,7 @@ search = $bindable(''), onSearchChange = () => {}, shouldFilter = true, - filter = computeCommandScore, + filter = computeFuzzyScore, loop = false, vimBindings = true, columns = 1, diff --git a/src/uix/soma/components/command/components/command.svelte b/src/uix/soma/components/command/components/command.svelte index 266a58a10..dbf54118e 100644 --- a/src/uix/soma/components/command/components/command.svelte +++ b/src/uix/soma/components/command/components/command.svelte @@ -7,7 +7,7 @@ import { createId } from '../../../id'; import { CommandProvider } from '../command-provider.svelte'; import type { CommandProps } from '../types'; - import { computeCommandScore } from '../score'; + import { computeFuzzyScore } from '$libs/strings'; import { Soma } from '../../../core/soma.svelte'; const uid = $props.id(); @@ -22,7 +22,7 @@ search = $bindable(''), onSearchChange = () => {}, shouldFilter = true, - filter = computeCommandScore, + filter = computeFuzzyScore, loop = false, vimBindings = true, columns = 1, diff --git a/src/uix/soma/components/command/exports.ts b/src/uix/soma/components/command/exports.ts index ebb2aff14..d7c31854c 100644 --- a/src/uix/soma/components/command/exports.ts +++ b/src/uix/soma/components/command/exports.ts @@ -13,7 +13,7 @@ export { default as Empty } from './components/command-empty.svelte'; export { default as Loading } from './components/command-loading.svelte'; export { default as Separator } from './components/command-separator.svelte'; -export { computeCommandScore } from './score'; +export { computeFuzzyScore as computeCommandScore } from '$libs/strings'; export type { CommandFilterFn,