forked from XiaoMo/ChatGPT-Next-Web
fix: #34 only auto scroll when textbox is focused
This commit is contained in:
parent
86507fa569
commit
1e89fe14ac
@ -205,7 +205,7 @@ export function Chat(props: { showSideBar?: () => void }) {
|
|||||||
const latestMessageRef = useRef<HTMLDivElement>(null);
|
const latestMessageRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
// wont scroll while hovering messages
|
// wont scroll while hovering messages
|
||||||
const [hoveringMessage, setHoveringMessage] = useState(false);
|
const [autoScroll, setAutoScroll] = useState(false);
|
||||||
|
|
||||||
// preview messages
|
// preview messages
|
||||||
const messages = (session.messages as RenderMessage[])
|
const messages = (session.messages as RenderMessage[])
|
||||||
@ -238,7 +238,7 @@ export function Chat(props: { showSideBar?: () => void }) {
|
|||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const dom = latestMessageRef.current;
|
const dom = latestMessageRef.current;
|
||||||
if (dom && !isIOS() && !hoveringMessage) {
|
if (dom && !isIOS() && autoScroll) {
|
||||||
dom.scrollIntoView({
|
dom.scrollIntoView({
|
||||||
behavior: "smooth",
|
behavior: "smooth",
|
||||||
block: "end",
|
block: "end",
|
||||||
@ -293,15 +293,7 @@ export function Chat(props: { showSideBar?: () => void }) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div className={styles["chat-body"]}>
|
||||||
className={styles["chat-body"]}
|
|
||||||
onMouseOver={() => {
|
|
||||||
setHoveringMessage(true);
|
|
||||||
}}
|
|
||||||
onMouseOut={() => {
|
|
||||||
setHoveringMessage(false);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{messages.map((message, i) => {
|
{messages.map((message, i) => {
|
||||||
const isUser = message.role === "user";
|
const isUser = message.role === "user";
|
||||||
|
|
||||||
@ -385,6 +377,9 @@ export function Chat(props: { showSideBar?: () => void }) {
|
|||||||
onInput={(e) => setUserInput(e.currentTarget.value)}
|
onInput={(e) => setUserInput(e.currentTarget.value)}
|
||||||
value={userInput}
|
value={userInput}
|
||||||
onKeyDown={(e) => onInputKeyDown(e as any)}
|
onKeyDown={(e) => onInputKeyDown(e as any)}
|
||||||
|
onFocus={() => setAutoScroll(true)}
|
||||||
|
onBlur={() => setAutoScroll(false)}
|
||||||
|
autoFocus
|
||||||
/>
|
/>
|
||||||
<IconButton
|
<IconButton
|
||||||
icon={<SendWhiteIcon />}
|
icon={<SendWhiteIcon />}
|
||||||
|
Loading…
Reference in New Issue
Block a user