mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-25 18:26:48 +08:00
Merge branch 'main' of https://github.com/Yidadaa/ChatGPT-Next-Web
This commit is contained in:
@@ -41,6 +41,8 @@ import chatStyle from "./chat.module.scss";
|
||||
|
||||
import { Input, Modal, showModal, showToast } from "./ui-lib";
|
||||
|
||||
import calcTextareaHeight from "../calcTextareaHeight";
|
||||
|
||||
const Markdown = dynamic(
|
||||
async () => memo((await import("./markdown")).Markdown),
|
||||
{
|
||||
@@ -331,6 +333,10 @@ function useScrollToBottom() {
|
||||
export function Chat(props: {
|
||||
showSideBar?: () => void;
|
||||
sideBarShowing?: boolean;
|
||||
autoSize: {
|
||||
minRows: number;
|
||||
maxRows?: number;
|
||||
};
|
||||
}) {
|
||||
type RenderMessage = Message & { preview?: boolean };
|
||||
|
||||
@@ -348,6 +354,7 @@ export function Chat(props: {
|
||||
const { submitKey, shouldSubmit } = useSubmitHandler();
|
||||
const { scrollRef, setAutoScroll } = useScrollToBottom();
|
||||
const [hitBottom, setHitBottom] = useState(false);
|
||||
const [textareaStyle, setTextareaStyle] = useState({});
|
||||
|
||||
const onChatBodyScroll = (e: HTMLElement) => {
|
||||
const isTouchBottom = e.scrollTop + e.clientHeight >= e.scrollHeight - 20;
|
||||
@@ -381,6 +388,14 @@ export function Chat(props: {
|
||||
dom.scrollTop = dom.scrollHeight - dom.offsetHeight + paddingBottomNum;
|
||||
};
|
||||
|
||||
// textarea has an adaptive height
|
||||
const resizeTextarea = () => {
|
||||
const dom = inputRef.current;
|
||||
if (!dom) return;
|
||||
const { minRows, maxRows } = props.autoSize;
|
||||
setTextareaStyle(calcTextareaHeight(dom, minRows, maxRows));
|
||||
};
|
||||
|
||||
// only search prompts when user input is short
|
||||
const SEARCH_TEXT_LIMIT = 30;
|
||||
const onInput = (text: string) => {
|
||||
@@ -512,6 +527,12 @@ export function Chat(props: {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
// Textarea Adaptive height
|
||||
useEffect(() => {
|
||||
resizeTextarea();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [userInput]);
|
||||
|
||||
return (
|
||||
<div className={styles.chat} key={session.id}>
|
||||
<div className={styles["window-header"]}>
|
||||
@@ -670,8 +691,8 @@ export function Chat(props: {
|
||||
<textarea
|
||||
ref={inputRef}
|
||||
className={styles["chat-input"]}
|
||||
style={textareaStyle}
|
||||
placeholder={Locale.Chat.Input(submitKey)}
|
||||
rows={2}
|
||||
onInput={(e) => onInput(e.currentTarget.value)}
|
||||
value={userInput}
|
||||
onKeyDown={onInputKeyDown}
|
||||
|
||||
@@ -407,7 +407,7 @@
|
||||
background-color: var(--white);
|
||||
color: var(--black);
|
||||
font-family: inherit;
|
||||
padding: 10px 14px 50px;
|
||||
padding: 10px 90px 10px 14px;
|
||||
resize: none;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
@@ -192,6 +192,7 @@ function _Home() {
|
||||
key="chat"
|
||||
showSideBar={() => setShowSideBar(true)}
|
||||
sideBarShowing={showSideBar}
|
||||
autoSize={{ minRows: 2, maxRows: 6 }}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -67,7 +67,7 @@ export function Markdown(props: { content: string }) {
|
||||
components={{
|
||||
pre: PreCode,
|
||||
}}
|
||||
linkTarget={'_blank'}
|
||||
linkTarget={"_blank"}
|
||||
>
|
||||
{props.content}
|
||||
</ReactMarkdown>
|
||||
|
||||
Reference in New Issue
Block a user