File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed
packages/core/src/prompts Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @clack/prompts " : minor
3+ ---
4+
5+ add wraparound behaviour to autocomplete components
Original file line number Diff line number Diff line change 11import type { Key } from 'node:readline' ;
22import color from 'picocolors' ;
33import Prompt , { type PromptOptions } from './prompt.js' ;
4+ import { findCursor } from '../utils/cursor.js' ;
45
56interface OptionLike {
67 value : unknown ;
78 label ?: string ;
9+ disabled ?: boolean ;
810}
911
1012type FilterFunction < T extends OptionLike > = ( search : string , opt : T ) => boolean ;
@@ -143,10 +145,7 @@ export default class AutocompletePrompt<T extends OptionLike> extends Prompt<
143145
144146 // Start navigation mode with up/down arrows
145147 if ( isUpKey || isDownKey ) {
146- this . #cursor = Math . max (
147- 0 ,
148- Math . min ( this . #cursor + ( isUpKey ? - 1 : 1 ) , this . filteredOptions . length - 1 )
149- ) ;
148+ this . #cursor = findCursor ( this . #cursor, isUpKey ? - 1 : 1 , this . filteredOptions ) ;
150149 this . focusedValue = this . filteredOptions [ this . #cursor] ?. value ;
151150 if ( ! this . multiple ) {
152151 this . selectedValues = [ this . focusedValue ] ;
You can’t perform that action at this time.
0 commit comments