summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/components/InputPrompt.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/cli/src/ui/components/InputPrompt.tsx')
-rw-r--r--packages/cli/src/ui/components/InputPrompt.tsx39
1 files changed, 38 insertions, 1 deletions
diff --git a/packages/cli/src/ui/components/InputPrompt.tsx b/packages/cli/src/ui/components/InputPrompt.tsx
index 1c3d2a07..b1e05554 100644
--- a/packages/cli/src/ui/components/InputPrompt.tsx
+++ b/packages/cli/src/ui/components/InputPrompt.tsx
@@ -24,6 +24,8 @@ interface InputPromptProps {
userMessages: readonly string[];
navigateSuggestionUp: () => void;
navigateSuggestionDown: () => void;
+ setEditorState: (updater: (prevState: EditorState) => EditorState) => void;
+ onClearScreen: () => void;
}
export interface EditorState {
@@ -44,6 +46,8 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
navigateSuggestionUp,
navigateSuggestionDown,
resetCompletion,
+ setEditorState,
+ onClearScreen,
}) => {
const handleSubmit = useCallback(
(submittedValue: string) => {
@@ -106,7 +110,12 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
);
const inputPreprocessor = useCallback(
- (input: string, key: Key) => {
+ (
+ input: string,
+ key: Key,
+ _currentText?: string,
+ _cursorOffset?: number,
+ ) => {
if (showSuggestions) {
if (key.upArrow) {
navigateSuggestionUp();
@@ -136,6 +145,31 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
resetCompletion();
return true;
}
+ } else {
+ // Keybindings when suggestions are not shown
+ if (key.ctrl && input === 'a') {
+ setEditorState((s) => ({ key: s.key + 1, initialCursorOffset: 0 }));
+ return true;
+ }
+ if (key.ctrl && input === 'e') {
+ setEditorState((s) => ({
+ key: s.key + 1,
+ initialCursorOffset: query.length,
+ }));
+ return true;
+ }
+ if (key.ctrl && input === 'l') {
+ onClearScreen();
+ return true;
+ }
+ if (key.ctrl && input === 'p') {
+ inputHistory.navigateUp();
+ return true;
+ }
+ if (key.ctrl && input === 'n') {
+ inputHistory.navigateDown();
+ return true;
+ }
}
return false;
},
@@ -149,6 +183,9 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
resetCompletion,
activeSuggestionIndex,
handleSubmit,
+ inputHistory,
+ setEditorState,
+ onClearScreen,
],
);