θΏ™ζ˜―indexlocζδΎ›ηš„ζœεŠ‘οΌŒδΈθ¦θΎ“ε…₯任何密码
Skip to content

Improve PromptInput component #3266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ const MAX_EDIT_STACK_SIZE = 100;
export default function PromptInput({
submit,
onChange,
inputDisabled,
buttonDisabled,
isStreaming,
sendCommand,
attachments = [],
}) {
Expand All @@ -49,11 +48,6 @@ export default function PromptInput({
setPromptInput(e?.detail ?? "");
}

function resetTextAreaHeight() {
if (!textareaRef.current) return;
textareaRef.current.style.height = "auto";
}

useEffect(() => {
if (!!window)
window.addEventListener(PROMPT_INPUT_EVENT, handlePromptUpdate);
Expand All @@ -62,9 +56,9 @@ export default function PromptInput({
}, []);

useEffect(() => {
if (!inputDisabled && textareaRef.current) textareaRef.current.focus();
if (!isStreaming && textareaRef.current) textareaRef.current.focus();
resetTextAreaHeight();
}, [inputDisabled]);
}, [isStreaming]);

/**
* Save the current state before changes
Expand Down Expand Up @@ -115,6 +109,7 @@ export default function PromptInput({
// Is simple enter key press w/o shift key
if (event.keyCode === 13 && !event.shiftKey) {
event.preventDefault();
if (isStreaming) return;
return submit(event);
}

Expand Down Expand Up @@ -264,7 +259,6 @@ export default function PromptInput({
handlePasteEvent(e);
}}
required={true}
disabled={inputDisabled}
onFocus={() => setFocused(true)}
onBlur={(e) => {
setFocused(false);
Expand All @@ -274,7 +268,7 @@ export default function PromptInput({
className={`border-none cursor-text max-h-[50vh] md:max-h-[350px] md:min-h-[40px] mx-2 md:mx-0 pt-[12px] w-full leading-5 md:text-md text-white bg-transparent placeholder:text-white/60 light:placeholder:text-theme-text-primary resize-none active:outline-none focus:outline-none flex-grow ${textSizeClass}`}
placeholder={"Send a message"}
/>
{buttonDisabled ? (
{isStreaming ? (
<StopGenerationButton />
) : (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ export default function ChatContainer({ workspace, knownHistory = [] }) {
<PromptInput
submit={handleSubmit}
onChange={handleMessageChange}
inputDisabled={loadingResponse}
buttonDisabled={loadingResponse}
isStreaming={loadingResponse}
sendCommand={sendCommand}
attachments={files}
/>
Expand Down