MCPcopy Create free account
hub / github.com/bombshell-dev/clack / getCursorForValue

Function getCursorForValue

packages/core/src/prompts/autocomplete.ts:14–32  ·  view source on GitHub ↗
(
	selected: T['value'] | undefined,
	items: T[]
)

Source from the content-addressed store, hash-verified

12type FilterFunction<T extends OptionLike> = (search: string, opt: T) => boolean;
13
14function getCursorForValue<T extends OptionLike>(
15 selected: T['value'] | undefined,
16 items: T[]
17): number {
18 if (selected === undefined) {
19 return 0;
20 }
21
22 const currLength = items.length;
23
24 // If filtering changed the available options, update cursor
25 if (currLength === 0) {
26 return 0;
27 }
28
29 // Try to maintain the same selected item
30 const index = items.findIndex((item) => item.value === selected);
31 return index !== -1 ? index : 0;
32}
33
34function defaultFilter<T extends OptionLike>(input: string, option: T): boolean {
35 const label = option.label ?? String(option.value);

Callers 1

#onUserInputChangedMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected