fix: Multiple UX improvements for GotoAnything command palette (#25637)
This commit is contained in:
parent
a825f0f2b2
commit
36ab9974d2
17 changed files with 772 additions and 45 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue