@@ -17,6 +17,7 @@ import { useTranslation } from 'react-i18next'
1717import InstallFromMarketplace from '../plugins/install-plugin/install-from-marketplace'
1818import type { Plugin } from '../plugins/types'
1919import { Command } from 'cmdk'
20+ import CommandSelector from './command-selector'
2021
2122type Props = {
2223 onHide ?: ( ) => void
@@ -81,11 +82,15 @@ const GotoAnything: FC<Props> = ({
8182 wait : 300 ,
8283 } )
8384
85+ const isCommandsMode = searchQuery . trim ( ) === '@'
86+
8487 const searchMode = useMemo ( ( ) => {
88+ if ( isCommandsMode ) return 'commands'
89+
8590 const query = searchQueryDebouncedValue . toLowerCase ( )
8691 const action = matchAction ( query , Actions )
8792 return action ? action . key : 'general'
88- } , [ searchQueryDebouncedValue , Actions ] )
93+ } , [ searchQueryDebouncedValue , Actions , isCommandsMode ] )
8994
9095 const { data : searchResults = [ ] , isLoading, isError, error } = useQuery (
9196 {
@@ -103,12 +108,20 @@ const GotoAnything: FC<Props> = ({
103108 const action = matchAction ( query , Actions )
104109 return await searchAnything ( defaultLocale , query , action )
105110 } ,
106- enabled : ! ! searchQueryDebouncedValue ,
111+ enabled : ! ! searchQueryDebouncedValue && ! isCommandsMode ,
107112 staleTime : 30000 ,
108113 gcTime : 300000 ,
109114 } ,
110115 )
111116
117+ const handleCommandSelect = useCallback ( ( commandKey : string ) => {
118+ setSearchQuery ( `${ commandKey } ` )
119+ setCmdVal ( '' )
120+ setTimeout ( ( ) => {
121+ inputRef . current ?. focus ( )
122+ } , 0 )
123+ } , [ ] )
124+
112125 // Handle navigation to selected result
113126 const handleNavigate = useCallback ( ( result : SearchResult ) => {
114127 setShow ( false )
@@ -141,7 +154,7 @@ const GotoAnything: FC<Props> = ({
141154 [ searchResults ] )
142155
143156 const emptyResult = useMemo ( ( ) => {
144- if ( searchResults . length || ! searchQueryDebouncedValue . trim ( ) || isLoading )
157+ if ( searchResults . length || ! searchQuery . trim ( ) || isLoading || isCommandsMode )
145158 return null
146159
147160 const isCommandSearch = searchMode !== 'general'
@@ -186,34 +199,22 @@ const GotoAnything: FC<Props> = ({
186199 </ div >
187200 </ div >
188201 )
189- } , [ searchResults , searchQueryDebouncedValue , Actions , searchMode , isLoading , isError ] )
202+ } , [ searchResults , searchQuery , Actions , searchMode , isLoading , isError , isCommandsMode ] )
190203
191204 const defaultUI = useMemo ( ( ) => {
192- if ( searchQueryDebouncedValue . trim ( ) )
205+ if ( searchQuery . trim ( ) )
193206 return null
194207
195- return ( < div className = "flex items-center justify-center py-8 text-center text-text-tertiary" >
208+ return ( < div className = "flex items-center justify-center py-12 text-center text-text-tertiary" >
196209 < div >
197210 < div className = 'text-sm font-medium' > { t ( 'app.gotoAnything.searchTitle' ) } </ div >
198- < div className = 'mt-3 space-y-2 text-xs text-text-quaternary' >
199- { Object . values ( Actions ) . map ( action => (
200- < div key = { action . key } className = 'flex items-center gap-2' >
201- < span className = 'inline-flex items-center rounded bg-gray-200 px-2 py-1 font-mono text-xs font-medium text-gray-600 dark:bg-gray-700 dark:text-gray-200' > { action . shortcut } </ span >
202- < span > { ( ( ) => {
203- const keyMap : Record < string , string > = {
204- '@app' : 'app.gotoAnything.actions.searchApplicationsDesc' ,
205- '@plugin' : 'app.gotoAnything.actions.searchPluginsDesc' ,
206- '@knowledge' : 'app.gotoAnything.actions.searchKnowledgeBasesDesc' ,
207- '@node' : 'app.gotoAnything.actions.searchWorkflowNodesDesc' ,
208- }
209- return t ( keyMap [ action . key ] )
210- } ) ( ) } </ span >
211- </ div >
212- ) ) }
211+ < div className = 'mt-3 space-y-1 text-xs text-text-quaternary' >
212+ < div > { t ( 'app.gotoAnything.searchHint' ) } </ div >
213+ < div > { t ( 'app.gotoAnything.commandHint' ) } </ div >
213214 </ div >
214215 </ div >
215216 </ div > )
216- } , [ searchQueryDebouncedValue , Actions ] )
217+ } , [ searchQuery , Actions ] )
217218
218219 useEffect ( ( ) => {
219220 if ( show ) {
@@ -296,7 +297,13 @@ const GotoAnything: FC<Props> = ({
296297 ) }
297298 { ! isLoading && ! isError && (
298299 < >
299- { Object . entries ( groupedResults ) . map ( ( [ type , results ] , groupIndex ) => (
300+ { isCommandsMode ? (
301+ < CommandSelector
302+ actions = { Actions }
303+ onCommandSelect = { handleCommandSelect }
304+ />
305+ ) : (
306+ Object . entries ( groupedResults ) . map ( ( [ type , results ] , groupIndex ) => (
300307 < Command . Group key = { groupIndex } heading = { ( ( ) => {
301308 const typeMap : Record < string , string > = {
302309 'app' : 'app.gotoAnything.groups.apps' ,
@@ -330,9 +337,10 @@ const GotoAnything: FC<Props> = ({
330337 </ Command . Item >
331338 ) ) }
332339 </ Command . Group >
333- ) ) }
334- { emptyResult }
335- { defaultUI }
340+ ) )
341+ ) }
342+ { ! isCommandsMode && emptyResult }
343+ { ! isCommandsMode && defaultUI }
336344 </ >
337345 ) }
338346 </ Command . List >
0 commit comments