11import { useTranslation } from "react-i18next" ;
2- import { Command } from "lucide-react" ;
2+ import { Command , RotateCcw } from "lucide-react" ;
33import { ChangeEvent , useEffect } from "react" ;
44
55import { formatKey } from "@/utils/keyboardUtils" ;
66import SettingsItem from "@/components/Settings/SettingsItem" ;
77import { isMac } from "@/utils/platform" ;
8- import { useShortcutsStore } from "@/stores/shortcutsStore" ;
8+ import {
9+ INITIAL_MODE_SWITCH ,
10+ INITIAL_RETURN_TO_INPUT ,
11+ INITIAL_VOICE_INPUT ,
12+ INITIAL_ADD_FILE ,
13+ INITIAL_DEEP_THINKING ,
14+ INITIAL_INTERNET_SEARCH ,
15+ INITIAL_INTERNET_SEARCH_SCOPE ,
16+ INITIAL_MCP_SEARCH ,
17+ INITIAL_MCP_SEARCH_SCOPE ,
18+ INITIAL_HISTORICAL_RECORDS ,
19+ INITIAL_AI_ASSISTANT ,
20+ INITIAL_NEW_SESSION ,
21+ INITIAL_FIXED_WINDOW ,
22+ INITIAL_SERVICE_LIST ,
23+ INITIAL_EXTERNAL ,
24+ useShortcutsStore ,
25+ } from "@/stores/shortcutsStore" ;
926import { ModifierKey } from "@/types/index" ;
1027import platformAdapter from "@/utils/platformAdapter" ;
28+ import { useAppStore } from "@/stores/appStore" ;
1129
1230export const modifierKeys : ModifierKey [ ] = isMac
1331 ? [ "meta" , "ctrl" ]
@@ -67,6 +85,7 @@ const Shortcuts = () => {
6785 const setServiceList = useShortcutsStore ( ( state ) => state . setServiceList ) ;
6886 const external = useShortcutsStore ( ( state ) => state . external ) ;
6987 const setExternal = useShortcutsStore ( ( state ) => state . setExternal ) ;
88+ const addError = useAppStore ( ( state ) => state . addError ) ;
7089
7190 useEffect ( ( ) => {
7291 const unlisten = useShortcutsStore . subscribe ( ( state ) => {
@@ -82,91 +101,136 @@ const Shortcuts = () => {
82101 description : "settings.advanced.shortcuts.modeSwitch.description" ,
83102 value : modeSwitch ,
84103 setValue : setModeSwitch ,
104+ reset : ( ) => {
105+ setModeSwitch ( INITIAL_MODE_SWITCH ) ;
106+ } ,
85107 } ,
86108 {
87109 title : "settings.advanced.shortcuts.returnToInput.title" ,
88110 description : "settings.advanced.shortcuts.returnToInput.description" ,
89111 value : returnToInput ,
90112 setValue : setReturnToInput ,
113+ reset : ( ) => {
114+ setReturnToInput ( INITIAL_RETURN_TO_INPUT ) ;
115+ } ,
91116 } ,
92117 {
93118 title : "settings.advanced.shortcuts.voiceInput.title" ,
94119 description : "settings.advanced.shortcuts.voiceInput.description" ,
95120 value : voiceInput ,
96121 setValue : setVoiceInput ,
122+ reset : ( ) => {
123+ setVoiceInput ( INITIAL_VOICE_INPUT ) ;
124+ } ,
97125 } ,
98126 {
99127 title : "settings.advanced.shortcuts.addFile.title" ,
100128 description : "settings.advanced.shortcuts.addFile.description" ,
101129 value : addFile ,
102130 setValue : setAddFile ,
131+ reset : ( ) => {
132+ setAddFile ( INITIAL_ADD_FILE ) ;
133+ } ,
103134 } ,
104135 {
105136 title : "settings.advanced.shortcuts.deepThinking.title" ,
106137 description : "settings.advanced.shortcuts.deepThinking.description" ,
107138 value : deepThinking ,
108139 setValue : setDeepThinking ,
140+ reset : ( ) => {
141+ setDeepThinking ( INITIAL_DEEP_THINKING ) ;
142+ } ,
109143 } ,
110144 {
111145 title : "settings.advanced.shortcuts.internetSearch.title" ,
112146 description : "settings.advanced.shortcuts.internetSearch.description" ,
113147 value : internetSearch ,
114148 setValue : setInternetSearch ,
149+ reset : ( ) => {
150+ setInternetSearch ( INITIAL_INTERNET_SEARCH ) ;
151+ } ,
115152 } ,
116153 {
117154 title : "settings.advanced.shortcuts.internetSearchScope.title" ,
118155 description :
119156 "settings.advanced.shortcuts.internetSearchScope.description" ,
120157 value : internetSearchScope ,
121158 setValue : setInternetSearchScope ,
159+ reset : ( ) => {
160+ setInternetSearchScope ( INITIAL_INTERNET_SEARCH_SCOPE ) ;
161+ } ,
122162 } ,
123163 {
124164 title : "settings.advanced.shortcuts.mcpSearch.title" ,
125165 description : "settings.advanced.shortcuts.mcpSearch.description" ,
126166 value : mcpSearch ,
127167 setValue : setMcpSearch ,
168+ reset : ( ) => {
169+ setMcpSearch ( INITIAL_MCP_SEARCH ) ;
170+ } ,
128171 } ,
129172 {
130173 title : "settings.advanced.shortcuts.mcpSearchScope.title" ,
131174 description : "settings.advanced.shortcuts.mcpSearchScope.description" ,
132175 value : mcpSearchScope ,
133176 setValue : setMcpSearchScope ,
177+ reset : ( ) => {
178+ setMcpSearchScope ( INITIAL_MCP_SEARCH_SCOPE ) ;
179+ } ,
134180 } ,
135181 {
136182 title : "settings.advanced.shortcuts.historicalRecords.title" ,
137183 description : "settings.advanced.shortcuts.historicalRecords.description" ,
138184 value : historicalRecords ,
139185 setValue : setHistoricalRecords ,
186+ reset : ( ) => {
187+ setHistoricalRecords ( INITIAL_HISTORICAL_RECORDS ) ;
188+ } ,
140189 } ,
141190 {
142191 title : "settings.advanced.shortcuts.aiAssistant.title" ,
143192 description : "settings.advanced.shortcuts.aiAssistant.description" ,
144193 value : aiAssistant ,
145194 setValue : setAiAssistant ,
195+ reset : ( ) => {
196+ setAiAssistant ( INITIAL_AI_ASSISTANT ) ;
197+ } ,
146198 } ,
147199 {
148200 title : "settings.advanced.shortcuts.newSession.title" ,
149201 description : "settings.advanced.shortcuts.newSession.description" ,
150202 value : newSession ,
151203 setValue : setNewSession ,
204+ reset : ( ) => {
205+ setNewSession ( INITIAL_NEW_SESSION ) ;
206+ } ,
152207 } ,
153208 {
154209 title : "settings.advanced.shortcuts.fixedWindow.title" ,
155210 description : "settings.advanced.shortcuts.fixedWindow.description" ,
156211 value : fixedWindow ,
157212 setValue : setFixedWindow ,
213+ reset : ( ) => {
214+ setFixedWindow ( INITIAL_FIXED_WINDOW ) ;
215+ } ,
158216 } ,
159217 {
160218 title : "settings.advanced.shortcuts.serviceList.title" ,
161219 description : "settings.advanced.shortcuts.serviceList.description" ,
162220 value : serviceList ,
163221 setValue : setServiceList ,
222+ reset : ( ) => {
223+ setServiceList ( INITIAL_SERVICE_LIST ) ;
224+ } ,
164225 } ,
165226 {
166227 title : "settings.advanced.shortcuts.external.title" ,
167228 description : "settings.advanced.shortcuts.external.description" ,
168229 value : external ,
169230 setValue : setExternal ,
231+ reset : ( ) => {
232+ setExternal ( INITIAL_EXTERNAL ) ;
233+ } ,
170234 } ,
171235 ] ;
172236
@@ -186,7 +250,16 @@ const Shortcuts = () => {
186250
187251 const isUsed = Object . values ( state ) . includes ( value ) ;
188252
189- if ( isSystemKey || isUsed ) return ;
253+ if ( isSystemKey ) {
254+ return addError (
255+ t ( "settings.advanced.shortcuts.hits.isSystem" ) ,
256+ "warning"
257+ ) ;
258+ }
259+
260+ if ( isUsed ) {
261+ return addError ( t ( "settings.advanced.shortcuts.hits.isUse" ) , "warning" ) ;
262+ }
190263
191264 setValue ( value ) ;
192265 } ;
@@ -217,7 +290,7 @@ const Shortcuts = () => {
217290 </ SettingsItem >
218291
219292 { list . map ( ( item ) => {
220- const { title, description, value, setValue } = item ;
293+ const { title, description, value, setValue, reset } = item ;
221294
222295 return (
223296 < SettingsItem
@@ -230,13 +303,20 @@ const Shortcuts = () => {
230303 < span > { formatKey ( modifierKey ) } </ span >
231304 < span > +</ span >
232305 < input
233- className = "w-20 h-8 px-2 rounded-md border bg-transparent border-black/5 dark:border-white/10"
306+ className = "w-20 h-8 px-2 rounded-md border bg-transparent border-black/5 dark:border-white/10 hover:border-[#0072FF] focus:border-[#0072FF] transition "
234307 value = { value }
235308 maxLength = { 1 }
236309 onChange = { ( event ) => {
237310 handleChange ( event , setValue ) ;
238311 } }
239312 />
313+
314+ < button
315+ className = "flex items-center justify-center size-8 rounded-md border border-black/5 dark:border-white/10 hover:border-[#0072FF] transition"
316+ onClick = { reset }
317+ >
318+ < RotateCcw className = "size-4 text-[#0072FF]" />
319+ </ button >
240320 </ div >
241321 </ SettingsItem >
242322 ) ;
0 commit comments