Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

Stop showing slash commands in general Go to Anything search (#29012)

yyh8e5cb86409eb
diff --git a/web/app/components/goto-anything/actions/index.ts b/web/app/components/goto-anything/actions/index.ts
index 0d4986f144e..6f8bb9564cb 100644
--- a/web/app/components/goto-anything/actions/index.ts
+++ b/web/app/components/goto-anything/actions/index.ts
@@ -214,8 +214,12 @@ export const searchAnything = async (
actionItem?: ActionItem,
dynamicActions?: Record<string, ActionItem>,
): Promise<SearchResult[]> => {
+ const trimmedQuery = query.trim()
+
if (actionItem) {
- const searchTerm = query.replace(actionItem.key, '').replace(actionItem.shortcut, '').trim()
+ const escapeRegExp = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
+ const prefixPattern = new RegExp(`^(${escapeRegExp(actionItem.key)}|${escapeRegExp(actionItem.shortcut)})\\s*`)
+ const searchTerm = trimmedQuery.replace(prefixPattern, '').trim()
try {
return await actionItem.search(query, searchTerm, locale)
}
@@ -225,10 +229,12 @@ export const searchAnything = async (
}
}
- if (query.startsWith('@') || query.startsWith('/'))
+ if (trimmedQuery.startsWith('@') || trimmedQuery.startsWith('/'))
return []
const globalSearchActions = Object.values(dynamicActions || Actions)
+ // Exclude slash commands from general search results
+ .filter(action => action.key !== '/')
// Use Promise.allSettled to handle partial failures gracefully
const searchPromises = globalSearchActions.map(async (action) => {
diff --git a/web/app/components/goto-anything/index.tsx b/web/app/components/goto-anything/index.tsx
index 5cdf9707253..50eddd1a43b 100644
--- a/web/app/components/goto-anything/index.tsx
+++ b/web/app/components/goto-anything/index.tsx
@@ -177,31 +177,42 @@ const GotoAnything: FC<Props> = ({
}
}, [router])
+ const dedupedResults = useMemo(() => {
+ const seen = new Set<string>()
+ return searchResults.filter((result) => {
+ const key = `${result.type}-${result.id}`
+ if (seen.has(key))
+ return false
+ seen.add(key)
+ return true
+ })
+ }, [searchResults])
+
// Group results by type
- const groupedResults = useMemo(() => searchResults.reduce((acc, result) => {
+ const groupedResults = useMemo(() => dedupedResults.reduce((acc, result) => {
if (!acc[result.type])
acc[result.type] = []
acc[result.type].push(result)
return acc
}, {} as { [key: string]: SearchResult[] }),
- [searchResults])
+ [dedupedResults])
useEffect(() => {
if (isCommandsMode)
return
- if (!searchResults.length)
+ if (!dedupedResults.length)
return
- const currentValueExists = searchResults.some(result => `${result.type}-${result.id}` === cmdVal)
+ const currentValueExists = dedupedResults.some(result => `${result.type}-${result.id}` === cmdVal)
if (!currentValueExists)
- setCmdVal(`${searchResults[0].type}-${searchResults[0].id}`)
- }, [isCommandsMode, searchResults, cmdVal])
+ setCmdVal(`${dedupedResults[0].type}-${dedupedResults[0].id}`)
+ }, [isCommandsMode, dedupedResults, cmdVal])
const emptyResult = useMemo(() => {
- if (searchResults.length || !searchQuery.trim() || isLoading || isCommandsMode)
+ if (dedupedResults.length || !searchQuery.trim() || isLoading || isCommandsMode)
return null
const isCommandSearch = searchMode !== 'general'
@@ -246,7 +257,7 @@ const GotoAnything: FC<Props> = ({
</div>
</div>
)
- }, [searchResults, searchQuery, Actions, searchMode, isLoading, isError, isCommandsMode])
+ }, [dedupedResults, searchQuery, Actions, searchMode, isLoading, isError, isCommandsMode])
const defaultUI = useMemo(() => {
if (searchQuery.trim())
@@ -430,14 +441,14 @@ const GotoAnything: FC<Props> = ({
{/* Always show footer to prevent height jumping */}
<div className='border-t border-divider-subtle bg-components-panel-bg-blur px-4 py-2 text-xs text-text-tertiary'>
<div className='flex min-h-[16px] items-center justify-between'>
- {(!!searchResults.length || isError) ? (
+ {(!!dedupedResults.length || isError) ? (
<>
<span>
{isError ? (
<span className='text-red-500'>{t('app.gotoAnything.someServicesUnavailable')}</span>
) : (
<>
- {t('app.gotoAnything.resultCount', { count: searchResults.length })}
+ {t('app.gotoAnything.resultCount', { count: dedupedResults.length })}
{searchMode !== 'general' && (
<span className='ml-2 opacity-60'>
{t('app.gotoAnything.inScope', { scope: searchMode.replace('@', '') })}