fix: Multiple UX improvements for GotoAnything command palette (#25637)

This commit is contained in:
lyzno1 2025-09-13 21:03:42 +08:00 • committed by GitHub
commit 36ab9974d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 772 additions and 45 deletions

View file

@ -169,6 +169,7 @@ import { pluginAction } from './plugin'
import { workflowNodesAction } from './workflow-nodes'
import type { ActionItem, SearchResult } from './types'
import { slashAction } from './commands'
import { slashCommandRegistry } from './commands/registry'
export const Actions = {
slash: slashAction,
@ -234,9 +235,23 @@ export const searchAnything = async (
export const matchAction = (query: string, actions: Record<string, ActionItem>) => {
return Object.values(actions).find((action) => {
// Special handling for slash commands to allow direct /theme, /lang
if (action.key === '/')
return query.startsWith('/')
// Special handling for slash commands
if (action.key === '/') {
// Get all registered commands from the registry
const allCommands = slashCommandRegistry.getAllCommands()
// Check if query matches any registered command
return allCommands.some((cmd) => {
const cmdPattern = `/${cmd.name}`
// For direct mode commands, don't match (keep in command selector)
if (cmd.mode === 'direct')
return false
// For submenu mode commands, match when complete command is entered
return query === cmdPattern || query.startsWith(`${cmdPattern} `)
})
}
const reg = new RegExp(`^(${action.key}|${action.shortcut})(?:\\s|$)`)
return reg.test(query)