This commit is contained in:
parent
761ffc6338
commit
6aac93ee07
|
@ -95,7 +95,9 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||||
const inputHistory = useInputHistory({
|
const inputHistory = useInputHistory({
|
||||||
userMessages,
|
userMessages,
|
||||||
onSubmit: handleSubmitAndClear,
|
onSubmit: handleSubmitAndClear,
|
||||||
isActive: !completion.showSuggestions && !shellModeActive,
|
isActive:
|
||||||
|
(!completion.showSuggestions || completion.suggestions.length === 1) &&
|
||||||
|
!shellModeActive,
|
||||||
currentQuery: buffer.text,
|
currentQuery: buffer.text,
|
||||||
onChange: customSetTextAndResetCompletionSignal,
|
onChange: customSetTextAndResetCompletionSignal,
|
||||||
});
|
});
|
||||||
|
@ -265,13 +267,15 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
if (completion.showSuggestions) {
|
if (completion.showSuggestions) {
|
||||||
if (key.name === 'up') {
|
if (completion.suggestions.length > 1) {
|
||||||
completion.navigateUp();
|
if (key.name === 'up') {
|
||||||
return;
|
completion.navigateUp();
|
||||||
}
|
return;
|
||||||
if (key.name === 'down') {
|
}
|
||||||
completion.navigateDown();
|
if (key.name === 'down') {
|
||||||
return;
|
completion.navigateDown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.name === 'tab' || (key.name === 'return' && !key.ctrl)) {
|
if (key.name === 'tab' || (key.name === 'return' && !key.ctrl)) {
|
||||||
|
@ -286,61 +290,61 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if (!shellModeActive) {
|
|
||||||
if (key.ctrl && key.name === 'p') {
|
|
||||||
inputHistory.navigateUp();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (key.ctrl && key.name === 'n') {
|
|
||||||
inputHistory.navigateDown();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Handle arrow-up/down for history on single-line or at edges
|
|
||||||
if (
|
|
||||||
key.name === 'up' &&
|
|
||||||
(buffer.allVisualLines.length === 1 ||
|
|
||||||
(buffer.visualCursor[0] === 0 && buffer.visualScrollRow === 0))
|
|
||||||
) {
|
|
||||||
inputHistory.navigateUp();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
key.name === 'down' &&
|
|
||||||
(buffer.allVisualLines.length === 1 ||
|
|
||||||
buffer.visualCursor[0] === buffer.allVisualLines.length - 1)
|
|
||||||
) {
|
|
||||||
inputHistory.navigateDown();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Shell History Navigation
|
|
||||||
if (key.name === 'up') {
|
|
||||||
const prevCommand = shellHistory.getPreviousCommand();
|
|
||||||
if (prevCommand !== null) buffer.setText(prevCommand);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (key.name === 'down') {
|
|
||||||
const nextCommand = shellHistory.getNextCommand();
|
|
||||||
if (nextCommand !== null) buffer.setText(nextCommand);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key.name === 'return' && !key.ctrl && !key.meta && !key.paste) {
|
if (!shellModeActive) {
|
||||||
if (buffer.text.trim()) {
|
if (key.ctrl && key.name === 'p') {
|
||||||
const [row, col] = buffer.cursor;
|
inputHistory.navigateUp();
|
||||||
const line = buffer.lines[row];
|
|
||||||
const charBefore = col > 0 ? cpSlice(line, col - 1, col) : '';
|
|
||||||
if (charBefore === '\\') {
|
|
||||||
buffer.backspace();
|
|
||||||
buffer.newline();
|
|
||||||
} else {
|
|
||||||
handleSubmitAndClear(buffer.text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (key.ctrl && key.name === 'n') {
|
||||||
|
inputHistory.navigateDown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Handle arrow-up/down for history on single-line or at edges
|
||||||
|
if (
|
||||||
|
key.name === 'up' &&
|
||||||
|
(buffer.allVisualLines.length === 1 ||
|
||||||
|
(buffer.visualCursor[0] === 0 && buffer.visualScrollRow === 0))
|
||||||
|
) {
|
||||||
|
inputHistory.navigateUp();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
key.name === 'down' &&
|
||||||
|
(buffer.allVisualLines.length === 1 ||
|
||||||
|
buffer.visualCursor[0] === buffer.allVisualLines.length - 1)
|
||||||
|
) {
|
||||||
|
inputHistory.navigateDown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Shell History Navigation
|
||||||
|
if (key.name === 'up') {
|
||||||
|
const prevCommand = shellHistory.getPreviousCommand();
|
||||||
|
if (prevCommand !== null) buffer.setText(prevCommand);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (key.name === 'down') {
|
||||||
|
const nextCommand = shellHistory.getNextCommand();
|
||||||
|
if (nextCommand !== null) buffer.setText(nextCommand);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key.name === 'return' && !key.ctrl && !key.meta && !key.paste) {
|
||||||
|
if (buffer.text.trim()) {
|
||||||
|
const [row, col] = buffer.cursor;
|
||||||
|
const line = buffer.lines[row];
|
||||||
|
const charBefore = col > 0 ? cpSlice(line, col - 1, col) : '';
|
||||||
|
if (charBefore === '\\') {
|
||||||
|
buffer.backspace();
|
||||||
|
buffer.newline();
|
||||||
|
} else {
|
||||||
|
handleSubmitAndClear(buffer.text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Newline insertion
|
// Newline insertion
|
||||||
|
|
Loading…
Reference in New Issue