This commit is contained in:
jardel 2025-12-18 13:35:40 +08:00 committed by GitHub
commit 21b7ce4912
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 71 additions and 21 deletions

View File

@ -210,6 +210,7 @@ const shortcutKeyMap = {
reset_to_default: 'settings.shortcuts.reset_to_default', reset_to_default: 'settings.shortcuts.reset_to_default',
search_message: 'settings.shortcuts.search_message', search_message: 'settings.shortcuts.search_message',
search_message_in_chat: 'settings.shortcuts.search_message_in_chat', search_message_in_chat: 'settings.shortcuts.search_message_in_chat',
send_shortcuts: 'settings.shortcuts.send_shortcuts',
selection_assistant_select_text: 'settings.shortcuts.selection_assistant_select_text', selection_assistant_select_text: 'settings.shortcuts.selection_assistant_select_text',
selection_assistant_toggle: 'settings.shortcuts.selection_assistant_toggle', selection_assistant_toggle: 'settings.shortcuts.selection_assistant_toggle',
show_app: 'settings.shortcuts.show_app', show_app: 'settings.shortcuts.show_app',

View File

@ -4666,6 +4666,7 @@
"search_message_in_chat": "Search Message in Current Chat", "search_message_in_chat": "Search Message in Current Chat",
"selection_assistant_select_text": "Selection Assistant: Select Text", "selection_assistant_select_text": "Selection Assistant: Select Text",
"selection_assistant_toggle": "Toggle Selection Assistant", "selection_assistant_toggle": "Toggle Selection Assistant",
"send_shortcuts": "Send shortcuts",
"show_app": "Show/Hide App", "show_app": "Show/Hide App",
"show_settings": "Open Settings", "show_settings": "Open Settings",
"title": "Keyboard Shortcuts", "title": "Keyboard Shortcuts",

View File

@ -4666,6 +4666,7 @@
"search_message_in_chat": "在当前对话中搜索消息", "search_message_in_chat": "在当前对话中搜索消息",
"selection_assistant_select_text": "划词助手:取词", "selection_assistant_select_text": "划词助手:取词",
"selection_assistant_toggle": "开关划词助手", "selection_assistant_toggle": "开关划词助手",
"send_shortcuts": "发送快捷键",
"show_app": "显示 / 隐藏应用", "show_app": "显示 / 隐藏应用",
"show_settings": "打开设置", "show_settings": "打开设置",
"title": "快捷键", "title": "快捷键",

View File

@ -4666,6 +4666,7 @@
"search_message_in_chat": "在目前對話中搜尋訊息", "search_message_in_chat": "在目前對話中搜尋訊息",
"selection_assistant_select_text": "劃詞助手:取詞", "selection_assistant_select_text": "劃詞助手:取詞",
"selection_assistant_toggle": "開關劃詞助手", "selection_assistant_toggle": "開關劃詞助手",
"send_shortcuts": "傳送快捷鍵",
"show_app": "顯示 / 隱藏應用程式", "show_app": "顯示 / 隱藏應用程式",
"show_settings": "開啟設定", "show_settings": "開啟設定",
"title": "快捷鍵", "title": "快捷鍵",

View File

@ -15,7 +15,6 @@ import { SettingDivider, SettingRow, SettingRowTitle } from '@renderer/pages/set
import { CollapsibleSettingGroup } from '@renderer/pages/settings/SettingGroup' import { CollapsibleSettingGroup } from '@renderer/pages/settings/SettingGroup'
import { getDefaultModel } from '@renderer/services/AssistantService' import { getDefaultModel } from '@renderer/services/AssistantService'
import { useAppDispatch } from '@renderer/store' import { useAppDispatch } from '@renderer/store'
import type { SendMessageShortcut } from '@renderer/store/settings'
import { import {
setAutoTranslateWithSpace, setAutoTranslateWithSpace,
setCodeCollapsible, setCodeCollapsible,
@ -47,7 +46,6 @@ import {
} from '@renderer/store/settings' } from '@renderer/store/settings'
import type { Assistant, CodeStyleVarious, MathEngine } from '@renderer/types' import type { Assistant, CodeStyleVarious, MathEngine } from '@renderer/types'
import { isGroqSystemProvider, ThemeMode } from '@renderer/types' import { isGroqSystemProvider, ThemeMode } from '@renderer/types'
import { getSendMessageShortcutLabel } from '@renderer/utils/input'
import { import {
isOpenAICompatibleProvider, isOpenAICompatibleProvider,
isSupportServiceTierProvider, isSupportServiceTierProvider,
@ -86,8 +84,6 @@ const SettingsTab: FC<Props> = (props) => {
showPrompt, showPrompt,
messageFont, messageFont,
showInputEstimatedTokens, showInputEstimatedTokens,
sendMessageShortcut,
setSendMessageShortcut,
targetLanguage, targetLanguage,
setTargetLanguage, setTargetLanguage,
pasteLongTextAsFile, pasteLongTextAsFile,
@ -561,21 +557,6 @@ const SettingsTab: FC<Props> = (props) => {
})} })}
/> />
</SettingRow> </SettingRow>
<SettingDivider />
<SettingRow>
<SettingRowTitleSmall>{t('settings.messages.input.send_shortcuts')}</SettingRowTitleSmall>
<Selector
value={sendMessageShortcut}
onChange={(value) => setSendMessageShortcut(value as SendMessageShortcut)}
options={[
{ value: 'Enter', label: getSendMessageShortcutLabel('Enter') },
{ value: 'Ctrl+Enter', label: getSendMessageShortcutLabel('Ctrl+Enter') },
{ value: 'Alt+Enter', label: getSendMessageShortcutLabel('Alt+Enter') },
{ value: 'Command+Enter', label: getSendMessageShortcutLabel('Command+Enter') },
{ value: 'Shift+Enter', label: getSendMessageShortcutLabel('Shift+Enter') }
]}
/>
</SettingRow>
</SettingGroup> </SettingGroup>
</CollapsibleSettingGroup> </CollapsibleSettingGroup>
</Container> </Container>

View File

@ -1,11 +1,14 @@
import { ClearOutlined, UndoOutlined } from '@ant-design/icons' import { ClearOutlined, UndoOutlined } from '@ant-design/icons'
import { HStack } from '@renderer/components/Layout' import { HStack } from '@renderer/components/Layout'
import Selector from "@renderer/components/Selector";
import { isMac, isWin } from '@renderer/config/constant' import { isMac, isWin } from '@renderer/config/constant'
import { useTheme } from '@renderer/context/ThemeProvider' import { useTheme } from '@renderer/context/ThemeProvider'
import { useSettings} from "@renderer/hooks/useSettings";
import { useShortcuts } from '@renderer/hooks/useShortcuts' import { useShortcuts } from '@renderer/hooks/useShortcuts'
import { useTimer } from '@renderer/hooks/useTimer' import { useTimer } from '@renderer/hooks/useTimer'
import { getShortcutLabel } from '@renderer/i18n/label' import { getShortcutLabel } from '@renderer/i18n/label'
import { useAppDispatch } from '@renderer/store' import { useAppDispatch } from '@renderer/store'
import type {SendMessageShortcut} from "@renderer/store/settings";
import { initialState, resetShortcuts, toggleShortcut, updateShortcut } from '@renderer/store/shortcuts' import { initialState, resetShortcuts, toggleShortcut, updateShortcut } from '@renderer/store/shortcuts'
import type { Shortcut } from '@renderer/types' import type { Shortcut } from '@renderer/types'
import type { InputRef } from 'antd' import type { InputRef } from 'antd'
@ -16,12 +19,15 @@ import React, { useRef, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import styled from 'styled-components' import styled from 'styled-components'
import { SettingContainer, SettingDivider, SettingGroup, SettingTitle } from '.' import {SettingContainer, SettingDivider, SettingGroup, SettingTitle} from '.'
const ShortcutSettings: FC = () => { const ShortcutSettings: FC = () => {
const { t } = useTranslation() const { t } = useTranslation()
const { theme } = useTheme() const { theme } = useTheme()
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const {
setSendMessageShortcut,
} = useSettings()
const { shortcuts: originalShortcuts } = useShortcuts() const { shortcuts: originalShortcuts } = useShortcuts()
const inputRefs = useRef<Record<string, InputRef>>({}) const inputRefs = useRef<Record<string, InputRef>>({})
const [editingKey, setEditingKey] = useState<string | null>(null) const [editingKey, setEditingKey] = useState<string | null>(null)
@ -304,7 +310,44 @@ const ShortcutSettings: FC = () => {
return return
} }
dispatch(updateShortcut({...record, shortcut: keys}))
setEditingKey(null)
}
const handleKeyChange = (value: string, record: Shortcut) => {
const parts = value.split('+').map(part => part.trim())
const keys: string[] = []
// Convert the string parts to the internal key format
for (const part of parts) {
switch (part) {
case 'Command':
case 'Cmd':
keys.push('CommandOrControl')
break
case 'Ctrl':
case 'Control':
keys.push(isMac ? 'Ctrl' : 'CommandOrControl')
break
case 'Alt':
keys.push('Alt')
break
case 'Shift':
keys.push('Shift')
break
case 'Meta':
case 'Win':
case 'Super':
keys.push('Meta')
break
default:
keys.push(part)
}
}
if (isDuplicateShortcut(keys, record.key)) {
return
}
dispatch(updateShortcut({ ...record, shortcut: keys })) dispatch(updateShortcut({ ...record, shortcut: keys }))
setSendMessageShortcut(value as SendMessageShortcut)
setEditingKey(null) setEditingKey(null)
} }
@ -332,11 +375,24 @@ const ShortcutSettings: FC = () => {
const isEditing = editingKey === record.key const isEditing = editingKey === record.key
const shortcutConfig = shortcuts.find((s) => s.key === record.key) const shortcutConfig = shortcuts.find((s) => s.key === record.key)
const isEditable = shortcutConfig?.editable !== false const isEditable = shortcutConfig?.editable !== false
const isSelector = !!shortcutConfig?.isSelector
return ( return (
<HStack style={{ display: 'flex', gap: '8px', justifyContent: 'flex-end', alignItems: 'center' }}> <HStack style={{ display: 'flex', gap: '8px', justifyContent: 'flex-end', alignItems: 'center' }}>
<HStack alignItems="center" style={{ position: 'relative' }}> <HStack alignItems="center" style={{ position: 'relative' }}>
{isEditing ? ( {isEditing ? isSelector ? (
<Selector
value={shortcut.join('+')}
onChange={(value) => handleKeyChange(value, record)}
options={[
{value: 'Enter', label: formatShortcut(['Enter'])},
{value: 'Ctrl+Enter', label: formatShortcut(['Ctrl','Enter'])},
{value: 'Alt+Enter', label: formatShortcut(['Alt','Enter'])},
{value: 'Command+Enter', label: formatShortcut(['Command','Enter'])},
{value: 'Shift+Enter', label: formatShortcut(['Shift','Enter'])}
]}
/>
) : (
<ShortcutInput <ShortcutInput
ref={(el) => { ref={(el) => {
if (el) { if (el) {

View File

@ -124,6 +124,14 @@ const initialState: ShortcutsState = {
editable: false, editable: false,
enabled: true, enabled: true,
system: true system: true
},
{
key: 'send_shortcuts',
shortcut: ['Enter'],
editable: true,
enabled: true,
system: true,
isSelector: true
} }
] ]
} }

View File

@ -503,6 +503,7 @@ export interface Shortcut {
editable: boolean editable: boolean
enabled: boolean enabled: boolean
system: boolean system: boolean
isSelector?: boolean
} }
export type ProcessingStatus = 'pending' | 'processing' | 'completed' | 'failed' export type ProcessingStatus = 'pending' | 'processing' | 'completed' | 'failed'