Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

feat(ui): add palette search-scope commands with instant scoped results

joshistoaste19197bf5e6c
diff --git a/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.browser.test.tsx
index 19cc31f7c6..8c3d24445a 100644
--- a/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.browser.test.tsx
@@ -260,6 +260,160 @@ describe('CommandPaletteDialog interaction', () => {
});
});
+ it('shows one search-scope command per provider in the empty launcher and bare > mode', async () => {
+ const providers: PaletteSearchProvider[] = [
+ { contextKey: 'context', label: 'Entities', providerKey: 'entities', search: vi.fn(() => []) },
+ { contextKey: 'context', label: 'Widgets', providerKey: 'widgets', search: vi.fn(() => []) },
+ ];
+ const { input } = await renderPalette({ entries: [entry('first', 'First command')], providers });
+
+ expect(document.body.textContent).toContain('Search in');
+ expect(document.body.textContent).toContain('Search entities…');
+ expect(document.body.textContent).toContain('Search widgets…');
+
+ await act(() => userEvent.fill(input, '>'));
+ expect(document.body.textContent).toContain('Search entities…');
+ expect(document.body.textContent).toContain('Search widgets…');
+ });
+
+ it('shows no search-scope section without providers (Launchpad shape)', async () => {
+ const { input } = await renderPalette({ entries: [entry('first', 'First command')] });
+
+ expect(document.body.textContent).not.toContain('Search in');
+
+ await act(() => userEvent.fill(input, '>'));
+ expect(document.body.textContent).not.toContain('Search in');
+ });
+
+ it('runs a search-scope command: clears the query, keeps the palette open, and lists results immediately', async () => {
+ const providerSearch = vi.fn(() => [
+ { group: 'Entities', id: 'entity-one', isPersistentRecent: false, run: vi.fn(), title: 'Entity One' },
+ ]);
+ const provider: PaletteSearchProvider = {
+ contextKey: 'context',
+ label: 'Entities',
+ providerKey: 'entities',
+ search: providerSearch,
+ supportsCreatedAtRange: true,
+ };
+ const { input, onClose } = await renderPalette({ entries: [], providers: [provider] });
+
+ await act(() => userEvent.fill(input, 'search ent'));
+ await act(() => userEvent.keyboard('{Enter}'));
+
+ expect(input.value).toBe('');
+ expect(onClose).not.toHaveBeenCalled();
+ await vi.waitFor(() => {
+ expect(providerSearch).toHaveBeenCalledWith({ range: undefined, text: '' });
+ });
+ expect(document.body.textContent).toContain('Entity One');
+
+ // The same command works from > commands mode and exits it into the scope.
+ await act(() => userEvent.keyboard('{Backspace}'));
+ await act(() => userEvent.fill(input, '>search ent'));
+ await act(() => userEvent.keyboard('{Enter}'));
+ expect(input.value).toBe('');
+ await vi.waitFor(() => expect(document.body.textContent).toContain('Entity One'));
+ });
+
+ it('keeps the query when entering a scope through a Tab scope row', async () => {
+ const providerSearch = vi.fn(() => []);
+ const provider: PaletteSearchProvider = {
+ contextKey: 'context',
+ label: 'Entities',
+ providerKey: 'entities',
+ search: providerSearch,
+ };
+ const { input } = await renderPalette({ entries: [], providers: [provider] });
+
+ await act(() => userEvent.fill(input, 'zz'));
+ // The trailing scope row is the last navigable row; ArrowUp wraps to it.
+ await act(() => userEvent.keyboard('{ArrowUp}'));
+ await act(() => userEvent.keyboard('{Tab}'));
+
+ expect(input.value).toBe('zz');
+ await vi.waitFor(() => {
+ expect(providerSearch).toHaveBeenCalledWith({ range: undefined, text: 'zz' });
+ });
+ });
+
+ it('searches at any length inside a scope but keeps the root minimum length', async () => {
+ const providerSearch = vi.fn(() => []);
+ const provider: PaletteSearchProvider = {
+ contextKey: 'context',
+ label: 'Entities',
+ providerKey: 'entities',
+ search: providerSearch,
+ };
+ const { input } = await renderPalette({ entries: [], providers: [provider] });
+
+ await act(() => userEvent.fill(input, 'e'));
+ await new Promise((resolve) => {
+ globalThis.setTimeout(resolve, 250);
+ });
+ expect(providerSearch).not.toHaveBeenCalled();
+
+ await act(() => userEvent.fill(input, ''));
+ await act(() => userEvent.keyboard('{Enter}'));
+ await vi.waitFor(() => {
+ expect(providerSearch).toHaveBeenCalledWith({ range: undefined, text: '' });
+ });
+
+ await act(() => userEvent.fill(input, 'a'));
+ await vi.waitFor(() => {
+ expect(providerSearch).toHaveBeenCalledWith({ range: undefined, text: 'a' });
+ });
+ });
+
+ it('says what an empty scope is missing and falls back to no-results for a miss', async () => {
+ const provider: PaletteSearchProvider = {
+ contextKey: 'context',
+ label: 'Entities',
+ providerKey: 'entities',
+ search: vi.fn(() => []),
+ };
+ const { input } = await renderPalette({ entries: [], providers: [provider] });
+
+ await act(() => userEvent.keyboard('{Enter}'));
+ await vi.waitFor(() => expect(document.body.textContent).toContain('No entities yet'));
+
+ await act(() => userEvent.fill(input, 'x'));
+ await vi.waitFor(() => expect(document.body.textContent).toContain('No results for “x”'));
+ });
+
+ it('keeps the error state and Retry for an empty scope', async () => {
+ const provider: PaletteSearchProvider = {
+ contextKey: 'context',
+ label: 'Entities',
+ providerKey: 'entities',
+ search: vi.fn(() => Promise.reject(new Error('offline'))),
+ };
+ await renderPalette({ entries: [], providers: [provider] });
+
+ await act(() => userEvent.keyboard('{Enter}'));
+ await vi.waitFor(() => expect(document.body.textContent).toContain("Couldn't search entities"));
+ expect([...document.querySelectorAll('button')].some((button) => button.textContent === 'Retry')).toBe(true);
+ });
+
+ it('records a used search-scope command as a persistent recent', async () => {
+ const provider: PaletteSearchProvider = {
+ contextKey: 'context',
+ label: 'Entities',
+ providerKey: 'entities',
+ search: vi.fn(() => []),
+ };
+ await renderPalette({ entries: [], providers: [provider] });
+
+ await act(() => userEvent.keyboard('{Enter}'));
+ await act(() => root?.unmount());
+ host?.remove();
+
+ await renderPalette({ entries: [], providers: [provider] });
+ expect(document.body.textContent).toContain('Recent');
+ // Deliberately listed twice: once under Recent, once under Search in.
+ expect(document.body.textContent?.match(/Search entities…/g)).toHaveLength(2);
+ });
+
it('drives stage preview from navigation and restores it on Escape and unmount', async () => {
const preview = vi.fn();
const clearPreview = vi.fn();
diff --git a/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.tsx b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.tsx
index 8043091241..bdc7e09042 100644
--- a/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.tsx
+++ b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.tsx
@@ -12,7 +12,6 @@ import type { CommandPaletteRowsHandle } from './CommandPaletteRows';
import type { PaletteEntry, PaletteSearchProvider, PaletteStage } from './entries';
import { CommandPaletteRows, getCommandPaletteRowDomId } from './CommandPaletteRows';
-import { PROVIDER_MIN_QUERY_LENGTH } from './entries';
import { useCommandPaletteController } from './useCommandPaletteController';
const INPUT_PLACEHOLDER_STYLE = { color: 'fg.subtle' };
@@ -109,18 +108,18 @@ const CommandPaletteContent = ({
let emptyState: ReactNode = null;
if (controller.rows.length === 0) {
- if (controller.scopeIsError && controller.scopeErrorLabel) {
+ if (controller.scopeIsError && controller.scopeLabel) {
emptyState = (
- <EmptyState danger py="6" title={`Couldn't search ${controller.scopeErrorLabel}`}>
+ <EmptyState danger py="6" title={`Couldn't search ${controller.scopeLabel}`}>
<Button size="xs" variant="subtle" onClick={controller.onRetry}>
Retry
</Button>
</EmptyState>
);
- } else if (controller.scopeErrorLabel && controller.trimmedQuery.length < PROVIDER_MIN_QUERY_LENGTH) {
- emptyState = <EmptyState py="6" title={`Keep typing to search ${controller.scopeErrorLabel}`} />;
- } else if (controller.scopeErrorLabel && controller.scopeIsFetching) {
+ } else if (controller.scopeLabel && controller.scopeIsFetching) {
emptyState = <EmptyState py="6" title="Searching…" />;
+ } else if (controller.scopeLabel && controller.trimmedQuery.length === 0) {
+ emptyState = <EmptyState py="6" title={`No ${controller.scopeLabel} yet`} />;
} else {
emptyState = <EmptyState py="6" title={`No results for “${controller.trimmedQuery}”`} />;
}
diff --git a/invokeai/frontend/webv2/src/workbench/palette/contributionKey.ts b/invokeai/frontend/webv2/src/workbench/palette/contributionKey.ts
index a42da7ed84..bc448e7292 100644
--- a/invokeai/frontend/webv2/src/workbench/palette/contributionKey.ts
+++ b/invokeai/frontend/webv2/src/workbench/palette/contributionKey.ts
@@ -8,7 +8,7 @@ import type { WidgetContributionSource } from '@workbench/widgetContracts';
* pulling extension registry internals into either route's initial graph.
*/
export const getPaletteContributionKey = (
- kind: 'command' | 'provider' | 'provider-result' | 'provider-row' | 'scope',
+ kind: 'command' | 'provider' | 'provider-result' | 'provider-row' | 'scope' | 'scope-command',
id: string,
source?: WidgetContributionSource | null
): string =>
diff --git a/invokeai/frontend/webv2/src/workbench/palette/entries.test.ts b/invokeai/frontend/webv2/src/workbench/palette/entries.test.ts
index 52f7eaec55..55986ef905 100644
--- a/invokeai/frontend/webv2/src/workbench/palette/entries.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/palette/entries.test.ts
@@ -12,6 +12,7 @@ import {
buildScopeRows,
buildSettingsEntries,
buildStageEntries,
+ SEARCH_SCOPE_GROUP,
searchPaletteRows,
resolveActivePaletteRow,
} from './entries';
@@ -297,6 +298,34 @@ describe('searchPaletteRows', () => {
'app.selectCanvasTab',
]);
});
+
+ it('renders the search-scope section last in the empty launcher', () => {
+ const rows = searchPaletteRows(
+ [
+ ...entries,
+ makeEntry({ group: SEARCH_SCOPE_GROUP, id: 'scope.images', showInEmptyState: true, title: 'Search images…' }),
+ ],
+ '',
+ []
+ );
+
+ expect(rows.filter((row) => row.kind === 'label').map((row) => row.id)).toEqual([
+ 'label:Navigation',
+ `label:${SEARCH_SCOPE_GROUP}`,
+ ]);
+ expect(rows.at(-1)?.id).toBe('scope.images');
+ });
+
+ it('includes search-scope commands in commands-only mode', () => {
+ const rows = searchPaletteRows(
+ [...entries, makeEntry({ group: SEARCH_SCOPE_GROUP, id: 'scope.images', title: 'Search images…' })],
+ '',
+ [],
+ { commandsOnly: true, showAllOnEmpty: true }
+ );
+
+ expect(rows.filter((row) => row.kind === 'entry').map((row) => row.entry.id)).toContain('scope.images');
+ });
});
describe('stable active row identity', () => {
diff --git a/invokeai/frontend/webv2/src/workbench/palette/entries.ts b/invokeai/frontend/webv2/src/workbench/palette/entries.ts
index 696a03df7b..5fed23240d 100644
--- a/invokeai/frontend/webv2/src/workbench/palette/entries.ts
+++ b/invokeai/frontend/webv2/src/workbench/palette/entries.ts
@@ -105,6 +105,8 @@ export const resolveActivePaletteRow = (
export const PROVIDER_ROOT_RESULT_CAP = 3;
/** Entity providers only fire at this query length. */
export const PROVIDER_MIN_QUERY_LENGTH = 2;
+/** Group for the synthesized "Search images…"-style scope commands. */
+export const SEARCH_SCOPE_GROUP = 'Search in';
const PALETTE_GROUP_ORDER = [
'Recent',
@@ -119,6 +121,7 @@ const PALETTE_GROUP_ORDER = [
'Workflows',
'Commands',
'Settings',
+ SEARCH_SCOPE_GROUP,
];
const RECENT_GROUP = 'Recent';
diff --git a/invokeai/frontend/webv2/src/workbench/palette/useCommandPaletteController.ts b/invokeai/frontend/webv2/src/workbench/palette/useCommandPaletteController.ts
index 4765b58132..18e388db84 100644
--- a/invokeai/frontend/webv2/src/workbench/palette/useCommandPaletteController.ts
+++ b/invokeai/frontend/webv2/src/workbench/palette/useCommandPaletteController.ts
@@ -15,12 +15,14 @@ import { useCallback, useMemo, useRef, useState } from 'react';
import type { PaletteEntry, PaletteRow, PaletteSearchProvider, PaletteStage, ProviderResultSection } from './entries';
+import { getPaletteContributionKey } from './contributionKey';
import {
buildProviderSectionRows,
buildScopeRows,
buildStageEntries,
PROVIDER_MIN_QUERY_LENGTH,
resolveActivePaletteRow,
+ SEARCH_SCOPE_GROUP,
searchPaletteRows,
STAGE_ENTRY_ID_PREFIX,
} from './entries';
@@ -76,9 +78,9 @@ export interface CommandPaletteController {
placeholder: string;
query: string;
rows: PaletteRow[];
- scopeErrorLabel: string | null;
scopeIsError: boolean;
scopeIsFetching: boolean;
+ scopeLabel: string | null;
secondaryHint: string | undefined;
setInputElement: (node: HTMLInputElement | null) => void;
stage: PaletteStage | null;
@@ -150,9 +152,13 @@ export const useCommandPaletteController = ({
[debouncedParse, debouncedQuery]
);
// A valid date range is a complete query on its own — it bypasses the
- // minimum text length so `from:7d` alone searches.
+ // minimum text length so `from:7d` alone searches. An active scope is a
+ // committed search context: it searches at any length, including empty
+ // (initial recent results) and one character.
const shouldSearchProviders =
- (providerQuery.text.length >= PROVIDER_MIN_QUERY_LENGTH || providerQuery.range !== undefined) &&
+ (scopeProvider !== null ||
+ providerQuery.text.length >= PROVIDER_MIN_QUERY_LENGTH ||
+ providerQuery.range !== undefined) &&
!stage &&
!isCommandsScope;
// Pure date query (range, no text): only range-capable providers run —
@@ -299,6 +305,41 @@ export const useCommandPaletteController = ({
return rows;
}, [datesEnabled, query, replaceQuery]);
+ const enterScope = useCallback(
+ (providerKey: string, { resetQuery = false }: { resetQuery?: boolean } = {}) => {
+ clearDebounce();
+ setScopeProviderKey(providerKey);
+ if (resetQuery) {
+ setQuery('');
+ }
+ setDebouncedQuery(resetQuery ? '' : trimmedQuery);
+ setActiveRowId(null);
+ focusInput();
+ },
+ [clearDebounce, focusInput, trimmedQuery]
+ );
+
+ // One "Search images…"-style command per provider, merged into the local
+ // entries so the empty-state launcher, `>` commands mode, fuzzy matching,
+ // and recents all treat them like any other command. Running one enters the
+ // scope with a fresh query — the text that found the command is not a
+ // search term for its results.
+ const scopeCommandEntries = useMemo<PaletteEntry[]>(
+ () =>
+ providers.map((provider) => ({
+ group: SEARCH_SCOPE_GROUP,
+ id: getPaletteContributionKey('scope-command', provider.providerKey),
+ isPersistentRecent: true,
+ keepOpen: true,
+ keywords: `search find browse ${provider.label.toLowerCase()}`,
+ run: () => enterScope(provider.providerKey, { resetQuery: true }),
+ showInEmptyState: true,
+ title: `Search ${provider.label.toLowerCase()}…`,
+ })),
+ [enterScope, providers]
+ );
+ const allEntries = useMemo(() => [...entries, ...scopeCommandEntries], [entries, scopeCommandEntries]);
+
const rows = useMemo<PaletteRow[]>(() => {
if (stage) {
return searchPaletteRows(buildStageEntries(stage, onStageApplied), query, [], { showAllOnEmpty: true });
@@ -315,7 +356,7 @@ export const useCommandPaletteController = ({
// are provider results (and their scopes) only.
const localRows = isLivePureDate
? []
- : searchPaletteRows(entries, matchText, recentIds, {
+ : searchPaletteRows(allEntries, matchText, recentIds, {
commandsOnly: isCommandsScope,
showAllOnEmpty: isCommandsScope && trimmedQuery.length === 0,
});
@@ -335,9 +376,9 @@ export const useCommandPaletteController = ({
...buildScopeRows(scopeProviders, isLivePureDate ? '' : matchText.trim()),
];
}, [
+ allEntries,
dateParse,
dateSuggestionRows,
- entries,
isCommandsScope,
localQuery,
onStageApplied,
@@ -357,17 +398,6 @@ export const useCommandPaletteController = ({
const effectiveActiveRowId = effectiveActive?.row.id ?? null;
const activeRow = effectiveActive?.row;
- const enterScope = useCallback(
- (providerKey: string) => {
- clearDebounce();
- setScopeProviderKey(providerKey);
- setDebouncedQuery(trimmedQuery);
- setActiveRowId(null);
- focusInput();
- },
- [clearDebounce, focusInput, trimmedQuery]
- );
-
const runRow = useCallback(
(row: PaletteRow) => {
if (row.kind === 'label') {
@@ -571,9 +601,9 @@ export const useCommandPaletteController = ({
: 'Search commands, settings, and more…',
query,
rows,
- scopeErrorLabel: scopeProvider?.label.toLowerCase() ?? null,
scopeIsError: Boolean(scopeProvider && scopedQueryResult?.isError),
scopeIsFetching: Boolean(scopeProvider && scopedQueryResult?.isFetching),
+ scopeLabel: scopeProvider?.label.toLowerCase() ?? null,
secondaryHint: activeRow?.kind === 'entry' ? activeRow.entry.secondary?.label : undefined,
setInputElement,
stage,