From b85765915e55a331dcb2d5e7d14b31af3eef93f9 Mon Sep 17 00:00:00 2001 From: Tan Xiang <82364837+TanXiang7o@users.noreply.github.com> Date: Tue, 24 Dec 2024 23:09:54 +0800 Subject: [PATCH] fix: shortcut tips (#525) --- src/renderer/src/hooks/useShortcuts.ts | 29 +++++++++++++++++++ src/renderer/src/i18n/locales/en-us.json | 2 +- src/renderer/src/i18n/locales/ru-ru.json | 2 +- src/renderer/src/i18n/locales/zh-cn.json | 2 +- src/renderer/src/i18n/locales/zh-tw.json | 2 +- .../src/pages/home/Inputbar/Inputbar.tsx | 6 ++-- 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/renderer/src/hooks/useShortcuts.ts b/src/renderer/src/hooks/useShortcuts.ts index bf88beca..d4c1b206 100644 --- a/src/renderer/src/hooks/useShortcuts.ts +++ b/src/renderer/src/hooks/useShortcuts.ts @@ -1,3 +1,4 @@ +import { isMac, isWindows } from '@renderer/config/constant' import { useAppSelector } from '@renderer/store' import { useCallback } from 'react' import { useHotkeys } from 'react-hotkeys-hook' @@ -59,3 +60,31 @@ export function useShortcuts() { const shortcuts = useAppSelector((state) => state.shortcuts.shortcuts) return { shortcuts } } + +export function useShortcutDisplay(key: string) { + const formatShortcut = useCallback((shortcut: string[]) => { + return shortcut + .map((key) => { + switch (key.toLowerCase()) { + case 'control': + return isMac ? '⌃' : 'Ctrl' + case 'ctrl': + return isMac ? '⌃' : 'Ctrl' + case 'command': + return isMac ? '⌘' : isWindows ? 'Win' : 'Super' + case 'alt': + return isMac ? '⌥' : 'Alt' + case 'shift': + return isMac ? '⇧' : 'Shift' + case 'commandorcontrol': + return isMac ? '⌘' : 'Ctrl' + default: + return key.charAt(0).toUpperCase() + key.slice(1).toLowerCase() + } + }) + .join('+') + }, []) + const shortcuts = useAppSelector((state) => state.shortcuts.shortcuts) + const shortcutConfig = shortcuts.find((s) => s.key === key) + return shortcutConfig?.enabled ? formatShortcut(shortcutConfig.shortcut) : '' +} diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index e97afe11..f69f6ff1 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -72,7 +72,7 @@ "input.estimated_tokens.tip": "Estimated tokens", "input.expand": "Expand", "input.new.context": "Clear Context", - "input.new_topic": "New Topic {{Command}}+N", + "input.new_topic": "New Topic {{Command}}", "input.pause": "Pause", "input.placeholder": "Type your message here...", "input.send": "Send", diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json index 38ded171..159d95e4 100644 --- a/src/renderer/src/i18n/locales/ru-ru.json +++ b/src/renderer/src/i18n/locales/ru-ru.json @@ -72,7 +72,7 @@ "input.estimated_tokens.tip": "Затраты токенов", "input.expand": "Развернуть", "input.new.context": "Очистить контекст", - "input.new_topic": "Новый топик {{Command}}+N", + "input.new_topic": "Новый топик {{Command}}", "input.pause": "Остановить", "input.placeholder": "Введите ваше сообщение здесь...", "input.send": "Отправить", diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index c287ff98..1e188369 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -72,7 +72,7 @@ "input.estimated_tokens.tip": "预估 token 数", "input.expand": "展开", "input.new.context": "清除上下文", - "input.new_topic": "新话题 {{Command}}+N", + "input.new_topic": "新话题 {{Command}}", "input.pause": "暂停", "input.placeholder": "在这里输入消息...", "input.send": "发送", diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index b700113d..b7f1939f 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -72,7 +72,7 @@ "input.estimated_tokens.tip": "預估 Token 數", "input.expand": "展開", "input.new.context": "清除上下文", - "input.new_topic": "新話題 {{Command}}+N", + "input.new_topic": "新話題 {{Command}}", "input.pause": "暫停", "input.placeholder": "在此輸入您的訊息...", "input.send": "發送", diff --git a/src/renderer/src/pages/home/Inputbar/Inputbar.tsx b/src/renderer/src/pages/home/Inputbar/Inputbar.tsx index 4416a466..120f3461 100644 --- a/src/renderer/src/pages/home/Inputbar/Inputbar.tsx +++ b/src/renderer/src/pages/home/Inputbar/Inputbar.tsx @@ -10,13 +10,12 @@ import { } from '@ant-design/icons' import { PicCenterOutlined } from '@ant-design/icons' import TranslateButton from '@renderer/components/TranslateButton' -import { isMac } from '@renderer/config/constant' import { isVisionModel, isWebSearchModel } from '@renderer/config/models' import db from '@renderer/databases' import { useAssistant } from '@renderer/hooks/useAssistant' import { useRuntime } from '@renderer/hooks/useRuntime' import { useMessageStyle, useSettings } from '@renderer/hooks/useSettings' -import { useShortcut } from '@renderer/hooks/useShortcuts' +import { useShortcut, useShortcutDisplay } from '@renderer/hooks/useShortcuts' import { useShowTopics } from '@renderer/hooks/useStore' import { addAssistantMessagesToTopic, getDefaultTopic } from '@renderer/services/AssistantService' import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService' @@ -90,6 +89,7 @@ const Inputbar: FC = ({ assistant: _assistant, setActiveTopic }) => { () => (showInputEstimatedTokens ? estimateTextTokens(text) || 0 : 0), [estimateTextTokens, showInputEstimatedTokens, text] ) + const newTopicShortcut = useShortcutDisplay('new_topic') _text = text _files = files @@ -411,7 +411,7 @@ const Inputbar: FC = ({ assistant: _assistant, setActiveTopic }) => { /> - +