refactor(cli): keyboard handling and AskUserDialog (#17414)

This commit is contained in:
Jacob Richman
2026-01-27 14:26:00 -08:00
committed by GitHub
parent 3103697ea7
commit b51323b40c
46 changed files with 1220 additions and 385 deletions
+12 -5
View File
@@ -30,6 +30,7 @@ export interface UseSelectionListOptions<T> {
showNumbers?: boolean;
wrapAround?: boolean;
focusKey?: string;
priority?: boolean;
}
export interface UseSelectionListResult {
@@ -288,6 +289,7 @@ export function useSelectionList<T>({
showNumbers = false,
wrapAround = true,
focusKey,
priority,
}: UseSelectionListOptions<T>): UseSelectionListResult {
const baseItems = toBaseItems(items);
@@ -397,17 +399,17 @@ export function useSelectionList<T>({
if (keyMatchers[Command.DIALOG_NAVIGATION_UP](key)) {
dispatch({ type: 'MOVE_UP' });
return;
return true;
}
if (keyMatchers[Command.DIALOG_NAVIGATION_DOWN](key)) {
dispatch({ type: 'MOVE_DOWN' });
return;
return true;
}
if (keyMatchers[Command.RETURN](key)) {
dispatch({ type: 'SELECT_CURRENT' });
return;
return true;
}
// Handle numeric input for quick selection
@@ -426,7 +428,7 @@ export function useSelectionList<T>({
numberInputTimer.current = setTimeout(() => {
numberInputRef.current = '';
}, NUMBER_INPUT_TIMEOUT_MS);
return;
return true;
}
if (targetIndex >= 0 && targetIndex < itemsLength) {
@@ -455,12 +457,17 @@ export function useSelectionList<T>({
// Number is out of bounds
numberInputRef.current = '';
}
return true;
}
return false;
},
[dispatch, itemsLength, showNumbers],
);
useKeypress(handleKeypress, { isActive: !!(isFocused && itemsLength > 0) });
useKeypress(handleKeypress, {
isActive: !!(isFocused && itemsLength > 0),
priority,
});
const setActiveIndex = (index: number) => {
dispatch({