mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 08:13:43 +08:00 
			
		
		
		
	fix: #2252 polyfill composing for old safari browsers
This commit is contained in:
		@@ -172,10 +172,29 @@ function PromptToast(props: {
 | 
			
		||||
function useSubmitHandler() {
 | 
			
		||||
  const config = useAppConfig();
 | 
			
		||||
  const submitKey = config.submitKey;
 | 
			
		||||
  const isComposing = useRef(false);
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    const onCompositionStart = () => {
 | 
			
		||||
      isComposing.current = true;
 | 
			
		||||
    };
 | 
			
		||||
    const onCompositionEnd = () => {
 | 
			
		||||
      isComposing.current = false;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    window.addEventListener("compositionstart", onCompositionStart);
 | 
			
		||||
    window.addEventListener("compositionend", onCompositionEnd);
 | 
			
		||||
 | 
			
		||||
    return () => {
 | 
			
		||||
      window.removeEventListener("compositionstart", onCompositionStart);
 | 
			
		||||
      window.removeEventListener("compositionend", onCompositionEnd);
 | 
			
		||||
    };
 | 
			
		||||
  }, []);
 | 
			
		||||
 | 
			
		||||
  const shouldSubmit = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
 | 
			
		||||
    if (e.key !== "Enter") return false;
 | 
			
		||||
    if (e.key === "Enter" && e.nativeEvent.isComposing) return false;
 | 
			
		||||
    if (e.key === "Enter" && (e.nativeEvent.isComposing || isComposing.current))
 | 
			
		||||
      return false;
 | 
			
		||||
    return (
 | 
			
		||||
      (config.submitKey === SubmitKey.AltEnter && e.altKey) ||
 | 
			
		||||
      (config.submitKey === SubmitKey.CtrlEnter && e.ctrlKey) ||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user