:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(command): merge shortcuts into search palettes (#125726)
Fernando Gomesa7759844dd9a
diff --git a/frontend/src/layout/GlobalShortcuts.tsx b/frontend/src/layout/GlobalShortcuts.tsxindex cc325bc36906..b2316209fc16 100644--- a/frontend/src/layout/GlobalShortcuts.tsx+++ b/frontend/src/layout/GlobalShortcuts.tsx@@ -5,7 +5,6 @@ import { newAccountMenuLogic } from 'lib/components/Account/newAccountMenuLogic'import { commandLogic } from 'lib/components/Command/commandLogic'import { openJumpToTimestampModal } from 'lib/components/DateFilter/openJumpToTimestampModal'import { helpMenuLogic } from 'lib/components/HelpMenu/helpMenuLogic'-import { shortcutLogic } from 'lib/components/Shortcuts/shortcutLogic'import { keyBinds } from 'lib/components/Shortcuts/shortcuts'import { useShortcut } from 'lib/components/Shortcuts/useShortcut'import { openCHQueriesDebugModal } from 'lib/components/Shortcuts/utils/DebugCHQueries'@@ -20,8 +19,6 @@ import { themeLogic } from './navigation-3000/themeLogic'export function GlobalShortcuts(): null {const { superpowersEnabled, user, excludedFromPostHogTeamCohort } = useValues(superpowersLogic)const { setExcludedFromPostHogTeamCohort } = useActions(superpowersLogic)- const { shortcutMenuOpen } = useValues(shortcutLogic)- const { setShortcutMenuOpen } = useActions(shortcutLogic)const { toggleCommand } = useActions(commandLogic)const { toggleHelpMenu } = useActions(helpMenuLogic)const { toggleAccountMenu, toggleProjectSwitcher, toggleOrgSwitcher } = useActions(newAccountMenuLogic)@@ -43,14 +40,6 @@ export function GlobalShortcuts(): null {priority: 10,})- useShortcut({- name: 'ToggleShortcutMenu',- keybind: [keyBinds.toggleShortcutMenu, keyBinds.toggleShortcutMenuFallback],- intent: 'Toggle shortcut menu',- interaction: 'function',- callback: () => setShortcutMenuOpen(!shortcutMenuOpen),- })-useShortcut({name: 'DebugClickhouseQueries',keybind: [['command', 'option', 'tab']],diff --git a/frontend/src/layout/navigation-3000/sidepanel/SidePanelNavigation.tsx b/frontend/src/layout/navigation-3000/sidepanel/SidePanelNavigation.tsxindex 2283921f4a80..3e1f75aaf76c 100644--- a/frontend/src/layout/navigation-3000/sidepanel/SidePanelNavigation.tsx+++ b/frontend/src/layout/navigation-3000/sidepanel/SidePanelNavigation.tsx@@ -4,7 +4,7 @@ import { useActions, useValues } from 'kea'import { IconSparkles, IconX } from '@posthog/icons'import { Tooltip } from '@posthog/lemon-ui'-import { RenderKeybind } from 'lib/components/Shortcuts/ShortcutMenu'+import { RenderKeybind } from 'lib/components/Shortcuts/RenderKeybind'import { keyBinds } from 'lib/components/Shortcuts/shortcuts'import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'import { cn } from 'lib/utils/css-classes'diff --git a/frontend/src/layout/scenes/SceneLayout.tsx b/frontend/src/layout/scenes/SceneLayout.tsxindex 2cef94b16d7b..c357ee43372b 100644--- a/frontend/src/layout/scenes/SceneLayout.tsx+++ b/frontend/src/layout/scenes/SceneLayout.tsx@@ -6,7 +6,6 @@ import { createPortal } from 'react-dom'import { LemonDivider } from '@posthog/lemon-ui'-import { ShortcutMenu } from 'lib/components/Shortcuts/ShortcutMenu'import { Label, LabelProps } from 'lib/ui/Label/Label'import { cn } from 'lib/utils/css-classes'import { SceneConfig } from 'scenes/sceneTypes'@@ -78,11 +77,5 @@ export function SceneLayout({ children, sceneConfig }: SceneLayoutProps): JSX.El}}, [sceneConfig, setSceneLayoutConfig])- return (- <SceneMenuBarSlotProvider>- {children}-- <ShortcutMenu />- </SceneMenuBarSlotProvider>- )+ return <SceneMenuBarSlotProvider>{children}</SceneMenuBarSlotProvider>}diff --git a/frontend/src/layout/scenes/components/SceneTitlePanelButton.tsx b/frontend/src/layout/scenes/components/SceneTitlePanelButton.tsxindex 6cadb09f012a..101aae50bcb8 100644--- a/frontend/src/layout/scenes/components/SceneTitlePanelButton.tsx+++ b/frontend/src/layout/scenes/components/SceneTitlePanelButton.tsx@@ -3,7 +3,7 @@ import posthog from 'posthog-js'import { IconBrackets, IconSidePanel, IconSparkles, IconWrench } from '@posthog/icons'-import { RenderKeybind } from 'lib/components/Shortcuts/ShortcutMenu'+import { RenderKeybind } from 'lib/components/Shortcuts/RenderKeybind'import { keyBinds } from 'lib/components/Shortcuts/shortcuts'import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'diff --git a/frontend/src/lib/components/Account/AccountMenu.tsx b/frontend/src/lib/components/Account/AccountMenu.tsxindex 9e2a8577c1c2..85768f03ef1e 100644--- a/frontend/src/lib/components/Account/AccountMenu.tsx+++ b/frontend/src/lib/components/Account/AccountMenu.tsx@@ -58,7 +58,6 @@ import { AccessLevelIndicator } from '~/layout/navigation/AccessLevelIndicator'import { getTreeItemsGames } from '~/products'import { UserTheme } from '~/types'-import { shortcutLogic } from '../Shortcuts/shortcutLogic'import { openCHQueriesDebugModal } from '../Shortcuts/utils/DebugCHQueries'import { OrgCombobox } from './OrgCombobox'@@ -146,7 +145,6 @@ export function AccountMenu({ trigger, ...props }: AccountMenuProps): JSX.Elemenconst { reportInviteMembersButtonClicked } = useActions(eventUsageLogic)const { reportAccountOwnerClicked } = useActions(eventUsageLogic)const { logout } = useActions(userLogic)- const { setShortcutMenuOpen } = useActions(shortcutLogic)return (<DropdownMenu>@@ -306,23 +304,6 @@ export function AccountMenu({ trigger, ...props }: AccountMenuProps): JSX.Elemen<ThemeMenu />- <DropdownMenuItem asChild>- <ButtonPrimitive- tooltip="Open shortcut menu"- tooltipPlacement="right"- onClick={() => setShortcutMenuOpen(true)}- menuItem- >- <span className="size-4 flex items-center justify-center">⌘</span>- Shortcuts- <div className="flex gap-1 ml-auto items-center">- <KeyboardShortcut command option k />- <span className="text-xs opacity-75">or</span>- <KeyboardShortcut command shift k />- </div>- </ButtonPrimitive>- </DropdownMenuItem>-<DropdownMenuItem asChild><Linkto="https://posthog.com/changelog"diff --git a/frontend/src/lib/components/Account/NewAccountMenu.tsx b/frontend/src/lib/components/Account/NewAccountMenu.tsxindex 401fdb494a07..1e0c536dea21 100644--- a/frontend/src/lib/components/Account/NewAccountMenu.tsx+++ b/frontend/src/lib/components/Account/NewAccountMenu.tsx@@ -37,7 +37,7 @@ import { globalModalsLogic } from '~/layout/globalModalsLogic'import { AvailableFeature } from '~/types'import { ScrollableShadows } from '../ScrollableShadows/ScrollableShadows'-import { RenderKeybind } from '../Shortcuts/ShortcutMenu'+import { RenderKeybind } from '../Shortcuts/RenderKeybind'import { keyBinds } from '../Shortcuts/shortcuts'import { upgradeModalLogic } from '../UpgradeModal/upgradeModalLogic'import { newAccountMenuLogic } from './newAccountMenuLogic'diff --git a/frontend/src/lib/components/CommandKSearch/COMMAND_K_SEARCH_UX.md b/frontend/src/lib/components/CommandKSearch/COMMAND_K_SEARCH_UX.mdindex 2df647fe9172..80988e0ccc84 100644--- a/frontend/src/lib/components/CommandKSearch/COMMAND_K_SEARCH_UX.md+++ b/frontend/src/lib/components/CommandKSearch/COMMAND_K_SEARCH_UX.md@@ -94,7 +94,7 @@ The input is always in exactly one mode, decided from the token under the cursor- A search with words goes to the ranked search endpoint (`file_system/search/`). A search made only of filters goes to the list endpoint, because there are no words to rank.- Sections, in this fixed order, covering everything the current palette finds:1. **Results**: file system objects (insights, dashboards, feature flags, experiments, surveys, notebooks, cohorts, actions, early access features, replay playlists, data pipelines), and products. For a search with words, see [Ranked results](#ranked-results).- 2. In-memory lists, filtered on every keystroke: **Data management**, **People**, **Health**, **Misc**, **Settings** (with a Dark mode / Light mode row for "dark", "light", "theme", "appearance"), **Create new**. For a search with words they keep only items that match every word with no typo. Products rank with the results instead. In the test group of the `command-k-settings-in-results` experiment, settings that match every word with no typo also rank with the results, unless a product has the same name, and the **Settings** section lists only the ones that did not.+ 2. In-memory lists, filtered on every keystroke: **Data management**, **People**, **Health**, **Misc**, **Shortcuts** (with their key bindings), **Settings** (with a Dark mode / Light mode row for "dark", "light", "theme", "appearance"), **Create new**. For a search with words they keep only items that match every word with no typo. Products rank with the results instead. In the test group of the `command-k-settings-in-results` experiment, settings that match every word with no typo also rank with the results, unless a product has the same name, and the **Settings** section lists only the ones that did not.3. Remote lists that the file system does not hold: **Events**, **Properties**, **Workflows** (one unified search request), **Accounts** (behind the customer analytics flag, excluding accounts already shown in ranked results), **Support tickets** (3+ characters or a ticket number).4. **Ask PostHog AI**.5. **Persons**, **Groups**. Person and group searches can take seconds, so they usually come last. The person search starts with the file system search, after 50 ms. A search that contains "@" waits for the person search and ranks the persons it finds with **Results** / **Best matches**. A person who matches every word comes first. Persons that do not rank stay in **Persons** below, with no duplicates. Other searches do not wait for persons or groups.diff --git a/frontend/src/lib/components/CommandKSearch/CommandKSearchRow.tsx b/frontend/src/lib/components/CommandKSearch/CommandKSearchRow.tsxindex fb1b64b5d492..f3160db058cb 100644--- a/frontend/src/lib/components/CommandKSearch/CommandKSearchRow.tsx+++ b/frontend/src/lib/components/CommandKSearch/CommandKSearchRow.tsx@@ -88,6 +88,7 @@ function RowContent({ row }: { row: CommandKRow }): JSX.Element | null {{item.productCategory && (<span className="shrink-0 text-xs text-muted-foreground">{item.productCategory}</span>)}+ {item.keybinding && <span className="ml-auto shrink-0">{item.keybinding}</span>}{item.matchedSearchKeyword && (<span className="ml-auto truncate text-xxs text-muted-foreground">Matches "{item.matchedSearchKeyword}"diff --git a/frontend/src/lib/components/CommandKSearch/commandKSearchLogic.tsx b/frontend/src/lib/components/CommandKSearch/commandKSearchLogic.tsxindex 86e0358fc2c3..648813f633cf 100644--- a/frontend/src/lib/components/CommandKSearch/commandKSearchLogic.tsx+++ b/frontend/src/lib/components/CommandKSearch/commandKSearchLogic.tsx@@ -16,6 +16,7 @@ import { commandLogic } from 'lib/components/Command/commandLogic'import { SearchItem, fileSystemEntryToSearchItem } from 'lib/components/Search/searchItems'import { searchListsLogic } from 'lib/components/Search/searchListsLogic'import { canOpenInNewTab } from 'lib/components/Search/utils'+import { shortcutLogic } from 'lib/components/Shortcuts/shortcutLogic'import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { themeLogic } from 'lib/logic/themeLogic'@@ -105,6 +106,7 @@ export interface commandKSearchLogicValues {productsItems: SearchItem[] // searchListsLogicsettingsItems: SearchItem[] // searchListsLogicstarredItems: SearchItem[] // searchListsLogic+ shortcutItems: SearchItem[] // shortcutLogiccurrentTeamId: number | null // teamLogicisDarkModeOn: boolean // themeLogicuser: UserType | null // userLogic@@ -310,6 +312,7 @@ export interface commandKSearchLogicMeta {localLists: (recentItems: SearchItem[],starredItems: SearchItem[],+ shortcutItems: SearchItem[],productsItems: SearchItem[],settingsItems: SearchItem[],newItems: SearchItem[],@@ -405,6 +408,8 @@ export const commandKSearchLogic = kea<commandKSearchLogicType>([['groupTypes', 'aggregationLabel'],themeLogic,['isDarkModeOn'],+ shortcutLogic,+ ['shortcutItems'],],actions: [commandLogic,@@ -642,6 +647,7 @@ export const commandKSearchLogic = kea<commandKSearchLogicType>([(s) => [s.recentItems,s.starredItems,+ s.shortcutItems,s.productsItems,s.settingsItems,s.newItems,@@ -653,6 +659,7 @@ export const commandKSearchLogic = kea<commandKSearchLogicType>([(recents: SearchItem[],starred: SearchItem[],+ shortcuts: SearchItem[],products: SearchItem[],settings: SearchItem[],create: SearchItem[],@@ -663,6 +670,7 @@ export const commandKSearchLogic = kea<commandKSearchLogicType>([): LocalLists => ({recents,starred,+ shortcuts,products,settings,create,diff --git a/frontend/src/lib/components/CommandKSearch/commandKSections.test.ts b/frontend/src/lib/components/CommandKSearch/commandKSections.test.tsindex 8b7104ffa79c..8f7e52d9cbc3 100644--- a/frontend/src/lib/components/CommandKSearch/commandKSections.test.ts+++ b/frontend/src/lib/components/CommandKSearch/commandKSections.test.ts@@ -34,6 +34,7 @@ const emptyLocal = (): LocalLists => ({people: [],health: [],misc: [],+ shortcuts: [],settings: [],create: [],recents: [],@@ -76,6 +77,14 @@ const remoteResults = (items: SearchItem[]): Partial<SectionsInput> => {}describe('buildSections', () => {+ it('shows every shortcut last when the input is empty', () => {+ const shortcuts = [dashboard('shortcut-1', '1'), dashboard('shortcut-2', '2')]+ const sections = buildSections(input('empty', { local: { ...emptyLocal(), shortcuts } }))++ expect(sections.at(-1)?.key).toBe('shortcuts')+ expect(sections.at(-1)?.rows).toHaveLength(2)+ })+test.each<[string, SectionsInput, string, number]>([['remote results', input('search', remoteResults(itemsWithRepeats(RESULTS_LIMIT))), 'results', RESULTS_LIMIT],[diff --git a/frontend/src/lib/components/CommandKSearch/commandKSections.ts b/frontend/src/lib/components/CommandKSearch/commandKSections.tsindex 723a17f14724..9b60572e9d7d 100644--- a/frontend/src/lib/components/CommandKSearch/commandKSections.ts+++ b/frontend/src/lib/components/CommandKSearch/commandKSections.ts@@ -13,7 +13,16 @@ export const DEFAULT_SKELETON_ROWS = 3const TRAILING_SOURCES: RemoteSource[] = ['persons', 'groups']/** Lists that filter in memory on every keystroke, in the order they render in Search mode. */-const LOCAL_SOURCES = ['products', 'data-management', 'people', 'health', 'misc', 'settings', 'create'] as const+const LOCAL_SOURCES = [+ 'products',+ 'data-management',+ 'people',+ 'health',+ 'misc',+ 'shortcuts',+ 'settings',+ 'create',+] as consttype LocalSource = (typeof LOCAL_SOURCES)[number]export type CommandKMode = 'empty' | 'key' | 'value' | 'search'@@ -89,6 +98,7 @@ const SECTION_LABELS: Record<Exclude<CommandKSectionKey, `group-${string}`>, strpeople: 'People',health: 'Health',misc: 'Misc',+ shortcuts: 'Shortcuts',settings: 'Settings',create: 'Create new',events: 'Events',@@ -399,6 +409,7 @@ export function buildSections(input: SectionsInput): CommandKSection[] {local.products.filter((item) => !item.parentName))),+ readySection('shortcuts', itemRows('shortcuts', local.shortcuts)),].filter((section) => section.rows.length > 0)}diff --git a/frontend/src/lib/components/HelpMenu/HelpMenu.tsx b/frontend/src/lib/components/HelpMenu/HelpMenu.tsxindex c385cf055127..575b20efc97a 100644--- a/frontend/src/lib/components/HelpMenu/HelpMenu.tsx+++ b/frontend/src/lib/components/HelpMenu/HelpMenu.tsx@@ -22,7 +22,7 @@ import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePaneimport { SidePanelTab } from '~/types'import { ScrollableShadows } from '../ScrollableShadows/ScrollableShadows'-import { RenderKeybind } from '../Shortcuts/ShortcutMenu'+import { RenderKeybind } from '../Shortcuts/RenderKeybind'import { keyBinds } from '../Shortcuts/shortcuts'import { openCHQueriesDebugModal } from '../Shortcuts/utils/DebugCHQueries'import { healthSummaryLabel } from './healthSummaryLabel'diff --git a/frontend/src/lib/components/NavSearchButton/NavSearchButton.tsx b/frontend/src/lib/components/NavSearchButton/NavSearchButton.tsxindex 4e04e5641dda..2bf2751261cc 100644--- a/frontend/src/lib/components/NavSearchButton/NavSearchButton.tsx+++ b/frontend/src/lib/components/NavSearchButton/NavSearchButton.tsx@@ -1,7 +1,7 @@import { IconSearch } from '@posthog/icons'import { CommandOpenSource } from 'lib/components/Command/commandLogic'-import { RenderKeybind } from 'lib/components/Shortcuts/ShortcutMenu'+import { RenderKeybind } from 'lib/components/Shortcuts/RenderKeybind'import { keyBinds } from 'lib/components/Shortcuts/shortcuts'import posthog from 'lib/posthog-typed'import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'diff --git a/frontend/src/lib/components/Search/Search.tsx b/frontend/src/lib/components/Search/Search.tsxindex 27d5586d8bb5..5609d2f3f256 100644--- a/frontend/src/lib/components/Search/Search.tsx+++ b/frontend/src/lib/components/Search/Search.tsx@@ -341,8 +341,8 @@ function SearchRoot({for (const category of allCategories) {items.push(...category.items)}- return items- }, [allCategories])+ return logicKey === 'command' ? items : items.filter((item) => item.category !== 'shortcuts')+ }, [allCategories, logicKey])// Compute filteredItems synchronously to avoid render gap between loading and contentconst filteredItems = useMemo(() => {@@ -355,8 +355,8 @@ function SearchRoot({const filteredClientItems = filterSearchItems(clientItems, searchValue)items = [...filteredClientItems, ...serverItems]} else {- // When not searching, show recents, starred, and tools- items = allItems.filter((item) => ['recents', 'starred', 'tools'].includes(item.category))+ // When not searching, show recents, starred, tools, and shortcuts+ items = allItems.filter((item) => ['recents', 'starred', 'tools', 'shortcuts'].includes(item.category))}// Add a direct shortcut to the theme setting when searching for dark/light/theme@@ -928,6 +928,11 @@ function SearchResults({{item.productCategory}</span>)}+ {item.keybinding && (+ <span className="ml-auto shrink-0">+ {item.keybinding}+ </span>+ )}{item.matchedSearchKeyword && (<span className="ml-auto text-xxs text-tertiary truncate mt-[2px]">{`Matches "${item.matchedSearchKeyword}"`}diff --git a/frontend/src/lib/components/Search/searchItems.tsx b/frontend/src/lib/components/Search/searchItems.tsxindex a0914e6ca60d..63c012156b90 100644--- a/frontend/src/lib/components/Search/searchItems.tsx+++ b/frontend/src/lib/components/Search/searchItems.tsx@@ -33,6 +33,7 @@ export interface SearchItem {* other than navigation (e.g. logging out). Consumers should prefer `onSelect` over `href`. */onSelect?: () => voidicon?: React.ReactNode+ keybinding?: React.ReactNodelastViewedAt?: string | nullgroupNoun?: string | nullitemType?: string | nulldiff --git a/frontend/src/lib/components/Search/searchLogic.tsx b/frontend/src/lib/components/Search/searchLogic.tsxindex d8c67f75b6e3..81b146448b86 100644--- a/frontend/src/lib/components/Search/searchLogic.tsx+++ b/frontend/src/lib/components/Search/searchLogic.tsx@@ -3,6 +3,7 @@ import type { BreakPointFunction } from 'kea'import { loaders } from 'kea-loaders'import api, { isAbortError } from 'lib/api'+import { shortcutLogic } from 'lib/components/Shortcuts/shortcutLogic'import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { getEntryAccessDisabledReason } from 'lib/utils/accessControlUtils'@@ -82,6 +83,7 @@ export interface searchLogicValues {productsItems: SearchItem[] // searchListsLogicsettingsItems: SearchItem[] // searchListsLogicstarredItems: SearchItem[] // searchListsLogic+ shortcutItems: SearchItem[] // shortcutLogiccurrentTeamId: number | null // teamLogicaccountItems: SearchItem[]accountSearchResults: AccountApi[]@@ -119,6 +121,7 @@ export interface searchLogicValues {searchPending: booleansearchedRecents: FileSystemEntry[] | nullsearchedRecentsLoading: boolean+ shortcutAndMiscItems: SearchItem[]ticketItems: SearchItem[]ticketSearchResults: TicketApi[]ticketSearchResultsLoading: boolean@@ -340,6 +343,7 @@ export interface searchLogicMeta {ticketSearchResultsLoading: booleanunifiedSearchResultsLoading: boolean}+ shortcutAndMiscItems: (shortcutItems: SearchItem[], miscItems: SearchItem[]) => SearchItem[]allCategories: (recentItems: SearchItem[],starredItems: SearchItem[],@@ -347,7 +351,7 @@ export interface searchLogicMeta {dataManagementItems: SearchItem[],peopleItems: SearchItem[],healthItems: SearchItem[],- miscItems: SearchItem[],+ shortcutAndMiscItems: SearchItem[],settingsItems: SearchItem[],newItems: SearchItem[],personItems: SearchItem[],@@ -405,6 +409,8 @@ export const searchLogic = kea<searchLogicType>([['recents as cachedRecents', 'recentsHasLoaded', 'sceneLogViewsHasLoaded'],projectTreeDataLogic,['shortcutDataHasLoaded'],+ shortcutLogic,+ ['shortcutItems'],],})),actions({@@ -811,6 +817,10 @@ export const searchLogic = kea<searchLogicType>([playlistSearchResultsLoading,}),],+ shortcutAndMiscItems: [+ (s) => [s.shortcutItems, s.miscItems],+ (shortcutItems: SearchItem[], miscItems: SearchItem[]): SearchItem[] => [...shortcutItems, ...miscItems],+ ],allCategories: [(s) => [s.recentItems,@@ -819,7 +829,7 @@ export const searchLogic = kea<searchLogicType>([s.dataManagementItems,s.peopleItems,s.healthItems,- s.miscItems,+ s.shortcutAndMiscItems,s.settingsItems,s.newItems,s.personItems,@@ -837,7 +847,7 @@ export const searchLogic = kea<searchLogicType>([dataManagementItems: SearchItem[],peopleItems: SearchItem[],healthItems: SearchItem[],- miscItems: SearchItem[],+ shortcutAndMiscItems: SearchItem[],settingsItems: SearchItem[],newItems: SearchItem[],personItems: SearchItem[],@@ -959,7 +969,7 @@ export const searchLogic = kea<searchLogicType>([}// Show misc items if searching with matching results- const filteredMisc = filterBySearch(miscItems)+ const filteredMisc = filterBySearch(shortcutAndMiscItems.filter((item) => item.category === 'misc'))if (hasSearch && filteredMisc.length > 0) {categories.push({key: 'misc',@@ -1070,6 +1080,17 @@ export const searchLogic = kea<searchLogicType>([}}+ const filteredShortcuts = filterBySearch(+ shortcutAndMiscItems.filter((item) => item.category === 'shortcuts')+ )+ if (filteredShortcuts.length > 0) {+ categories.push({+ key: 'shortcuts',+ items: filteredShortcuts,+ isLoading: false,+ })+ }+return categories},],diff --git a/frontend/src/lib/components/Search/utils.ts b/frontend/src/lib/components/Search/utils.tsindex fe4f62ef4c08..9b7299d74da6 100644--- a/frontend/src/lib/components/Search/utils.ts+++ b/frontend/src/lib/components/Search/utils.ts@@ -118,6 +118,7 @@ export const getCategoryDisplayName = (category: string): string => {tools: 'Products','data-management': 'Data management',[SEARCH_TAB_CATEGORY]: 'Tabs',+ shortcuts: 'Shortcuts',settings: 'Settings',early_access_feature: 'Early access features',suggested: 'Suggested',diff --git a/frontend/src/lib/components/Shortcuts/RenderKeybind.tsx b/frontend/src/lib/components/Shortcuts/RenderKeybind.tsxnew file mode 100644index 000000000000..b55a055e24d1--- /dev/null+++ b/frontend/src/lib/components/Shortcuts/RenderKeybind.tsx@@ -0,0 +1,44 @@+import React from 'react'++import { KeyboardShortcut } from 'lib/components/KeyboardShortcut/KeyboardShortcut'+import { cn } from 'lib/utils/css-classes'++interface RenderKeybindProps {+ keybind: string[][]+ className?: string+ minimal?: boolean+}++export function RenderKeybind({ keybind, className, minimal }: RenderKeybindProps): JSX.Element {+ return (+ <span className={cn('inline-flex items-center gap-1', className)}>+ {keybind.map((keybindOption, index) => {+ const isSequence = keybindOption.includes('then')+ if (isSequence) {+ const keys = keybindOption.filter((k) => k !== 'then')+ return (+ <React.Fragment key={index}>+ {index > 0 && <span className="mx-1 text-xxs opacity-75">or</span>}+ {keys.map((key, keyIndex) => (+ <React.Fragment key={key}>+ {keyIndex > 0 && <span className="mx-1 opacity-50 lowercase text-xxs">then</span>}+ <kbd className="KeyboardShortcut gap-x-0.5 text-xxs">{key}</kbd>+ </React.Fragment>+ ))}+ </React.Fragment>+ )+ }+ return (+ <React.Fragment key={index}>+ {index > 0 && <span className="mx-1 text-xxs opacity-75">or</span>}+ <KeyboardShortcut+ {...Object.fromEntries(keybindOption.map((key: string) => [key, true]))}+ className="text-xs"+ minimal={minimal}+ />+ </React.Fragment>+ )+ })}+ </span>+ )+}diff --git a/frontend/src/lib/components/Shortcuts/Shortcut.tsx b/frontend/src/lib/components/Shortcuts/Shortcut.tsxindex 2158d81911f9..25e4e63e3f76 100644--- a/frontend/src/lib/components/Shortcuts/Shortcut.tsx+++ b/frontend/src/lib/components/Shortcuts/Shortcut.tsx@@ -3,8 +3,8 @@ import { ReactElement, cloneElement, forwardRef, isValidElement } from 'react'import { cn } from 'lib/utils/css-classes'+import { RenderKeybind } from './RenderKeybind'import { ShortcutType } from './shortcutLogic'-import { RenderKeybind } from './ShortcutMenu'import { convertPlatformKeybind, useShortcut } from './useShortcut'export function keybindToKeyboardShortcutProps(keybind: string[]): Record<string, boolean> {diff --git a/frontend/src/lib/components/Shortcuts/ShortcutMenu.tsx b/frontend/src/lib/components/Shortcuts/ShortcutMenu.tsxdeleted file mode 100644index b873afafcd7d..000000000000--- a/frontend/src/lib/components/Shortcuts/ShortcutMenu.tsx+++ /dev/null@@ -1,350 +0,0 @@-import { useActions, useValues } from 'kea'-import React, { useCallback, useEffect, useMemo, useRef } from 'react'-import { createPortal } from 'react-dom'--import { IconArrowRight } from '@posthog/icons'--import { KeyboardShortcut } from 'lib/components/KeyboardShortcut/KeyboardShortcut'-import { IconAction } from 'lib/lemon-ui/icons'-import { LemonSwitch } from 'lib/lemon-ui/LemonSwitch'-import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'-import { DropdownMenuSeparator } from 'lib/ui/DropdownMenu/DropdownMenu'-import { Label } from 'lib/ui/Label/Label'-import { ListBoxHandle } from 'lib/ui/ListBox/ListBox'-import { cn } from 'lib/utils/css-classes'-import { sceneLogic } from 'scenes/sceneLogic'-import { Scene } from 'scenes/sceneTypes'--import { Combobox } from '~/lib/ui/Combobox/Combobox'--import { ShortcutType, shortcutLogic } from './shortcutLogic'--function titleForKey(key: string): string {- switch (key) {- case 'global':- return 'App'- case Scene.SavedInsights:- return 'Product Analytics'- default:- // Split capitalized case (e.g. ProductAnalytics -> Product Analytics)- return key.replace(/([A-Z])/g, ' $1').replace(/^ /, '')- }-}--function getShortcutIcon(shortcut: ShortcutType): JSX.Element | null {- switch (shortcut.interaction) {- case 'focus':- return (- <div className="flex items-center gap-1 size-4">- <IconAction className="w-4 h-4 text-muted" />- </div>- )- case 'click':- default:- return (- <div className="flex items-center gap-1 size-4">- <IconArrowRight className="w-4 h-4 text-muted" />- </div>- )- }-}--interface RenderKeybindProps {- keybind: string[][]- className?: string- minimal?: boolean-}--export function RenderKeybind({ keybind, className, minimal }: RenderKeybindProps): JSX.Element {- return (- <span className={cn('inline-flex items-center gap-1', className)}>- {keybind.map((keybindOption, index) => {- const isSequence = keybindOption.includes('then')- if (isSequence) {- const keys = keybindOption.filter((k) => k !== 'then')- return (- <React.Fragment key={index}>- {index > 0 && <span className="text-xxs opacity-75">or</span>}- {keys.map((key, keyIndex) => (- <React.Fragment key={key}>- {keyIndex > 0 && <span className="opacity-50 lowercase text-xxs">then</span>}- <kbd className="KeyboardShortcut gap-x-0.5 text-xxs">{key}</kbd>- </React.Fragment>- ))}- </React.Fragment>- )- }- return (- <React.Fragment key={index}>- {index > 0 && <span className="text-xxs opacity-75">or</span>}- <KeyboardShortcut- {...Object.fromEntries(keybindOption.map((key: string) => [key, true]))}- className="text-xs"- minimal={minimal}- />- </React.Fragment>- )- })}- </span>- )-}--export function ShortcutMenu(): JSX.Element | null {- const { shortcutMenuOpen, disabledShortcutNames } = useValues(shortcutLogic)- const { setShortcutMenuOpen, toggleShortcutDisabled } = useActions(shortcutLogic)- const { registeredShortcuts } = useValues(shortcutLogic)- const { sceneId } = useValues(sceneLogic)- const comboboxRef = useRef<ListBoxHandle>(null)-- // Group shortcuts by scope, with scene-specific first and global last- const groupedShortcuts = useMemo(() => {- const groups: Record<string, ShortcutType[]> = {}- const currentScene = sceneId-- registeredShortcuts.forEach((shortcut) => {- const scope = shortcut.scope || 'global'-- // Only include shortcuts that are global or match the current scene- if (scope === 'global' || scope === currentScene) {- if (!groups[scope]) {- groups[scope] = []- }- groups[scope].push(shortcut)- }- })-- // Sort groups: scene-specific first, then 'global' last- const sortedGroupKeys = Object.keys(groups).sort((a, b) => {- if (a === 'global') {- return 1- }- if (b === 'global') {- return -1- }-- return a.localeCompare(b)- })-- // Inside each group: priority first, then alphabetically- for (const key of sortedGroupKeys) {- groups[key].sort((a, b) => {- const priorityDiff = (b.priority ?? 0) - (a.priority ?? 0)- if (priorityDiff !== 0) {- return priorityDiff- }-- return a.intent.localeCompare(b.intent)- })- }-- return sortedGroupKeys.map((key) => ({- key,- title: titleForKey(key),- shortcuts: groups[key],- }))- }, [registeredShortcuts, sceneId])-- const handleClose = useCallback(() => {- setShortcutMenuOpen(false)- }, [setShortcutMenuOpen])-- const handleItemClick = useCallback(- (shortcut: ShortcutType) => {- if (shortcut.interaction === 'click') {- shortcut.ref.current?.click()- } else if (shortcut.interaction === 'focus') {- shortcut.ref.current?.focus()- } else if (shortcut.interaction === 'function') {- shortcut.callback()- }-- // Always close the menu after executing a shortcut- handleClose()- },- [handleClose]- )-- const handleKeyDown = useCallback(- (event: React.KeyboardEvent) => {- if (event.key === 'Option') {- event.preventDefault()- event.stopPropagation()- return- }- if (event.key === 'Escape') {- event.preventDefault()- handleClose()- } else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {- // Let the combobox handle arrow navigation- return- } else if (event.key === 'Enter') {- // Handle Enter key directly to avoid ListBox focus issues- event.preventDefault()- event.stopPropagation()-- // Find the currently focused/selected shortcut by looking at the virtual focus- const focusedElement = document.querySelector('#scene-action-palette [data-focused="true"]')- if (focusedElement) {- // Get the shortcut name from the data attribute- const shortcutName = focusedElement.getAttribute('data-shortcut-name')- if (shortcutName) {- const shortcut = registeredShortcuts.find((s) => s.name === shortcutName)- if (shortcut) {- handleItemClick(shortcut)- }- }- }- return- }-- // For any other key (typing in search), ensure search input stays focused and first item is selected- if (event.target && (event.target as HTMLElement).tagName === 'INPUT') {- setTimeout(() => {- const searchInput = document.querySelector('#scene-action-palette input') as HTMLInputElement- if (searchInput) {- searchInput.focus()- }- comboboxRef.current?.recalculateFocusableElements()- comboboxRef.current?.focusFirstItem()- }, 50) // Slightly longer delay for search updates- }- },- [handleClose, registeredShortcuts, handleItemClick]- )-- useEffect(() => {- if (shortcutMenuOpen) {- // Focus the search input when opened- setTimeout(() => {- const searchInput = document.querySelector('#scene-action-palette input') as HTMLInputElement- if (searchInput) {- searchInput.focus()- }- // Also ensure first item is focused in listbox- comboboxRef.current?.recalculateFocusableElements()- comboboxRef.current?.focusFirstItem()- }, 0)-- // Add escape key listener- const handleEscape = (event: KeyboardEvent): void => {- if (event.key === 'Escape') {- handleClose()- }- }-- window.addEventListener('keydown', handleEscape)- return () => {- window.removeEventListener('keydown', handleEscape)- }- }- }, [shortcutMenuOpen, handleClose])-- // Ensure search input is focused and first item is selected when shortcuts change- useEffect(() => {- if (shortcutMenuOpen && registeredShortcuts.length > 0) {- setTimeout(() => {- const searchInput = document.querySelector('#scene-action-palette input') as HTMLInputElement- if (searchInput) {- searchInput.focus()- }- comboboxRef.current?.recalculateFocusableElements()- comboboxRef.current?.focusFirstItem()- }, 0)- }- }, [shortcutMenuOpen, registeredShortcuts])-- if (!shortcutMenuOpen) {- return null- }-- const paletteContent = (- <div className="fixed inset-0 z-[var(--z-shortcut-menu)] flex items-end justify-center p-6 backdrop-blur-[var(--modal-backdrop-blur)]">- <div- className="bg-surface-secondary border-3 border-tertiary rounded-lg shadow-2xl w-96 max-h-[calc(100vh-(var(--spacing)*6))] overflow-x-hidden overflow-y-auto backdrop-blur-sm"- id="shortcut-menu"- onKeyDown={handleKeyDown}- >- <Combobox ref={comboboxRef}>- <Combobox.Content>- <Combobox.Empty>No matching actions</Combobox.Empty>- {groupedShortcuts.map((group, groupIndex) => (- <React.Fragment key={group.key}>- <Combobox.Group value={group.shortcuts.map((s) => s.intent)}>- <Label- intent="menu"- className={cn('px-1', {- 'pt-1': groupIndex > 0,- })}- >- {group.title}- </Label>- <DropdownMenuSeparator />- </Combobox.Group>- {group.shortcuts.map((shortcut, index) => {- const isFirstItem = groupIndex === 0 && index === 0- const isDisabled = disabledShortcutNames.includes(shortcut.name)- return (- <Combobox.Group key={shortcut.name} value={[shortcut.intent]}>- <Combobox.Item focusFirst={isFirstItem} asChild>- <ButtonPrimitive- menuItem- data-shortcut-name={shortcut.name}- onClick={(e) => {- e.preventDefault()- e.stopPropagation()- if (!isDisabled) {- handleItemClick(shortcut)- }- }}- truncate- >- <span- className={cn(- 'flex items-center gap-2 truncate max-w-full',- isDisabled && 'opacity-50 line-through'- )}- >- {getShortcutIcon(shortcut)}- {shortcut.intent}- </span>- <span className="ml-auto flex items-center gap-1.5">- <RenderKeybind- keybind={shortcut.keybind as string[][]}- className={cn(isDisabled && 'opacity-50')}- />- <div- onClick={(e) => {- e.stopPropagation()- }}- >- <LemonSwitch- size="xxsmall"- checked={!isDisabled}- onChange={() => toggleShortcutDisabled(shortcut.name)}- tooltip={- isDisabled ? 'Enable shortcut' : 'Disable shortcut'- }- />- </div>- </span>- </ButtonPrimitive>- </Combobox.Item>- </Combobox.Group>- )- })}- </React.Fragment>- ))}- </Combobox.Content>- <Combobox.Search- placeholder="Search actions... escape to close"- autoFocus- wrapperClassName="sticky bottom-0"- />- </Combobox>- </div>- <div className="absolute inset-0 -z-10" onClick={handleClose} aria-hidden="true" />- </div>- )-- return createPortal(paletteContent, document.body)-}diff --git a/frontend/src/lib/components/Shortcuts/shortcutLogic.test.ts b/frontend/src/lib/components/Shortcuts/shortcutLogic.test.tsnew file mode 100644index 000000000000..644888fb4b5a--- /dev/null+++ b/frontend/src/lib/components/Shortcuts/shortcutLogic.test.ts@@ -0,0 +1,47 @@+import { initKeaTests } from '~/test/init'++import { shortcutLogic } from './shortcutLogic'++describe('shortcutLogic', () => {+ beforeEach(() => {+ initKeaTests()+ shortcutLogic.mount()+ })++ afterEach(() => {+ shortcutLogic.unmount()+ })++ it('turns enabled shortcuts into executable search items', () => {+ const callback = jest.fn()+ shortcutLogic.actions.registerShortcut({+ name: 'staff-only-action',+ keybind: [['command', 'shift', 'p']],+ intent: 'Open staff action',+ interaction: 'function',+ callback,+ })+ shortcutLogic.actions.registerShortcut({+ name: 'disabled-action',+ keybind: [['command', 'shift', 'd']],+ intent: 'Disabled action',+ interaction: 'function',+ callback: jest.fn(),+ })+ shortcutLogic.actions.toggleShortcutDisabled('disabled-action')+ for (const name of ['Search', 'SQLEditor']) {+ shortcutLogic.actions.registerShortcut({+ name,+ keybind: [['command', 'k']],+ intent: name,+ interaction: 'function',+ callback: jest.fn(),+ })+ }++ expect(shortcutLogic.values.shortcutItems.map((item) => item.name)).toEqual(['Open staff action'])+ expect(shortcutLogic.values.shortcutItems[0].keybinding).toBeTruthy()+ shortcutLogic.values.shortcutItems[0].onSelect?.()+ expect(callback).toHaveBeenCalledTimes(1)+ })+})diff --git a/frontend/src/lib/components/Shortcuts/shortcutLogic.tsx b/frontend/src/lib/components/Shortcuts/shortcutLogic.tsxindex 01d93f3cfc60..4fac704ac6ca 100644--- a/frontend/src/lib/components/Shortcuts/shortcutLogic.tsx+++ b/frontend/src/lib/components/Shortcuts/shortcutLogic.tsx@@ -1,14 +1,22 @@-import { MakeLogicType, actions, afterMount, beforeUnmount, kea, path, reducers } from 'kea'+import { MakeLogicType, actions, afterMount, beforeUnmount, kea, path, reducers, selectors } from 'kea'+import { IconKeyboard } from '@posthog/icons'++import { SearchItem } from 'lib/components/Search/searchItems'import posthog from 'lib/posthog-typed'import { isMac } from 'lib/utils/dom'import { Scene } from 'scenes/sceneTypes'+import { RenderKeybind } from './RenderKeybind'+const IS_MAC = isMac()const COMMAND_OR_CTRL = IS_MAC ? 'command' : 'ctrl'const DISABLED_SHORTCUTS_KEY = 'posthog-disabled-shortcuts'+/** These open search or the SQL editor, so listing them in search only repeats what the palette is for. */+const HIDDEN_FROM_SEARCH = new Set(['Search', 'SQLEditor'])+function loadDisabledShortcuts(): string[] {try {const stored = localStorage.getItem(DISABLED_SHORTCUTS_KEY)@@ -105,7 +113,7 @@ function isEditableElement(event: KeyboardEvent): boolean {export interface shortcutLogicValues {disabledShortcutNames: string[]registeredShortcuts: ShortcutType[]- shortcutMenuOpen: boolean+ shortcutItems: SearchItem[]}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -113,9 +121,6 @@ export interface shortcutLogicActions {registerShortcut: (shortcut: ShortcutType) => {shortcut: ShortcutType}- setShortcutMenuOpen: (open: boolean) => {- open: boolean- }toggleShortcutDisabled: (name: string) => {name: string}@@ -124,14 +129,25 @@ export interface shortcutLogicActions {}}-export type shortcutLogicType = MakeLogicType<shortcutLogicValues, shortcutLogicActions>+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface shortcutLogicMeta {+ __keaTypeGenInternalSelectorTypes: {+ shortcutItems: (registeredShortcuts: ShortcutType[], disabledShortcutNames: string[]) => SearchItem[]+ }+}++export type shortcutLogicType = MakeLogicType<+ shortcutLogicValues,+ shortcutLogicActions,+ Record<string, any>,+ shortcutLogicMeta+>export const shortcutLogic = kea<shortcutLogicType>([path(['lib', 'components', 'Shortcuts', 'shortcutLogic']),actions({registerShortcut: (shortcut: ShortcutType) => ({ shortcut }),unregisterShortcut: (name: string) => ({ name }),- setShortcutMenuOpen: (open: boolean) => ({ open }),toggleShortcutDisabled: (name: string) => ({ name }),}),reducers({@@ -146,12 +162,6 @@ export const shortcutLogic = kea<shortcutLogicType>([unregisterShortcut: (state, { name }) => state.filter((shortcut) => shortcut.name !== name),},],- shortcutMenuOpen: [- false,- {- setShortcutMenuOpen: (_, { open }) => open,- },- ],disabledShortcutNames: [loadDisabledShortcuts() as string[],{@@ -163,6 +173,33 @@ export const shortcutLogic = kea<shortcutLogicType>([},],}),+ selectors({+ shortcutItems: [+ (s) => [s.registeredShortcuts, s.disabledShortcutNames],+ (shortcuts: ShortcutType[], disabledNames: string[]): SearchItem[] =>+ shortcuts+ .filter(+ (shortcut) => !disabledNames.includes(shortcut.name) && !HIDDEN_FROM_SEARCH.has(shortcut.name)+ )+ .map((shortcut) => ({+ id: `shortcut-${shortcut.name}`,+ name: shortcut.intent,+ category: 'shortcuts',+ icon: <IconKeyboard />,+ keybinding: <RenderKeybind keybind={shortcut.keybind} />,+ onSelect: () => {+ if (shortcut.interaction === 'click') {+ shortcut.ref.current?.click()+ } else if (shortcut.interaction === 'focus') {+ shortcut.ref.current?.focus()+ } else {+ shortcut.callback?.()+ }+ },+ record: { type: 'shortcut', ref: shortcut.name },+ })),+ ],+ }),afterMount(({ values, cache }) => {// Sequence shortcut statecache.sequenceKeys = [] as string[]diff --git a/frontend/src/lib/components/Shortcuts/shortcuts.ts b/frontend/src/lib/components/Shortcuts/shortcuts.tsindex 9ada671cf5eb..896373a9e43c 100644--- a/frontend/src/lib/components/Shortcuts/shortcuts.ts+++ b/frontend/src/lib/components/Shortcuts/shortcuts.ts@@ -12,8 +12,6 @@ export const keyBinds: Record<string, string[]> = {orgSwitcher: ['g', 'then', 'o'],quickStart: ['g', 'then', 's'],recentItems: [...baseModifier, 'y'],- toggleShortcutMenu: [...baseModifier, 'k'],- toggleShortcutMenuFallback: ['command', 'shift', 'k'],search: ['command', 'k'],new: [...baseModifier, 'n'],edit: ['e'],