Skip to content

Commit 0af04e0

Browse files
authored
Merge pull request ChatGPTNextWeb#5468 from DDMeaqua/feat-shortcutkey
feat: ChatGPTNextWeb#5422 快捷键清除上下文
2 parents 63c5baa + d184eb6 commit 0af04e0

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

app/components/chat.tsx

+26-4
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,12 @@ export function ShortcutKeyModal(props: { onClose: () => void }) {
900900
title: Locale.Chat.ShortcutKey.showShortcutKey,
901901
keys: isMac ? ["⌘", "/"] : ["Ctrl", "/"],
902902
},
903+
{
904+
title: Locale.Chat.ShortcutKey.clearContext,
905+
keys: isMac
906+
? ["⌘", "Shift", "backspace"]
907+
: ["Ctrl", "Shift", "backspace"],
908+
},
903909
];
904910
return (
905911
<div className="modal-mask">
@@ -1552,7 +1558,7 @@ function _Chat() {
15521558
const [showShortcutKeyModal, setShowShortcutKeyModal] = useState(false);
15531559

15541560
useEffect(() => {
1555-
const handleKeyDown = (event: any) => {
1561+
const handleKeyDown = (event: KeyboardEvent) => {
15561562
// 打开新聊天 command + shift + o
15571563
if (
15581564
(event.metaKey || event.ctrlKey) &&
@@ -1603,14 +1609,30 @@ function _Chat() {
16031609
event.preventDefault();
16041610
setShowShortcutKeyModal(true);
16051611
}
1612+
// 清除上下文 command + shift + backspace
1613+
else if (
1614+
(event.metaKey || event.ctrlKey) &&
1615+
event.shiftKey &&
1616+
event.key.toLowerCase() === "backspace"
1617+
) {
1618+
event.preventDefault();
1619+
chatStore.updateTargetSession(session, (session) => {
1620+
if (session.clearContextIndex === session.messages.length) {
1621+
session.clearContextIndex = undefined;
1622+
} else {
1623+
session.clearContextIndex = session.messages.length;
1624+
session.memoryPrompt = ""; // will clear memory
1625+
}
1626+
});
1627+
}
16061628
};
16071629

1608-
window.addEventListener("keydown", handleKeyDown);
1630+
document.addEventListener("keydown", handleKeyDown);
16091631

16101632
return () => {
1611-
window.removeEventListener("keydown", handleKeyDown);
1633+
document.removeEventListener("keydown", handleKeyDown);
16121634
};
1613-
}, [messages, chatStore, navigate]);
1635+
}, [messages, chatStore, navigate, session]);
16141636

16151637
const [showChatSidePanel, setShowChatSidePanel] = useState(false);
16161638

app/locales/cn.ts

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ const cn = {
106106
copyLastMessage: "复制最后一个回复",
107107
copyLastCode: "复制最后一个代码块",
108108
showShortcutKey: "显示快捷方式",
109+
clearContext: "清除上下文",
109110
},
110111
},
111112
Export: {

app/locales/en.ts

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ const en: LocaleType = {
107107
copyLastMessage: "Copy Last Reply",
108108
copyLastCode: "Copy Last Code Block",
109109
showShortcutKey: "Show Shortcuts",
110+
clearContext: "Clear Context",
110111
},
111112
},
112113
Export: {

app/locales/tw.ts

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ const tw = {
100100
copyLastMessage: "複製最後一個回覆",
101101
copyLastCode: "複製最後一個程式碼區塊",
102102
showShortcutKey: "顯示快捷方式",
103+
clearContext: "清除上下文",
103104
},
104105
},
105106
Export: {

0 commit comments

Comments
 (0)