feat: allow editing queued messages with up arrow key (#10392)

Co-authored-by: Akhil Appana <akhilapp@google.com>
This commit is contained in:
Akhil Appana
2025-10-16 17:04:13 -07:00
committed by GitHub
parent 9049f8f8ae
commit 22f725eb08
9 changed files with 399 additions and 8 deletions

View File

@@ -75,6 +75,7 @@ export interface InputPromptProps {
isEmbeddedShellFocused?: boolean;
setQueueErrorMessage: (message: string | null) => void;
streamingState: StreamingState;
popAllMessages?: (onPop: (messages: string | undefined) => void) => void;
}
// The input content, input container, and input suggestions list may have different widths
@@ -113,6 +114,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
isEmbeddedShellFocused,
setQueueErrorMessage,
streamingState,
popAllMessages,
}) => {
const kittyProtocol = useKittyKeyboardProtocol();
const isShellFocused = useShellFocusState();
@@ -288,6 +290,23 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
resetCommandSearchCompletionState,
]);
// Helper function to handle loading queued messages into input
// Returns true if we should continue with input history navigation
const tryLoadQueuedMessages = useCallback(() => {
if (buffer.text.trim() === '' && popAllMessages) {
popAllMessages((allMessages) => {
if (allMessages) {
buffer.setText(allMessages);
} else {
// No queued messages, proceed with input history
inputHistory.navigateUp();
}
});
return true; // We handled the up arrow key
}
return false;
}, [buffer, popAllMessages, inputHistory]);
// Handle clipboard image pasting with Ctrl+V
const handleClipboardImage = useCallback(async () => {
try {
@@ -597,6 +616,12 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
}
if (keyMatchers[Command.HISTORY_UP](key)) {
// Check for queued messages first when input is empty
// If no queued messages, inputHistory.navigateUp() is called inside tryLoadQueuedMessages
if (tryLoadQueuedMessages()) {
return;
}
// Only navigate history if popAllMessages doesn't exist
inputHistory.navigateUp();
return;
}
@@ -610,6 +635,12 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
(buffer.allVisualLines.length === 1 ||
(buffer.visualCursor[0] === 0 && buffer.visualScrollRow === 0))
) {
// Check for queued messages first when input is empty
// If no queued messages, inputHistory.navigateUp() is called inside tryLoadQueuedMessages
if (tryLoadQueuedMessages()) {
return;
}
// Only navigate history if popAllMessages doesn't exist
inputHistory.navigateUp();
return;
}
@@ -753,6 +784,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
commandSearchActive,
commandSearchCompletion,
kittyProtocol.supported,
tryLoadQueuedMessages,
],
);