: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(search): select chips and text together with cmd+a in command k (#114347)
Adam Leithde3a5d09050e
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex e9262eaaa79f..02149d8389d1 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -657,9 +657,9 @@ snapshots:components-chart-legend-series-menu--single-series--light:hash: v1.k794b7964.45544c43c187fd1d1fc7b204e7c33c7e422c5c56838cac44e5d63318c7f5e283.phbzfcS5A5m2LHaspjABfv-I6FPQ1-LnsCFRwyX81uQcomponents-command-k-search--chip-and-value-suggestions--dark:- hash: v1.k794b7964.bb2146400c33663fe6dcf1bd8ed3b728759ad68c72c676ac86f03d4abb209507.gdnIyse2UFs7BPGXjLG1EJXyF7jtrfDzCNo7LLzCwKM+ hash: v1.k794b7964.1db8f7cf1e15e47931535561c9fa8fe4e7635b5441715efb183776410482ebd4.TzkbRd1YbNiuS-4IyijmupTNwdCJLJo9BkkBqVgDBNIcomponents-command-k-search--chip-and-value-suggestions--light:- hash: v1.k794b7964.7c546a5379c0a5d025630508266a9f40c2e216a45bfa6d894d983ace0c4cae5b.MXIWq8T3Rb_keioh261ukhjJk0E279_P42OuZVDakfA+ hash: v1.k794b7964.1f156fcb62177c54eddaf141565a293f383d79ced9443ad570108215f5d68627.xvKPM445SeJQj5XOeZcMd3YTDywIpPVgQ5g4kZew9O8components-command-k-search--empty--dark:hash: v1.k794b7964.458b55fd345ec31873d513d00258ebe6f6f6e9b1e91c4504ad4f0c16046f5151.wfpwrARigE_uao91HNDgU7NeZN24s2vP9Q3H4W4mEX4components-command-k-search--empty--light:diff --git a/frontend/src/lib/components/CommandKSearch/COMMAND_K_SEARCH_UX.md b/frontend/src/lib/components/CommandKSearch/COMMAND_K_SEARCH_UX.mdindex 667af51b6852..a7464dccca6c 100644--- a/frontend/src/lib/components/CommandKSearch/COMMAND_K_SEARCH_UX.md+++ b/frontend/src/lib/components/CommandKSearch/COMMAND_K_SEARCH_UX.md@@ -14,10 +14,10 @@ When a change disagrees with this file, change this file in the same PR or don't## Building blocks-- Styled only with quill tokens (`bg-card`, `bg-background`, `text-muted-foreground`, `border-input`, `ring-ring`, `fill-selected`) under a `data-quill` root, never LemonUI tokens such as `bg-surface-primary` or `text-tertiary`.+- Styled only with quill tokens (`bg-card`, `bg-background`, `text-muted-foreground`, `border-input`, `ring-ring`, `fill-selected`) under a `data-quill` root, never LemonUI tokens such as `bg-surface-primary` or `text-tertiary`. One exception: chips selected with ⌘A use the `Highlight` system color, so they match the input's native text selection.- Built from quill primitives: `InputGroup` (with `InputGroupInput`, `InputGroupAddon`, `InputGroupButton`) for the field, `Button` rows, `MenuLabel` section headers, `Skeleton`, `Kbd`, `ScrollArea`. One combobox input, one listbox, grouped options, wired with `aria-activedescendant`.- Not on quill's `Autocomplete`: Base UI tracks the highlight by index and cannot hold it by item identity (stability rule 5), so the logic owns the highlight.-- Committed filters render inline as text, not as boxed chips: the key in the muted color at normal weight, the value in the brand color on a light tint (`is:` **Dashboard**). They still behave as chips (select, remove, edit). There is no × on a chip; ⌫ removes it.+- Committed filters render inline as text, not as boxed chips: the key in the foreground color at normal weight, the value in the brand color on a light tint (`is:` **Dashboard**). They still behave as chips (select, remove, edit). There is no × on a chip; ⌫ removes it.- The field has a fixed height. Committing a chip never resizes it; chips that overflow scroll sideways.- One kea logic (`commandKSearchLogic`) owns state, highlight, and orchestration. Components only render and translate events. The rules live in pure modules with unit tests:- `commandKQuery.ts`: tokenizing, cursor context, `resolveQuery` (filters, free text, and the backend search string in one pass), and which edits commit a chip.@@ -170,6 +170,7 @@ These are the rules reviewers check. Breaking one is a bug.| `↵` on a selected chip | Turns the chip back into editable text (`is:dashboard`) with the cursor after it. || `←` / `→` at text edges | Move between chips. || `Esc` | Text in the input: clear it. Empty input: close the palette. |+| `⌘A` | Selects the chips and the text together. `⌫`, typing, or cut then replaces all of it. Copy includes the chips as text. |## Edge casesdiff --git a/frontend/src/lib/components/CommandKSearch/CommandKSearchFooter.tsx b/frontend/src/lib/components/CommandKSearch/CommandKSearchFooter.tsxindex 8f4bd24f7c95..edfcf6aff9cf 100644--- a/frontend/src/lib/components/CommandKSearch/CommandKSearchFooter.tsx+++ b/frontend/src/lib/components/CommandKSearch/CommandKSearchFooter.tsx@@ -7,7 +7,7 @@ import { todayShellLogic } from '~/layout/today/todayShellLogic'import { commandKSearchLogic } from './commandKSearchLogic'export function CommandKSearchFooter(): JSX.Element {- const { highlightIsFilterRow, chips, mode, selectedChipIndex, tabAsksAi } = useValues(commandKSearchLogic)+ const { highlightIsFilterRow, chips, mode, chipSelection, tabAsksAi } = useValues(commandKSearchLogic)const { todayRailEnabled } = useValues(todayShellLogic)return (@@ -39,10 +39,11 @@ export function CommandKSearchFooter(): JSX.Element {)}{chips.length > 0 && (<span className="flex items-center gap-1">- <Kbd>⌫</Kbd> {selectedChipIndex === null ? 'select filter' : 'remove filter'}+ <Kbd>⌫</Kbd>{' '}+ {chipSelection === 'all' ? 'clear all' : chipSelection === null ? 'select filter' : 'remove filter'}</span>)}- {selectedChipIndex !== null && (+ {typeof chipSelection === 'number' && (<span className="flex items-center gap-1"><Kbd>↵</Kbd> edit filter</span>diff --git a/frontend/src/lib/components/CommandKSearch/CommandKSearchInput.tsx b/frontend/src/lib/components/CommandKSearch/CommandKSearchInput.tsxindex f9a4b3120674..785b8b7b875f 100644--- a/frontend/src/lib/components/CommandKSearch/CommandKSearchInput.tsx+++ b/frontend/src/lib/components/CommandKSearch/CommandKSearchInput.tsx@@ -7,13 +7,14 @@ import { Button, InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput,import { todayShellLogic } from '~/layout/today/todayShellLogic'import { keyIntent } from './commandKKeys'+import { queryAsText } from './commandKQuery'import { commandKSearchLogic } from './commandKSearchLogic'import { rowDomId } from './CommandKSearchRow'export const COMMAND_K_LISTBOX_ID = 'command-k-listbox'export function CommandKSearchInput(): JSX.Element {- const { text, cursor, chips, selectedChipIndex, highlightedRow, highlightIsFilterRow, tabAsksAi, isPaletteEmpty } =+ const { text, cursor, chips, chipSelection, highlightedRow, highlightIsFilterRow, tabAsksAi, isPaletteEmpty } =useValues(commandKSearchLogic)const { todayRailEnabled } = useValues(todayShellLogic)const { inputChanged, setCursor, applyKeyIntent, selectChip, clearQuery, askAi, closeCommand } =@@ -42,13 +43,15 @@ export function CommandKSearchInput(): JSX.Element {const intent = keyIntent(event.key, event, {atStart: input.selectionStart === 0 && input.selectionEnd === 0,chipCount: chips.length,- selectedChipIndex,+ chipSelection,tabHasAction: tabAsksAi || highlightIsFilterRow,})if (!intent) {return}- event.preventDefault()+ if (!('keepDefault' in intent)) {+ event.preventDefault()+ }if (intent.type === 'clear-or-close') {// Stop the dialog from closing, so the first press only clears the query.event.stopPropagation()@@ -56,18 +59,25 @@ export function CommandKSearchInput(): JSX.Element {applyKeyIntent(intent)}+ // With everything selected, the clipboard gets the chips as text, so pasting it back rebuilds them.+ const copyWholeQuery = (event: React.ClipboardEvent<HTMLInputElement>): void => {+ event.preventDefault()+ event.clipboardData.setData('text/plain', queryAsText(text, chips))+ }+return (<div className="flex items-center gap-1 p-2">{/* A fixed height, so committing a chip never resizes the field. Chips that overflow scroll sideways. */}<InputGroup className="flex-1">- {/* The scroll container clips, so it gets room on the right for the selected chip's outline and gives it back with a negative margin. */}+ {/* The scroll container clips, so it gets room on the right for the selected chip's outline and gives it back with a negative margin.+ ms-0 cancels quill's pull-in for button addons, and gap-1.5 matches the input's start padding, so committing a chip doesn't shift the text. */}<InputGroupAddonalign="inline-start"- className="-mr-1 min-w-0 shrink overflow-x-auto pr-1 [scrollbar-width:none]"+ className="-mr-1 ms-0 min-w-0 shrink gap-1.5 overflow-x-auto pr-1 [scrollbar-width:none]"><IconSearch className="size-4 shrink-0" />{chips.map((chip, index) => (- // Committed filters read as typed text: muted key, brand-tinted value.+ // Committed filters read as typed text: plain key, brand-tinted value.<buttonkey={chip.key}type="button"@@ -75,13 +85,15 @@ export function CommandKSearchInput(): JSX.Element {data-attr="command-k-chip"aria-label={`${chip.negated ? 'Not ' : ''}${chip.key}: ${chip.label}. Backspace removes it.`}className={cn(- 'flex max-w-60 shrink-0 items-center rounded-xs text-sm leading-none text-foreground',- selectedChipIndex === index && 'ring-2 ring-ring'+ 'flex max-w-60 shrink-0 items-center rounded-xs leading-none text-foreground',+ chipSelection === index && 'ring-2 ring-ring',+ // The system color the input paints its own selected text with.+ chipSelection === 'all' && 'bg-[Highlight]')}onMouseDown={(event: React.MouseEvent<HTMLButtonElement>) => event.preventDefault()}onClick={() => selectChip(index)}>- <span className="shrink-0 font-normal text-muted-foreground">+ <span className="shrink-0 font-normal">{chip.negated ? '-' : ''}{chip.key}:</span>@@ -118,7 +130,26 @@ export function CommandKSearchInput(): JSX.Element {pasted)}}+ onCopy={(event: React.ClipboardEvent<HTMLInputElement>) => {+ if (chipSelection === 'all') {+ copyWholeQuery(event)+ }+ }}+ onCut={(event: React.ClipboardEvent<HTMLInputElement>) => {+ if (chipSelection === 'all') {+ copyWholeQuery(event)+ clearQuery()+ }+ }}+ // An empty input fires no select event on click, so this is the only place that click deselects.+ onMouseDown={() => chipSelection === 'all' && selectChip(null)}onSelect={(event: React.SyntheticEvent<HTMLInputElement>) => {+ const input = event.currentTarget+ const wholeTextSelected =+ input.selectionStart === 0 && input.selectionEnd === input.value.length+ if (chipSelection === 'all' && !wholeTextSelected) {+ selectChip(null)+ }const nextCursor = event.currentTarget.selectionStart ?? 0if (nextCursor !== cursor) {setCursor(nextCursor)diff --git a/frontend/src/lib/components/CommandKSearch/commandKKeys.test.ts b/frontend/src/lib/components/CommandKSearch/commandKKeys.test.tsindex b3c155be0580..c892dc5a9130 100644--- a/frontend/src/lib/components/CommandKSearch/commandKKeys.test.ts+++ b/frontend/src/lib/components/CommandKSearch/commandKKeys.test.ts@@ -4,7 +4,7 @@ const NO_MODIFIERS = { metaKey: false, ctrlKey: false }const state = (overrides: Partial<KeyState> = {}): KeyState => ({atStart: false,chipCount: 0,- selectedChipIndex: null,+ chipSelection: null,tabHasAction: false,...overrides,})@@ -16,7 +16,7 @@ describe('keyIntent', () => {['Enter on a selected chip edits it','Enter',- state({ chipCount: 2, selectedChipIndex: 0 }),+ state({ chipCount: 2, chipSelection: 0 }),{ type: 'edit-chip', index: 0 },],[@@ -28,24 +28,50 @@ describe('keyIntent', () => {['second Backspace removes it','Backspace',- state({ atStart: true, chipCount: 2, selectedChipIndex: 1 }),+ state({ atStart: true, chipCount: 2, chipSelection: 1 }),{ type: 'remove-chip', index: 1 },],['Backspace inside the text is left to the input', 'Backspace', state({ chipCount: 2 }), null],['ArrowLeft at the start walks back through chips','ArrowLeft',- state({ atStart: true, chipCount: 2, selectedChipIndex: 1 }),+ state({ atStart: true, chipCount: 2, chipSelection: 1 }),{ type: 'select-chip', index: 0 },],['ArrowRight past the last chip returns to the text','ArrowRight',- state({ chipCount: 2, selectedChipIndex: 1 }),+ state({ chipCount: 2, chipSelection: 1 }),{ type: 'select-chip', index: null },],['ArrowRight with no chip selected is left to the input', 'ArrowRight', state({ chipCount: 2 }), null],['typing is left to the input', 'a', state(), null],+ [+ 'Cmd+A with chips selects them with the text',+ 'a',+ state({ chipCount: 2 }),+ { type: 'select-chip', index: 'all', keepDefault: true },+ true,+ ],+ ['Cmd+A without chips is left to the input', 'a', state(), null, true],+ [+ 'Backspace after select-all clears chips and text',+ 'Backspace',+ state({ atStart: true, chipCount: 2, chipSelection: 'all' }),+ { type: 'clear' },+ ],+ [+ 'ArrowLeft after select-all collapses the selection',+ 'ArrowLeft',+ state({ chipCount: 2, chipSelection: 'all' }),+ { type: 'select-chip', index: null, keepDefault: true },+ ],+ [+ 'ArrowDown after select-all still moves the highlight',+ 'ArrowDown',+ state({ chipSelection: 'all' }),+ { type: 'move', direction: 1 },+ ],['Tab completes or asks AI when it has an action', 'Tab', state({ tabHasAction: true }), { type: 'complete' }],['Tab with nothing to do moves focus', 'Tab', state(), null],])('%s', (_, key, keyState, expected, metaKey = false) => {diff --git a/frontend/src/lib/components/CommandKSearch/commandKKeys.ts b/frontend/src/lib/components/CommandKSearch/commandKKeys.tsindex 500a76c54f19..ddd7026cf86b 100644--- a/frontend/src/lib/components/CommandKSearch/commandKKeys.ts+++ b/frontend/src/lib/components/CommandKSearch/commandKKeys.ts@@ -1,17 +1,22 @@+/** A chip index, every chip plus the text (⌘A), or nothing. */+export type ChipSelection = number | 'all' | null+export type KeyIntent =| { type: 'move'; direction: 1 | -1 }| { type: 'activate'; newTab: boolean }| { type: 'complete' }- | { type: 'select-chip'; index: number | null }+ /** `keepDefault` lets the input also select or collapse its own text. */+ | { type: 'select-chip'; index: ChipSelection; keepDefault?: true }| { type: 'remove-chip'; index: number }| { type: 'edit-chip'; index: number }+ | { type: 'clear' }| { type: 'clear-or-close' }export interface KeyState {/** The caret sits at the very start of the text with nothing selected. */atStart: booleanchipCount: number- selectedChipIndex: number | null+ chipSelection: ChipSelection/** Tab completes a filter row or asks AI. With neither, it moves focus as usual. */tabHasAction: boolean}@@ -22,41 +27,63 @@ export function keyIntent(modifiers: { metaKey: boolean; ctrlKey: boolean },state: KeyState): KeyIntent | null {- const { atStart, chipCount, selectedChipIndex } = state+ const { atStart, chipCount, chipSelection } = stateconst chipsBeforeCaret = chipCount > 0 && atStart+ const chipIndex = typeof chipSelection === 'number' ? chipSelection : nullswitch (key) {+ case 'a':+ case 'A':+ if (!modifiers.metaKey && !modifiers.ctrlKey) {+ return null+ }+ // With no chips the input's own select-all already covers the whole query.+ return chipCount > 0 ? { type: 'select-chip', index: 'all', keepDefault: true } : nullcase 'ArrowDown':return { type: 'move', direction: 1 }case 'ArrowUp':return { type: 'move', direction: -1 }case 'Enter':- return selectedChipIndex !== null- ? { type: 'edit-chip', index: selectedChipIndex }+ return chipIndex !== null+ ? { type: 'edit-chip', index: chipIndex }: { type: 'activate', newTab: modifiers.metaKey || modifiers.ctrlKey }case 'Tab':return state.tabHasAction ? { type: 'complete' } : nullcase 'Escape':return { type: 'clear-or-close' }+ case 'Delete':+ return chipSelection === 'all' ? { type: 'clear' } : nullcase 'Backspace':+ if (chipSelection === 'all') {+ return { type: 'clear' }+ }if (!chipsBeforeCaret) {return null}- return selectedChipIndex === null+ return chipIndex === null? { type: 'select-chip', index: chipCount - 1 }- : { type: 'remove-chip', index: selectedChipIndex }+ : { type: 'remove-chip', index: chipIndex }+ case 'Home':+ case 'End':+ return chipSelection === 'all' ? { type: 'select-chip', index: null, keepDefault: true } : nullcase 'ArrowLeft':+ if (chipSelection === 'all') {+ return { type: 'select-chip', index: null, keepDefault: true }+ }if (!chipsBeforeCaret) {return null}return {type: 'select-chip',- index: selectedChipIndex === null ? chipCount - 1 : Math.max(0, selectedChipIndex - 1),+ index: chipIndex === null ? chipCount - 1 : Math.max(0, chipIndex - 1),}case 'ArrowRight':- if (selectedChipIndex === null) {+ if (chipSelection === 'all') {+ return { type: 'select-chip', index: null, keepDefault: true }+ }+ if (chipIndex === null) {return null}- return { type: 'select-chip', index: selectedChipIndex + 1 < chipCount ? selectedChipIndex + 1 : null }+ return { type: 'select-chip', index: chipIndex + 1 < chipCount ? chipIndex + 1 : null }default:return null}diff --git a/frontend/src/lib/components/CommandKSearch/commandKSearchLogic.tsx b/frontend/src/lib/components/CommandKSearch/commandKSearchLogic.tsxindex 4c6d73e36b74..ad815582cfb7 100644--- a/frontend/src/lib/components/CommandKSearch/commandKSearchLogic.tsx+++ b/frontend/src/lib/components/CommandKSearch/commandKSearchLogic.tsx@@ -36,7 +36,7 @@ import type { GroupType, GroupTypeIndex, OrganizationMemberType, UserType } fromimport type { FeatureFlagsSet } from '../../logic/featureFlagLogic'import type { CommandOpenSource } from '../Command/commandLogic'import { buildFilterOptions } from './commandKFilterOptions'-import { KeyIntent } from './commandKKeys'+import { ChipSelection, KeyIntent } from './commandKKeys'import {CursorContext,FilterDefinition,@@ -96,6 +96,7 @@ export interface commandKSearchLogicValues {isDarkModeOn: boolean // themeLogicuser: UserType | null // userLogicaskAiQuestion: string+ chipSelection: ChipSelectionchips: QueryChip[]cursor: numbercursorContext: CursorContext@@ -118,7 +119,6 @@ export interface commandKSearchLogicValues {resultOpened: booleansections: CommandKSection[]selectableRows: CommandKRow[]- selectedChipIndex: number | nullsuggestionsSection: CommandKSection | nulltabAsksAi: booleantext: string@@ -223,8 +223,8 @@ export interface commandKSearchLogicActions {query: stringrequestId: string}- selectChip: (index: number | null) => {- index: number | null+ selectChip: (index: ChipSelection) => {+ index: ChipSelection}setChipsAndText: (chips: QueryChip[],@@ -382,7 +382,7 @@ export const commandKSearchLogic = kea<commandKSearchLogicType>([setChipsAndText: (chips: QueryChip[], text: string, cursor: number) => ({ chips, text, cursor }),commitChip: (chip: QueryChip, token: QueryToken | null, via: CommitVia) => ({ chip, token, via }),removeChip: (index: number) => ({ index }),- selectChip: (index: number | null) => ({ index }),+ selectChip: (index: ChipSelection) => ({ index }),editChip: (index: number) => ({ index }),completeFilterKey: (filter: FilterDefinition, negated: boolean) => ({ filter, negated }),applyKeyIntent: (intent: KeyIntent) => ({ intent }),@@ -422,8 +422,8 @@ export const commandKSearchLogic = kea<commandKSearchLogicType>([removeChip: (state, { index }) => state.filter((_, i) => i !== index),},],- selectedChipIndex: [- null as number | null,+ chipSelection: [+ null as ChipSelection,{selectChip: (_, { index }) => index,setInput: () => null,@@ -684,9 +684,15 @@ export const commandKSearchLogic = kea<commandKSearchLogicType>([})}- const commit = (chip: QueryChip, token: QueryToken | null, text: string, via: CommitVia): void => {+ const commit = (+ chips: QueryChip[],+ chip: QueryChip,+ token: QueryToken | null,+ text: string,+ via: CommitVia+ ): void => {const remaining = token ? removeToken(text, token) : { text, cursor: values.cursor }- actions.setChipsAndText(addChip(values.chips, chip), remaining.text, remaining.cursor)+ actions.setChipsAndText(addChip(chips, chip), remaining.text, remaining.cursor)trackCommit(chip, via)}@@ -745,30 +751,38 @@ export const commandKSearchLogic = kea<commandKSearchLogicType>([// Remote searches wait for a project, so a project that loads mid-query starts them.loadCurrentTeamSuccess: () => actions.syncRemote(),inputChanged: ({ text, cursor, pasted }) => {+ // With everything selected, the edit replaced the chips along with the text.+ const replacedAll = values.chipSelection === 'all'+ const chips = replacedAll ? [] : values.chipsif (pasted) {- const extracted = extractChips(text, values.chips, values.filterOptions)- for (const chip of extracted.chips.filter((chip) => !values.chips.includes(chip))) {+ const extracted = extractChips(text, chips, values.filterOptions)+ for (const chip of extracted.chips.filter((chip) => !chips.includes(chip))) {trackCommit(chip, 'paste')}actions.setChipsAndText(extracted.chips, extracted.text, extracted.text.length)return}- const edit = { previousText: values.text, previousCursor: values.cursor, text, cursor }+ const edit = {+ previousText: replacedAll ? '' : values.text,+ previousCursor: replacedAll ? 0 : values.cursor,+ text,+ cursor,+ }if (isRedundantSpace(edit)) {return}- const committed = chipCommittedByEdit(edit, values.chips, values.filterOptions)+ const committed = chipCommittedByEdit(edit, chips, values.filterOptions)if (committed) {- commit(committed.chip, committed.token, text, committed.via)+ commit(chips, committed.chip, committed.token, text, committed.via)} else {- actions.setInput(text, cursor)+ actions.setChipsAndText(chips, text, cursor)}},setInput: onQueryChanged,setCursor: onQueryChanged,setChipsAndText: onQueryChanged,removeChip: onQueryChanged,- commitChip: ({ chip, token, via }) => commit(chip, token, values.text, via),+ commitChip: ({ chip, token, via }) => commit(values.chips, chip, token, values.text, via),completeFilterKey: ({ filter, negated }) => {const token = tokenAtCursor(values.text, values.cursor)const replacement = `${negated ? '-' : ''}${filter.key}:`@@ -805,6 +819,9 @@ export const commandKSearchLogic = kea<commandKSearchLogicType>([case 'select-chip':actions.selectChip(intent.index)break+ case 'clear':+ actions.clearQuery()+ breakcase 'remove-chip':actions.removeChip(intent.index)break