+
}
+ key="ok"
+ onClick={() => {
+ props.onClose();
+ }}
+ />,
+ ]}
+ >
+
+
+ {shortcuts.map((shortcut, index) => (
+
+
+ {shortcut.title}
+
+
+ {shortcut.keys.map((key, i) => (
+
+ {key}
+
+ ))}
+
+
+ ))}
+
+
+
+
+ );
+}
+
function _Chat() {
type RenderMessage = ChatMessage & { preview?: boolean };
@@ -972,7 +1044,7 @@ function _Chat() {
})
.then(() => setIsLoading(false));
setAttachImages([]);
- localStorage.setItem(LAST_INPUT_KEY, userInput);
+ chatStore.setLastInput(userInput);
setUserInput("");
setMjImageMode("IMAGINE");
setPromptHints([]);
@@ -1039,7 +1111,7 @@ function _Chat() {
userInput.length <= 0 &&
!(e.metaKey || e.altKey || e.ctrlKey)
) {
- setUserInput(localStorage.getItem(LAST_INPUT_KEY) ?? "");
+ setUserInput(chatStore.lastInput ?? "");
e.preventDefault();
return;
}
@@ -1410,7 +1482,6 @@ function _Chat() {
}
setAttachImages(images);
}
-
// 加载状态结束,获取token
const [loadingChange, setLoadingChange] = useState(false);
useEffect(() => {
@@ -1439,20 +1510,69 @@ function _Chat() {
};
}, [isLoading, loadingChange]);
- // const [ voiceInputText, setVoiceInputText ] = useState("");
- // const [ voiceInputLoading, setVoiceInputLoading ] = useState(false);
+ // 快捷键 shortcut keys
+ const [showShortcutKeyModal, setShowShortcutKeyModal] = useState(false);
- // useEffect(() => {
- // if (voiceInputLoading) {
- // // 正在进行语音输入,输入框应该显示原有文本加上语音输入的。
- // setUserInput(userInput + voiceInputText);
- // } else {
- // // 但是语音输入结束,应该清理多余字符。
- // console.log('end', userInput, voiceInputText)
- // }
- //
- // // eslint-disable-next-line react-hooks/exhaustive-deps
- // }, [voiceInputLoading, voiceInputText]);
+ useEffect(() => {
+ const handleKeyDown = (event: any) => {
+ // 打开新聊天 command + shift + o
+ if (
+ (event.metaKey || event.ctrlKey) &&
+ event.shiftKey &&
+ event.key.toLowerCase() === "o"
+ ) {
+ event.preventDefault();
+ setTimeout(() => {
+ chatStore.newSession();
+ navigate(Path.Chat);
+ }, 10);
+ }
+ // 聚焦聊天输入 shift + esc
+ else if (event.shiftKey && event.key.toLowerCase() === "escape") {
+ event.preventDefault();
+ inputRef.current?.focus();
+ }
+ // 复制最后一个代码块 command + shift + ;
+ else if (
+ (event.metaKey || event.ctrlKey) &&
+ event.shiftKey &&
+ event.code === "Semicolon"
+ ) {
+ event.preventDefault();
+ const copyCodeButton =
+ document.querySelectorAll