Move command scorer to shared strings lib

active-uix
dev 5 months ago
parent e1a21269ec
commit 4829ce1321

@ -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. * Keywords are joined with the value and scored as a single string.
*/ */
export function computeCommandScore( export function computeFuzzyScore(
value: string, value: string,
search: string, search: string,
keywords?: readonly string[] keywords?: readonly string[]

@ -1 +1,2 @@
export * from './utilities'; export * from './utilities';
export * from './fuzzy-score';

@ -10,7 +10,7 @@ import { Soma } from '$soma/core/soma.svelte';
import { createSomaRuntime, type SomaRuntimeSources } from '$soma/runtime.svelte'; import { createSomaRuntime, type SomaRuntimeSources } from '$soma/runtime.svelte';
import { CommandProvider } from './command-provider.svelte'; import { CommandProvider } from './command-provider.svelte';
import { computeCommandScore } from './score'; import { computeFuzzyScore } from '$libs/strings';
function withEffectRoot<T>(fn: () => T): { result: T; cleanup: () => void } { function withEffectRoot<T>(fn: () => T): { result: T; cleanup: () => void } {
let result!: T; let result!: T;
@ -46,7 +46,7 @@ function createCommandOpts() {
search: state(''), search: state(''),
label: state<string | undefined>('Commands'), label: state<string | undefined>('Commands'),
shouldFilter: state(true), shouldFilter: state(true),
filter: state(computeCommandScore), filter: state(computeFuzzyScore),
loop: state(false), loop: state(false),
vimBindings: state(false), vimBindings: state(false),
columns: state(1), columns: state(1),

@ -15,7 +15,6 @@ function dbg(_label: string, _payload?: unknown): void {}
import { Soma } from '../../core/soma.svelte'; import { Soma } from '../../core/soma.svelte';
import { COMMAND_LANGS } from './langs'; import { COMMAND_LANGS } from './langs';
import { computeCommandScore } from './score';
import type { CommandFilterFn, CommandSnippetProps } from './types'; import type { CommandFilterFn, CommandSnippetProps } from './types';
import { commandMorfo } from '../../../morfo/components/command'; import { commandMorfo } from '../../../morfo/components/command';

@ -3,7 +3,7 @@
import * as Dialog from '../../dialog'; import * as Dialog from '../../dialog';
import Portal from '../../internal/portal.svelte'; import Portal from '../../internal/portal.svelte';
import Command from './command.svelte'; import Command from './command.svelte';
import { computeCommandScore } from '../score'; import { computeFuzzyScore } from '$libs/strings';
import type { CommandFilterFn, CommandSnippetProps } from '../types'; import type { CommandFilterFn, CommandSnippetProps } from '../types';
import type { OnChangeFn } from '../../../types'; import type { OnChangeFn } from '../../../types';
@ -47,7 +47,7 @@
search = $bindable(''), search = $bindable(''),
onSearchChange = () => {}, onSearchChange = () => {},
shouldFilter = true, shouldFilter = true,
filter = computeCommandScore, filter = computeFuzzyScore,
loop = false, loop = false,
vimBindings = true, vimBindings = true,
columns = 1, columns = 1,

@ -7,7 +7,7 @@
import { createId } from '../../../id'; import { createId } from '../../../id';
import { CommandProvider } from '../command-provider.svelte'; import { CommandProvider } from '../command-provider.svelte';
import type { CommandProps } from '../types'; import type { CommandProps } from '../types';
import { computeCommandScore } from '../score'; import { computeFuzzyScore } from '$libs/strings';
import { Soma } from '../../../core/soma.svelte'; import { Soma } from '../../../core/soma.svelte';
const uid = $props.id(); const uid = $props.id();
@ -22,7 +22,7 @@
search = $bindable(''), search = $bindable(''),
onSearchChange = () => {}, onSearchChange = () => {},
shouldFilter = true, shouldFilter = true,
filter = computeCommandScore, filter = computeFuzzyScore,
loop = false, loop = false,
vimBindings = true, vimBindings = true,
columns = 1, columns = 1,

@ -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 Loading } from './components/command-loading.svelte';
export { default as Separator } from './components/command-separator.svelte'; export { default as Separator } from './components/command-separator.svelte';
export { computeCommandScore } from './score'; export { computeFuzzyScore as computeCommandScore } from '$libs/strings';
export type { export type {
CommandFilterFn, CommandFilterFn,

Loading…
Cancel
Save

Powered by TurnKey Linux.