fix: shortcut tips (#525)

This commit is contained in:
Tan Xiang 2024-12-24 23:09:54 +08:00 committed by GitHub
parent 960f50e4e4
commit b85765915e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 36 additions and 7 deletions

View File

@ -1,3 +1,4 @@
import { isMac, isWindows } from '@renderer/config/constant'
import { useAppSelector } from '@renderer/store' import { useAppSelector } from '@renderer/store'
import { useCallback } from 'react' import { useCallback } from 'react'
import { useHotkeys } from 'react-hotkeys-hook' import { useHotkeys } from 'react-hotkeys-hook'
@ -59,3 +60,31 @@ export function useShortcuts() {
const shortcuts = useAppSelector((state) => state.shortcuts.shortcuts) const shortcuts = useAppSelector((state) => state.shortcuts.shortcuts)
return { 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) : ''
}

View File

@ -72,7 +72,7 @@
"input.estimated_tokens.tip": "Estimated tokens", "input.estimated_tokens.tip": "Estimated tokens",
"input.expand": "Expand", "input.expand": "Expand",
"input.new.context": "Clear Context", "input.new.context": "Clear Context",
"input.new_topic": "New Topic {{Command}}+N", "input.new_topic": "New Topic {{Command}}",
"input.pause": "Pause", "input.pause": "Pause",
"input.placeholder": "Type your message here...", "input.placeholder": "Type your message here...",
"input.send": "Send", "input.send": "Send",

View File

@ -72,7 +72,7 @@
"input.estimated_tokens.tip": "Затраты токенов", "input.estimated_tokens.tip": "Затраты токенов",
"input.expand": "Развернуть", "input.expand": "Развернуть",
"input.new.context": "Очистить контекст", "input.new.context": "Очистить контекст",
"input.new_topic": "Новый топик {{Command}}+N", "input.new_topic": "Новый топик {{Command}}",
"input.pause": "Остановить", "input.pause": "Остановить",
"input.placeholder": "Введите ваше сообщение здесь...", "input.placeholder": "Введите ваше сообщение здесь...",
"input.send": "Отправить", "input.send": "Отправить",

View File

@ -72,7 +72,7 @@
"input.estimated_tokens.tip": "预估 token 数", "input.estimated_tokens.tip": "预估 token 数",
"input.expand": "展开", "input.expand": "展开",
"input.new.context": "清除上下文", "input.new.context": "清除上下文",
"input.new_topic": "新话题 {{Command}}+N", "input.new_topic": "新话题 {{Command}}",
"input.pause": "暂停", "input.pause": "暂停",
"input.placeholder": "在这里输入消息...", "input.placeholder": "在这里输入消息...",
"input.send": "发送", "input.send": "发送",

View File

@ -72,7 +72,7 @@
"input.estimated_tokens.tip": "預估 Token 數", "input.estimated_tokens.tip": "預估 Token 數",
"input.expand": "展開", "input.expand": "展開",
"input.new.context": "清除上下文", "input.new.context": "清除上下文",
"input.new_topic": "新話題 {{Command}}+N", "input.new_topic": "新話題 {{Command}}",
"input.pause": "暫停", "input.pause": "暫停",
"input.placeholder": "在此輸入您的訊息...", "input.placeholder": "在此輸入您的訊息...",
"input.send": "發送", "input.send": "發送",

View File

@ -10,13 +10,12 @@ import {
} from '@ant-design/icons' } from '@ant-design/icons'
import { PicCenterOutlined } from '@ant-design/icons' import { PicCenterOutlined } from '@ant-design/icons'
import TranslateButton from '@renderer/components/TranslateButton' import TranslateButton from '@renderer/components/TranslateButton'
import { isMac } from '@renderer/config/constant'
import { isVisionModel, isWebSearchModel } from '@renderer/config/models' import { isVisionModel, isWebSearchModel } from '@renderer/config/models'
import db from '@renderer/databases' import db from '@renderer/databases'
import { useAssistant } from '@renderer/hooks/useAssistant' import { useAssistant } from '@renderer/hooks/useAssistant'
import { useRuntime } from '@renderer/hooks/useRuntime' import { useRuntime } from '@renderer/hooks/useRuntime'
import { useMessageStyle, useSettings } from '@renderer/hooks/useSettings' 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 { useShowTopics } from '@renderer/hooks/useStore'
import { addAssistantMessagesToTopic, getDefaultTopic } from '@renderer/services/AssistantService' import { addAssistantMessagesToTopic, getDefaultTopic } from '@renderer/services/AssistantService'
import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService' import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService'
@ -90,6 +89,7 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic }) => {
() => (showInputEstimatedTokens ? estimateTextTokens(text) || 0 : 0), () => (showInputEstimatedTokens ? estimateTextTokens(text) || 0 : 0),
[estimateTextTokens, showInputEstimatedTokens, text] [estimateTextTokens, showInputEstimatedTokens, text]
) )
const newTopicShortcut = useShortcutDisplay('new_topic')
_text = text _text = text
_files = files _files = files
@ -411,7 +411,7 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic }) => {
/> />
<Toolbar> <Toolbar>
<ToolbarMenu> <ToolbarMenu>
<Tooltip placement="top" title={t('chat.input.new_topic', { Command: isMac ? '⌘' : 'Ctrl' })} arrow> <Tooltip placement="top" title={t('chat.input.new_topic', { Command: newTopicShortcut })} arrow>
<ToolbarButton type="text" onClick={addNewTopic}> <ToolbarButton type="text" onClick={addNewTopic}>
<FormOutlined /> <FormOutlined />
</ToolbarButton> </ToolbarButton>