Skip to content

Commit

Permalink
feat: arrow up inside of composer will fill with the last user message (
Browse files Browse the repository at this point in the history
#663)

* feat: arrow up inside of composer will fill with the last user message

* fix: take the last user message instead the first one

* refactor: run format

---------

Co-authored-by: Khalil Najjar <knajjars@gmail.com>
  • Loading branch information
2 people authored and 1vn committed Aug 15, 2024
1 parent 19f846f commit 7e020ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Props = {
agent?: AgentPublic;
tools?: ManagedTool[];
chatWindowRef?: React.RefObject<HTMLDivElement>;
lastUserMessage?: ChatMessage;
};

export const Composer: React.FC<Props> = ({
Expand All @@ -39,6 +40,7 @@ export const Composer: React.FC<Props> = ({
onStop,
onUploadFile,
chatWindowRef,
lastUserMessage,
}) => {
const isDesktop = useIsDesktop();
const breakpoint = useBreakpoint();
Expand All @@ -65,6 +67,16 @@ export const Composer: React.FC<Props> = ({
onChange('');
}
}

if (e.key === 'ArrowUp' && value.trim() === '' && !isStreaming) {
onChange(lastUserMessage?.text || '');
setTimeout(() => {
textareaRef.current?.setSelectionRange(
textareaRef.current?.value.length,
textareaRef.current?.value.length
);
}, 0);
}
};

const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const Conversation: React.FC<Props> = ({ agent, tools, startOptionsEnabled = fal
onSend={handleSend}
onStop={handleStop}
onUploadFile={handleUploadFile}
lastUserMessage={messages.findLast((m) => m.type === 'user')}
/>
</>
}
Expand Down

0 comments on commit 7e020ae

Please sign in to comment.