From 4c63ee23cdf2760a4b88510081b2d630c583050e Mon Sep 17 00:00:00 2001 From: DDMeaqua Date: Thu, 19 Sep 2024 15:13:33 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20#5422=20=E5=BF=AB=E6=8D=B7=E9=94=AE?= =?UTF-8?q?=E6=B8=85=E9=99=A4=E4=B8=8A=E4=B8=8B=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/chat.tsx | 20 ++++++++++++++++++++ app/locales/cn.ts | 1 + app/locales/en.ts | 1 + app/locales/tw.ts | 1 + 4 files changed, 23 insertions(+) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 3d519dee722..08c931f9efe 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -874,6 +874,10 @@ export function ShortcutKeyModal(props: { onClose: () => void }) { title: Locale.Chat.ShortcutKey.showShortcutKey, keys: isMac ? ["⌘", "/"] : ["Ctrl", "/"], }, + { + title: Locale.Chat.ShortcutKey.clearContext, + keys: isMac ? ["⌘", "Shift", "Delete"] : ["Ctrl", "Shift", "Delete"], + }, ]; return (
@@ -1560,6 +1564,22 @@ function _Chat() { event.preventDefault(); setShowShortcutKeyModal(true); } + // 清除上下文 command + shift + delete + else if ( + (event.metaKey || event.ctrlKey) && + event.shiftKey && + event.key.toLowerCase() === "delete" + ) { + event.preventDefault(); + chatStore.updateCurrentSession((session) => { + if (session.clearContextIndex === session.messages.length) { + session.clearContextIndex = undefined; + } else { + session.clearContextIndex = session.messages.length; + session.memoryPrompt = ""; // will clear memory + } + }); + } }; window.addEventListener("keydown", handleKeyDown); diff --git a/app/locales/cn.ts b/app/locales/cn.ts index 0017e8e4243..0acf8c545a6 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -95,6 +95,7 @@ const cn = { copyLastMessage: "复制最后一个回复", copyLastCode: "复制最后一个代码块", showShortcutKey: "显示快捷方式", + clearContext: "清除上下文", }, }, Export: { diff --git a/app/locales/en.ts b/app/locales/en.ts index 63e244b9a81..559b93abd56 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -97,6 +97,7 @@ const en: LocaleType = { copyLastMessage: "Copy Last Reply", copyLastCode: "Copy Last Code Block", showShortcutKey: "Show Shortcuts", + clearContext: "Clear Context", }, }, Export: { diff --git a/app/locales/tw.ts b/app/locales/tw.ts index b0602a08174..b84d3bf1f03 100644 --- a/app/locales/tw.ts +++ b/app/locales/tw.ts @@ -90,6 +90,7 @@ const tw = { copyLastMessage: "複製最後一個回覆", copyLastCode: "複製最後一個代碼塊", showShortcutKey: "顯示快捷方式", + clearContext: "清除上下文", }, }, Export: { From 5b5dea1c59605f26b382d780b5a558169d1a1021 Mon Sep 17 00:00:00 2001 From: DDMeaqua Date: Mon, 30 Dec 2024 12:11:50 +0800 Subject: [PATCH 2/6] =?UTF-8?q?chore:=20=E6=9B=B4=E6=8D=A2=E5=BF=AB?= =?UTF-8?q?=E6=8D=B7=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/chat.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 08c931f9efe..138c0b86544 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -876,7 +876,7 @@ export function ShortcutKeyModal(props: { onClose: () => void }) { }, { title: Locale.Chat.ShortcutKey.clearContext, - keys: isMac ? ["⌘", "Shift", "Delete"] : ["Ctrl", "Shift", "Delete"], + keys: isMac ? ["⌘", "Shift", "k"] : ["Ctrl", "Shift", "k"], }, ]; return ( @@ -1568,7 +1568,7 @@ function _Chat() { else if ( (event.metaKey || event.ctrlKey) && event.shiftKey && - event.key.toLowerCase() === "delete" + event.key.toLowerCase() === "k" ) { event.preventDefault(); chatStore.updateCurrentSession((session) => { From 6d84f9d3ae62da0c5d1617645f961d9f9e1a1a27 Mon Sep 17 00:00:00 2001 From: DDMeaqua Date: Tue, 31 Dec 2024 13:27:15 +0800 Subject: [PATCH 3/6] chore: update --- app/components/chat.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 138c0b86544..b15be19f9a0 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -876,7 +876,9 @@ export function ShortcutKeyModal(props: { onClose: () => void }) { }, { title: Locale.Chat.ShortcutKey.clearContext, - keys: isMac ? ["⌘", "Shift", "k"] : ["Ctrl", "Shift", "k"], + keys: isMac + ? ["⌘", "Shift", "Backspace"] + : ["Ctrl", "Shift", "Backspace"], }, ]; return ( @@ -1513,7 +1515,7 @@ function _Chat() { const [showShortcutKeyModal, setShowShortcutKeyModal] = useState(false); useEffect(() => { - const handleKeyDown = (event: any) => { + const handleKeyDown = (event: KeyboardEvent) => { // 打开新聊天 command + shift + o if ( (event.metaKey || event.ctrlKey) && @@ -1564,11 +1566,11 @@ function _Chat() { event.preventDefault(); setShowShortcutKeyModal(true); } - // 清除上下文 command + shift + delete + // 清除上下文 command + shift + Backspace else if ( (event.metaKey || event.ctrlKey) && event.shiftKey && - event.key.toLowerCase() === "k" + event.key.toLowerCase() === "backspace" ) { event.preventDefault(); chatStore.updateCurrentSession((session) => { @@ -1582,10 +1584,10 @@ function _Chat() { } }; - window.addEventListener("keydown", handleKeyDown); + document.addEventListener("keydown", handleKeyDown); return () => { - window.removeEventListener("keydown", handleKeyDown); + document.removeEventListener("keydown", handleKeyDown); }; }, [messages, chatStore, navigate]); From aba4baf38403dd717ee04f5555ba81749d9ee6c8 Mon Sep 17 00:00:00 2001 From: DDMeaqua Date: Tue, 31 Dec 2024 14:25:43 +0800 Subject: [PATCH 4/6] chore: update --- app/components/chat.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index b15be19f9a0..6fcd23d3853 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -876,9 +876,7 @@ export function ShortcutKeyModal(props: { onClose: () => void }) { }, { title: Locale.Chat.ShortcutKey.clearContext, - keys: isMac - ? ["⌘", "Shift", "Backspace"] - : ["Ctrl", "Shift", "Backspace"], + keys: isMac ? ["⌘", "Shift", "k"] : ["Ctrl", "Shift", "k"], }, ]; return ( @@ -1566,11 +1564,11 @@ function _Chat() { event.preventDefault(); setShowShortcutKeyModal(true); } - // 清除上下文 command + shift + Backspace + // 清除上下文 command + shift + k else if ( (event.metaKey || event.ctrlKey) && event.shiftKey && - event.key.toLowerCase() === "backspace" + event.key.toLowerCase() === "k" ) { event.preventDefault(); chatStore.updateCurrentSession((session) => { From c5d9b1131ec932e53cd0394c283e24549f6426cb Mon Sep 17 00:00:00 2001 From: DDMeaqua Date: Tue, 31 Dec 2024 14:38:58 +0800 Subject: [PATCH 5/6] fix: merge bug --- app/components/chat.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 25f692f2ad7..0d6051a31a3 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -1614,7 +1614,7 @@ function _Chat() { event.key.toLowerCase() === "k" ) { event.preventDefault(); - chatStore.updateCurrentSession((session) => { + chatStore.updateTargetSession(session, (session) => { if (session.clearContextIndex === session.messages.length) { session.clearContextIndex = undefined; } else { @@ -1630,7 +1630,7 @@ function _Chat() { return () => { document.removeEventListener("keydown", handleKeyDown); }; - }, [messages, chatStore, navigate]); + }, [messages, chatStore, navigate, session]); const [showChatSidePanel, setShowChatSidePanel] = useState(false); From d184eb64585562de7f75e1ff7d291eb242b2f076 Mon Sep 17 00:00:00 2001 From: DDMeaqua Date: Tue, 31 Dec 2024 14:50:54 +0800 Subject: [PATCH 6/6] chore: cmd + shift+ backspace --- app/components/chat.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 0d6051a31a3..9990a359e14 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -902,7 +902,9 @@ export function ShortcutKeyModal(props: { onClose: () => void }) { }, { title: Locale.Chat.ShortcutKey.clearContext, - keys: isMac ? ["⌘", "Shift", "k"] : ["Ctrl", "Shift", "k"], + keys: isMac + ? ["⌘", "Shift", "backspace"] + : ["Ctrl", "Shift", "backspace"], }, ]; return ( @@ -1607,11 +1609,11 @@ function _Chat() { event.preventDefault(); setShowShortcutKeyModal(true); } - // 清除上下文 command + shift + k + // 清除上下文 command + shift + backspace else if ( (event.metaKey || event.ctrlKey) && event.shiftKey && - event.key.toLowerCase() === "k" + event.key.toLowerCase() === "backspace" ) { event.preventDefault(); chatStore.updateTargetSession(session, (session) => {