Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions src/components/AIView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,26 @@ const AIViewInner: React.FC<AIViewProps> = ({
setEditingMessage({ id: messageId, content });
}, []);

const handleEditLastUserMessage = useCallback(() => {
if (!workspaceState) return;
const mergedMessages = mergeConsecutiveStreamErrors(workspaceState.messages);
const lastUserMessage = [...mergedMessages]
.reverse()
.find((msg): msg is Extract<DisplayedMessage, { type: "user" }> => msg.type === "user");
if (lastUserMessage) {
setEditingMessage({ id: lastUserMessage.historyId, content: lastUserMessage.content });
setAutoScroll(false); // Show jump-to-bottom indicator

// Scroll to the message being edited
requestAnimationFrame(() => {
const element = contentRef.current?.querySelector(
`[data-message-id="${lastUserMessage.historyId}"]`
);
element?.scrollIntoView({ behavior: "smooth", block: "center" });
});
}
}, [workspaceState, contentRef, setAutoScroll]);

const handleCancelEdit = useCallback(() => {
setEditingMessage(undefined);
}, []);
Expand Down Expand Up @@ -464,12 +484,18 @@ const AIViewInner: React.FC<AIViewProps> = ({

return (
<React.Fragment key={msg.id}>
<MessageRenderer
message={msg}
onEditUserMessage={handleEditUserMessage}
workspaceId={workspaceId}
isCompacting={isCompacting}
/>
<div
data-message-id={
msg.type !== "history-hidden" ? msg.historyId : undefined
}
>
<MessageRenderer
message={msg}
onEditUserMessage={handleEditUserMessage}
workspaceId={workspaceId}
isCompacting={isCompacting}
/>
</div>
{isAtCutoff && (
<EditBarrier>
⚠️ Messages below this line will be removed when you submit the edit
Expand Down Expand Up @@ -530,6 +556,7 @@ const AIViewInner: React.FC<AIViewProps> = ({
isCompacting={isCompacting}
editingMessage={editingMessage}
onCancelEdit={handleCancelEdit}
onEditLastUserMessage={handleEditLastUserMessage}
canInterrupt={canInterrupt}
onReady={handleChatInputReady}
/>
Expand Down
25 changes: 12 additions & 13 deletions src/components/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export interface ChatInputProps {
isCompacting?: boolean;
editingMessage?: { id: string; content: string };
onCancelEdit?: () => void;
onEditLastUserMessage?: () => void;
canInterrupt?: boolean; // Whether Esc can be used to interrupt streaming
onReady?: (api: ChatInputAPI) => void; // Callback with focus method
}
Expand Down Expand Up @@ -334,6 +335,7 @@ export const ChatInput: React.FC<ChatInputProps> = ({
isCompacting = false,
editingMessage,
onCancelEdit,
onEditLastUserMessage,
canInterrupt = false,
onReady,
}) => {
Expand Down Expand Up @@ -808,13 +810,16 @@ export const ChatInput: React.FC<ChatInputProps> = ({
}
}

// Handle escape - let VimTextArea handle it (for Vim mode transitions)
// Edit canceling is handled by Ctrl+Q above
// Stream interruption is handled by Ctrl+C (INTERRUPT_STREAM keybind)
if (matchesKeybind(e, KEYBINDS.CANCEL)) {
// Do not preventDefault here: allow VimTextArea or other handlers (like suggestions) to process ESC
// Handle up arrow on empty input - edit last user message
if (e.key === "ArrowUp" && !editingMessage && input.trim() === "" && onEditLastUserMessage) {
e.preventDefault();
onEditLastUserMessage();
return;
}

// Note: ESC handled by VimTextArea (for mode transitions) and CommandSuggestions (for dismissal)
// Edit canceling is Ctrl+Q, stream interruption is Ctrl+C

// Don't handle keys if command suggestions are visible
if (
showCommandSuggestions &&
Expand All @@ -824,13 +829,7 @@ export const ChatInput: React.FC<ChatInputProps> = ({
return; // Let CommandSuggestions handle it
}

// Handle newline
if (matchesKeybind(e, KEYBINDS.NEW_LINE)) {
// Allow newline (default behavior)
return;
}

// Handle send message
// Handle send message (Shift+Enter for newline is default behavior)
if (matchesKeybind(e, KEYBINDS.SEND_MESSAGE)) {
e.preventDefault();
void handleSend();
Expand All @@ -840,7 +839,7 @@ export const ChatInput: React.FC<ChatInputProps> = ({
// Build placeholder text based on current state
const placeholder = (() => {
if (editingMessage) {
return `Edit your message... (${formatKeybind(KEYBINDS.CANCEL)} to cancel edit, ${formatKeybind(KEYBINDS.SEND_MESSAGE)} to send)`;
return `Edit your message... (${formatKeybind(KEYBINDS.CANCEL_EDIT)} to cancel, ${formatKeybind(KEYBINDS.SEND_MESSAGE)} to send)`;
}
if (isCompacting) {
return `Compacting... (${formatKeybind(KEYBINDS.INTERRUPT_STREAM)} to cancel)`;
Expand Down