MCPcopy Create free account
hub / github.com/Effect-TS/effect / updateAutoCompleteState

Function updateAutoCompleteState

packages/effect/src/unstable/cli/Prompt.ts:3073–3086  ·  view source on GitHub ↗
(
  state: AutoCompleteState,
  options: AutoCompleteOptionsReq<A>,
  query: string
)

Source from the content-addressed store, hash-verified

3071}
3072
3073const updateAutoCompleteState = <A>(
3074 state: AutoCompleteState,
3075 options: AutoCompleteOptionsReq<A>,
3076 query: string
3077): AutoCompleteState => {
3078 const filtered = filterAutoCompleteChoices(options.choices, query)
3079 if (filtered.length === 0) {
3080 return { ...state, query, filtered, index: 0 }
3081 }
3082 if (filtered.includes(state.index)) {
3083 return { ...state, query, filtered }
3084 }
3085 return { ...state, query, filtered, index: filtered[0] }
3086}
3087
3088const autoCompleteCursor = (state: AutoCompleteState) =>
3089 Option.getOrElse(Arr.findFirstIndex(state.filtered, (index) => index === state.index), () => 0)

Callers 3

processAutoCompleteClearFunction · 0.85
processAutoCompleteInputFunction · 0.85

Calls 1

Tested by

no test coverage detected