diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 0cf1409..58ae1d2 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -174,11 +174,24 @@ function PromptToast(props: { function useSubmitHandler() { const config = useAppConfig(); + const isMobileScreen = useMobileScreen(); const submitKey = config.submitKey; + const mobileSubmitKey = config.mobileSubmitKey; const shouldSubmit = (e: React.KeyboardEvent) => { if (e.key !== "Enter") return false; if (e.key === "Enter" && e.nativeEvent.isComposing) return false; + if (isMobileScreen) return ( + (mobileSubmitKey === SubmitKey.AltEnter && e.altKey) || + (mobileSubmitKey === SubmitKey.CtrlEnter && e.ctrlKey) || + (mobileSubmitKey === SubmitKey.ShiftEnter && e.shiftKey) || + (mobileSubmitKey === SubmitKey.MetaEnter && e.metaKey) || + (mobileSubmitKey === SubmitKey.Enter && + !e.altKey && + !e.ctrlKey && + !e.shiftKey && + !e.metaKey) + ); return ( (submitKey === SubmitKey.AltEnter && e.altKey) || (submitKey === SubmitKey.CtrlEnter && e.ctrlKey) || @@ -316,9 +329,31 @@ function ChatAction(props: { }); } + // useEffect(() => { + // // updateWidth(); + // setTimeout(updateWidth, 600); // 手机优化,给DOM元素一些加载的时间 + // }, []); useEffect(() => { - // updateWidth(); - setTimeout(updateWidth, 600); // 手机优化,给DOM元素一些加载的时间 + let resizeObserver: ResizeObserver; + if (window.ResizeObserver) { + resizeObserver = new ResizeObserver(() => { + updateWidth(); + }); + if (iconRef.current && textRef.current) { + resizeObserver.observe(iconRef.current); + resizeObserver.observe(textRef.current); + } + } else { + setTimeout(updateWidth, 600); // 增加600ms延迟,给DOM元素一些加载的时间 + } + + return () => { + if (resizeObserver) { + if (iconRef.current) resizeObserver.unobserve(iconRef.current); + if (textRef.current) resizeObserver.unobserve(textRef.current); + resizeObserver.disconnect(); + } + }; }, []); return ( @@ -751,10 +786,11 @@ export function Chat() { > {!session.topic ? DEFAULT_TOPIC : session.topic} -
- {Locale.Chat.SubTitle(session.messages.length)} -
- {/* todo */} + {!isMobileScreen && ( +
+ {Locale.Chat.SubTitle(session.messages.length)} +
+ )}
@@ -765,13 +801,15 @@ export function Chat() { onClick={() => navigate(Path.Home)} />
-
- } - bordered - onClick={renameSession} - /> -
+ {!isMobileScreen && ( +
+ } + bordered + onClick={renameSession} + /> +
+ )}
} @@ -936,7 +974,7 @@ export function Chat() {