mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 08:13:43 +08:00 
			
		
		
		
	Merge pull request #587 from zhongmeizhi/main
feat: 添加对热键的支持 Escape to close settings, Up Arrow to get last input
This commit is contained in:
		@@ -343,6 +343,7 @@ export function Chat(props: {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  const inputRef = useRef<HTMLTextAreaElement>(null);
 | 
					  const inputRef = useRef<HTMLTextAreaElement>(null);
 | 
				
			||||||
  const [userInput, setUserInput] = useState("");
 | 
					  const [userInput, setUserInput] = useState("");
 | 
				
			||||||
 | 
					  const [beforeInput, setBeforeInput] = useState("");
 | 
				
			||||||
  const [isLoading, setIsLoading] = useState(false);
 | 
					  const [isLoading, setIsLoading] = useState(false);
 | 
				
			||||||
  const { submitKey, shouldSubmit } = useSubmitHandler();
 | 
					  const { submitKey, shouldSubmit } = useSubmitHandler();
 | 
				
			||||||
  const { scrollRef, setAutoScroll } = useScrollToBottom();
 | 
					  const { scrollRef, setAutoScroll } = useScrollToBottom();
 | 
				
			||||||
@@ -407,6 +408,7 @@ export function Chat(props: {
 | 
				
			|||||||
    if (userInput.length <= 0) return;
 | 
					    if (userInput.length <= 0) return;
 | 
				
			||||||
    setIsLoading(true);
 | 
					    setIsLoading(true);
 | 
				
			||||||
    chatStore.onUserInput(userInput).then(() => setIsLoading(false));
 | 
					    chatStore.onUserInput(userInput).then(() => setIsLoading(false));
 | 
				
			||||||
 | 
					    setBeforeInput(userInput);
 | 
				
			||||||
    setUserInput("");
 | 
					    setUserInput("");
 | 
				
			||||||
    setPromptHints([]);
 | 
					    setPromptHints([]);
 | 
				
			||||||
    if (!isMobileScreen()) inputRef.current?.focus();
 | 
					    if (!isMobileScreen()) inputRef.current?.focus();
 | 
				
			||||||
@@ -420,6 +422,12 @@ export function Chat(props: {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  // check if should send message
 | 
					  // check if should send message
 | 
				
			||||||
  const onInputKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
 | 
					  const onInputKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
 | 
				
			||||||
 | 
					    // if ArrowUp and no userInput
 | 
				
			||||||
 | 
					    if (e.key === "ArrowUp" && userInput.length <= 0) {
 | 
				
			||||||
 | 
					      setUserInput(beforeInput);
 | 
				
			||||||
 | 
					      e.preventDefault();
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    if (shouldSubmit(e)) {
 | 
					    if (shouldSubmit(e)) {
 | 
				
			||||||
      onUserSubmit();
 | 
					      onUserSubmit();
 | 
				
			||||||
      e.preventDefault();
 | 
					      e.preventDefault();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -128,6 +128,19 @@ export function Settings(props: { closeSettings: () => void }) {
 | 
				
			|||||||
    // eslint-disable-next-line react-hooks/exhaustive-deps
 | 
					    // eslint-disable-next-line react-hooks/exhaustive-deps
 | 
				
			||||||
  }, []);
 | 
					  }, []);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  useEffect(() => {
 | 
				
			||||||
 | 
					    const keydownEvent = (e: KeyboardEvent) => {
 | 
				
			||||||
 | 
					      if (e.key === "Escape") {
 | 
				
			||||||
 | 
					        props.closeSettings();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    document.addEventListener("keydown", keydownEvent);
 | 
				
			||||||
 | 
					    return () => {
 | 
				
			||||||
 | 
					      document.removeEventListener("keydown", keydownEvent);
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    // eslint-disable-next-line react-hooks/exhaustive-deps
 | 
				
			||||||
 | 
					  }, []);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <ErrorBoundary>
 | 
					    <ErrorBoundary>
 | 
				
			||||||
      <div className={styles["window-header"]}>
 | 
					      <div className={styles["window-header"]}>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user