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.

fix: unify command palette hotkey resolution

joshistoast299b99a97d53
diff --git a/invokeai/frontend/webv2/performance/architecture-baseline.json b/invokeai/frontend/webv2/performance/architecture-baseline.json
index ffd23831f4..4aebec6343 100644
--- a/invokeai/frontend/webv2/performance/architecture-baseline.json
+++ b/invokeai/frontend/webv2/performance/architecture-baseline.json
@@ -1,15 +1,15 @@
{
"schemaVersion": 1,
- "capturedAt": "2026-07-21",
+ "capturedAt": "2026-07-22",
"build": {
"launchpad": {
"source": "index.html",
"owner": "app",
"remediationTicket": "set-performance-budgets",
- "baselineOwnedRawBytes": 26824,
- "baselineInitialRawBytes": 1894171,
- "baselineGzipBytes": 559337,
- "baselineBrotliBytes": 561242,
+ "baselineOwnedRawBytes": 27837,
+ "baselineInitialRawBytes": 1922304,
+ "baselineGzipBytes": 568928,
+ "baselineBrotliBytes": 570982,
"initialChunkNames": [
"ModelsUiContext",
"Tooltip",
diff --git a/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.test.ts b/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.test.ts
index 203648ee5d..377a0811c7 100644
--- a/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
-import { firstPartyHotkeyCatalog } from './catalog';
+import { firstPartyHotkeyCatalog, OPEN_COMMAND_PALETTE_HOTKEY } from './catalog';
describe('firstPartyHotkeyCatalog', () => {
it('keeps legacy default hotkey parity', () => {
@@ -16,4 +16,10 @@ describe('firstPartyHotkeyCatalog', () => {
expect(firstPartyHotkeyCatalog.map((hotkey) => hotkey.id)).toContain('gallery.remix');
expect(firstPartyHotkeyCatalog.map((hotkey) => hotkey.id)).toContain('viewer.deleteImage');
});
+
+ it('uses the exported command-palette definition as the catalog entry', () => {
+ expect(firstPartyHotkeyCatalog.find((hotkey) => hotkey.id === 'app.openCommandPalette')).toBe(
+ OPEN_COMMAND_PALETTE_HOTKEY
+ );
+ });
});
diff --git a/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.ts b/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.ts
index 46cb2051e1..00610b37ec 100644
--- a/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.ts
+++ b/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.ts
@@ -103,10 +103,23 @@ const hotkey = (category: HotkeyCategory, id: string, defaultKeys: string[]): Ho
};
};
+// The palette must open while typing and toggle closed above its own modal
+// layer, so it opts into both editable and modal contexts.
+export const OPEN_COMMAND_PALETTE_HOTKEY: HotkeyDefinition = {
+ allowInEditable: true,
+ allowInModal: true,
+ category: 'app',
+ commandId: 'app.openCommandPalette',
+ defaultKeys: ['mod+k'],
+ id: 'app.openCommandPalette',
+ implemented: true,
+ preventDefault: true,
+ scope: { kind: 'global' },
+ title: 'Open Command Palette',
+};
+
export const firstPartyHotkeyCatalog: HotkeyDefinition[] = [
- // The palette must open while typing and toggle closed above its own modal
- // layer, so it opts into both editable and modal contexts.
- { ...hotkey('app', 'openCommandPalette', ['mod+k']), allowInEditable: true, allowInModal: true },
+ OPEN_COMMAND_PALETTE_HOTKEY,
hotkey('app', 'invoke', ['mod+enter']),
hotkey('app', 'invokeFront', ['mod+shift+enter']),
hotkey('app', 'cancelQueueItem', ['shift+x']),
diff --git a/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteHotkey.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteHotkey.browser.test.tsx
new file mode 100644
index 0000000000..f62351a0b7
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteHotkey.browser.test.tsx
@@ -0,0 +1,169 @@
+import type * as settingsStoreModule from '@workbench/settings/store';
+
+import { ChakraProvider } from '@chakra-ui/react';
+import { system } from '@theme/system';
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { userEvent } from 'vitest/browser';
+
+const testPreferences = vi.hoisted(() => ({ customHotkeys: {} as Record<string, string[]> }));
+
+vi.mock('@workbench/settings/store', async (importOriginal) => ({
+ ...(await importOriginal<typeof settingsStoreModule>()),
+ useWorkbenchPreferenceSelector: <Selected,>(selector: (preferences: typeof testPreferences) => Selected): Selected =>
+ selector(testPreferences),
+ useWorkbenchPreferences: () => testPreferences,
+}));
+
+vi.mock('react-i18next', () => ({
+ useTranslation: () => ({
+ t: (key: string, options?: { hotkey?: string }) =>
+ key === 'commandPalette.buttonTooltip'
+ ? `Command palette (${options?.hotkey ?? ''})`
+ : key === 'commandPalette.buttonLabel'
+ ? 'Command palette'
+ : key,
+ }),
+}));
+
+vi.mock('./LaunchpadCommandPaletteDialog', () => ({ default: () => <div data-testid="launchpad-palette" /> }));
+
+import { LaunchpadCommandPalette } from './LaunchpadCommandPalette';
+import { PaletteButton } from './PaletteButton';
+import { closeCommandPalette, useIsCommandPaletteOpen } from './paletteStore';
+
+let host: HTMLDivElement | null = null;
+let root: Root | null = null;
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+const OpenState = () => <output data-testid="palette-state">{useIsCommandPaletteOpen() ? 'open' : 'closed'}</output>;
+
+const renderLaunchpad = async (): Promise<void> => {
+ await act(() =>
+ root?.render(
+ <>
+ <input aria-label="Editable target" />
+ <LaunchpadCommandPalette />
+ <OpenState />
+ </>
+ )
+ );
+};
+
+const press = async ({ altKey = false, code, ctrlKey = false, key }: KeyboardEventInit): Promise<void> => {
+ const target = document.querySelector<HTMLInputElement>('[aria-label="Editable target"]') ?? window;
+
+ await act(() => {
+ target.dispatchEvent(new KeyboardEvent('keydown', { altKey, bubbles: true, cancelable: true, code, ctrlKey, key }));
+ });
+};
+
+const expectPaletteState = (state: 'closed' | 'open'): void => {
+ expect(document.querySelector('[data-testid="palette-state"]')?.textContent).toBe(state);
+};
+
+beforeEach(() => {
+ testPreferences.customHotkeys = {};
+ closeCommandPalette();
+ host = document.createElement('div');
+ document.body.append(host);
+ root = createRoot(host);
+});
+
+afterEach(async () => {
+ await act(() => {
+ closeCommandPalette();
+ root?.unmount();
+ });
+ host?.remove();
+ host = null;
+ root = null;
+});
+
+describe('Launchpad command-palette hotkeys', () => {
+ it('opens and closes from the default Mod+K binding, including from editable targets', async () => {
+ await renderLaunchpad();
+ document.querySelector<HTMLInputElement>('[aria-label="Editable target"]')?.focus();
+
+ await press({ code: 'KeyK', ctrlKey: true, key: 'k' });
+ expectPaletteState('open');
+
+ await press({ code: 'KeyK', ctrlKey: true, key: 'k' });
+ expectPaletteState('closed');
+ });
+
+ it('replaces the default binding and installs every custom binding', async () => {
+ testPreferences.customHotkeys = { 'app.openCommandPalette': ['alt+p', 'alt+o'] };
+ await renderLaunchpad();
+
+ await press({ code: 'KeyK', ctrlKey: true, key: 'k' });
+ expectPaletteState('closed');
+
+ await press({ altKey: true, code: 'KeyP', key: 'p' });
+ expectPaletteState('open');
+ await act(() => closeCommandPalette());
+
+ await press({ altKey: true, code: 'KeyO', key: 'o' });
+ expectPaletteState('open');
+ });
+
+ it('installs no listener when the command is unbound', async () => {
+ testPreferences.customHotkeys = { 'app.openCommandPalette': [] };
+ await renderLaunchpad();
+
+ await press({ code: 'KeyK', ctrlKey: true, key: 'k' });
+ expectPaletteState('closed');
+ });
+
+ it('replaces listeners when preferences change without remounting the Launchpad host', async () => {
+ testPreferences.customHotkeys = { 'app.openCommandPalette': ['alt+p'] };
+ await renderLaunchpad();
+
+ testPreferences.customHotkeys = { 'app.openCommandPalette': ['alt+o'] };
+ await renderLaunchpad();
+
+ await press({ altKey: true, code: 'KeyP', key: 'p' });
+ expectPaletteState('closed');
+
+ await press({ altKey: true, code: 'KeyO', key: 'o' });
+ expectPaletteState('open');
+ });
+});
+
+describe('PaletteButton hotkey tooltip', () => {
+ const renderButton = async (): Promise<HTMLButtonElement> => {
+ await act(() =>
+ root?.render(
+ <ChakraProvider value={system}>
+ <PaletteButton />
+ </ChakraProvider>
+ )
+ );
+
+ const button = document.querySelector<HTMLButtonElement>('button[aria-label="Command palette"]');
+ expect(button).not.toBeNull();
+ return button!;
+ };
+
+ it('displays the first effective custom binding', async () => {
+ testPreferences.customHotkeys = { 'app.openCommandPalette': ['alt+p', 'alt+o'] };
+ const button = await renderButton();
+
+ await act(async () => {
+ await userEvent.hover(button);
+ await vi.waitFor(() => expect(document.body.textContent).toContain('Command palette (alt+p)'));
+ });
+ });
+
+ it('falls back to the plain label when the command is unbound', async () => {
+ testPreferences.customHotkeys = { 'app.openCommandPalette': [] };
+ const button = await renderButton();
+
+ await act(async () => {
+ await userEvent.hover(button);
+ await vi.waitFor(() => expect(document.body.textContent).toContain('Command palette'));
+ });
+ expect(document.body.textContent).not.toContain('Command palette (');
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/palette/LaunchpadCommandPalette.tsx b/invokeai/frontend/webv2/src/workbench/palette/LaunchpadCommandPalette.tsx
index 02d22d6486..2942a64657 100644
--- a/invokeai/frontend/webv2/src/workbench/palette/LaunchpadCommandPalette.tsx
+++ b/invokeai/frontend/webv2/src/workbench/palette/LaunchpadCommandPalette.tsx
@@ -1,5 +1,7 @@
import { useMountEffect } from '@platform/react/useMountEffect';
-import { formatHotkeyForPlatform } from '@workbench/hotkeys/keys';
+import { OPEN_COMMAND_PALETTE_HOTKEY } from '@workbench/hotkeys/catalog';
+import { formatHotkeyForPlatform, toTinykeysBinding } from '@workbench/hotkeys/keys';
+import { applyCustomHotkeys } from '@workbench/hotkeys/resolve';
import { useWorkbenchPreferences } from '@workbench/settings/store';
import { lazy, Suspense } from 'react';
import { tinykeys } from 'tinykeys';
@@ -9,28 +11,43 @@ import { SETTINGS_ENTRY_DEPS } from './settingsEntryDeps';
const LazyLaunchpadCommandPaletteDialog = lazy(() => import('./LaunchpadCommandPaletteDialog'));
+const LaunchpadCommandPaletteHotkeys = ({ keys }: { keys: readonly string[] }) => {
+ useMountEffect(() => {
+ if (keys.length === 0) {
+ return;
+ }
+
+ const onHotkey = (event: KeyboardEvent): void => {
+ event.preventDefault();
+ toggleCommandPalette();
+ };
+ const bindings = Object.fromEntries(keys.map((key) => [toTinykeysBinding(key), onHotkey]));
+
+ return tinykeys(window, bindings, { ignore: () => false });
+ });
+
+ return null;
+};
+
/** Lightweight Launchpad runtime and lazy dialog host. */
export const LaunchpadCommandPalette = () => {
const isOpen = useIsCommandPaletteOpen();
const preferences = useWorkbenchPreferences();
+ const paletteHotkeys = applyCustomHotkeys(OPEN_COMMAND_PALETTE_HOTKEY, preferences.customHotkeys).keys;
- useMountEffect(() =>
- tinykeys(window, {
- '$mod+KeyK': (event) => {
- event.preventDefault();
- toggleCommandPalette();
- },
- })
+ return (
+ <>
+ <LaunchpadCommandPaletteHotkeys key={paletteHotkeys.join('\n')} keys={paletteHotkeys} />
+ {isOpen ? (
+ <Suspense fallback={null}>
+ <LazyLaunchpadCommandPaletteDialog
+ modifierKeyLabel={formatHotkeyForPlatform('mod')[0]!}
+ preferences={preferences}
+ settingsEntryDeps={SETTINGS_ENTRY_DEPS}
+ onClose={closeCommandPalette}
+ />
+ </Suspense>
+ ) : null}
+ </>
);
-
- return isOpen ? (
- <Suspense fallback={null}>
- <LazyLaunchpadCommandPaletteDialog
- modifierKeyLabel={formatHotkeyForPlatform('mod')[0]!}
- preferences={preferences}
- settingsEntryDeps={SETTINGS_ENTRY_DEPS}
- onClose={closeCommandPalette}
- />
- </Suspense>
- ) : null;
};
diff --git a/invokeai/frontend/webv2/src/workbench/palette/PaletteButton.tsx b/invokeai/frontend/webv2/src/workbench/palette/PaletteButton.tsx
index b0efd236dc..26b46481a9 100644
--- a/invokeai/frontend/webv2/src/workbench/palette/PaletteButton.tsx
+++ b/invokeai/frontend/webv2/src/workbench/palette/PaletteButton.tsx
@@ -1,20 +1,27 @@
import { Icon } from '@chakra-ui/react';
import { IconButton } from '@platform/ui/Button';
import { Tooltip } from '@platform/ui/Tooltip';
+import { OPEN_COMMAND_PALETTE_HOTKEY } from '@workbench/hotkeys/catalog';
import { formatHotkeyForPlatform } from '@workbench/hotkeys/keys';
+import { applyCustomHotkeys } from '@workbench/hotkeys/resolve';
+import { useWorkbenchPreferenceSelector } from '@workbench/settings/store';
import { SearchIcon } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { openCommandPalette } from './paletteStore';
-const hotkeyLabel = formatHotkeyForPlatform('mod+k').join('+');
-
-/** Pointer affordance for the palette; the kbd hint keeps mod+K discoverable. */
+/** Pointer affordance for the palette; the tooltip advertises its effective binding. */
export const PaletteButton = () => {
const { t } = useTranslation();
+ const customHotkeys = useWorkbenchPreferenceSelector((preferences) => preferences.customHotkeys);
+ const firstHotkey = applyCustomHotkeys(OPEN_COMMAND_PALETTE_HOTKEY, customHotkeys).keys[0];
+ const hotkeyLabel = firstHotkey ? formatHotkeyForPlatform(firstHotkey).join('+') : null;
+ const tooltip = hotkeyLabel
+ ? t('commandPalette.buttonTooltip', { hotkey: hotkeyLabel })
+ : t('commandPalette.buttonLabel');
return (
- <Tooltip content={t('commandPalette.buttonTooltip', { hotkey: hotkeyLabel })}>
+ <Tooltip content={tooltip}>
<IconButton aria-label={t('commandPalette.buttonLabel')} size="sm" variant="ghost" onClick={openCommandPalette}>
<Icon as={SearchIcon} />
</IconButton>