mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 08:47:44 +00:00
Implement additional readline-like keybindings, including alt-left arrow and alt-right arrow. (#443)
This change adds keybinding support for: - `Ctrl+B`: Moves the cursor backward one character. - `Ctrl+F`: Moves the cursor forward one character. - `Alt+Left Arrow`: Moves the cursor backward one word. - `Alt+Right Arrow`: Moves the cursor forward one word. Closes b/411469305.
This commit is contained in:
@@ -24,7 +24,6 @@ interface InputPromptProps {
|
||||
userMessages: readonly string[];
|
||||
navigateSuggestionUp: () => void;
|
||||
navigateSuggestionDown: () => void;
|
||||
setEditorState: (updater: (prevState: EditorState) => EditorState) => void;
|
||||
onClearScreen: () => void;
|
||||
shellModeActive: boolean;
|
||||
setShellModeActive: (value: boolean) => void;
|
||||
@@ -48,7 +47,6 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
navigateSuggestionUp,
|
||||
navigateSuggestionDown,
|
||||
resetCompletion,
|
||||
setEditorState,
|
||||
onClearScreen,
|
||||
shellModeActive,
|
||||
setShellModeActive,
|
||||
@@ -114,12 +112,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
);
|
||||
|
||||
const inputPreprocessor = useCallback(
|
||||
(
|
||||
input: string,
|
||||
key: Key,
|
||||
_currentText?: string,
|
||||
_cursorOffset?: number,
|
||||
) => {
|
||||
(input: string, key: Key) => {
|
||||
if (input === '!' && query === '' && !showSuggestions) {
|
||||
setShellModeActive(!shellModeActive);
|
||||
onChangeAndMoveCursor(''); // Clear the '!' from input
|
||||
@@ -156,17 +149,6 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
}
|
||||
} 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;
|
||||
@@ -193,7 +175,6 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
activeSuggestionIndex,
|
||||
handleSubmit,
|
||||
inputHistory,
|
||||
setEditorState,
|
||||
onClearScreen,
|
||||
shellModeActive,
|
||||
setShellModeActive,
|
||||
|
||||
Reference in New Issue
Block a user