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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(webv2): show the modifier keycap in command palette hints
Josh Corbettb7dc953b2c8b
diff --git a/invokeai/frontend/webv2/src/workbench/hotkeys/keys.ts b/invokeai/frontend/webv2/src/workbench/hotkeys/keys.tsindex 30f1ba9c8f..63332ce13b 100644--- a/invokeai/frontend/webv2/src/workbench/hotkeys/keys.ts+++ b/invokeai/frontend/webv2/src/workbench/hotkeys/keys.ts@@ -90,11 +90,18 @@ export const toTinykeysBinding = (hotkey: string): string => {return parts.map((part) => TINY_MODIFIER_ALIASES[part] ?? TINY_KEY_ALIASES[part] ?? part).join('+');};+/** The `mod` key's platform name; a bare modifier normalizes to nothing, so use this rather than formatting 'mod'. */+export const MOD_KEY_LABEL = IS_MAC_OS ? 'cmd' : 'ctrl';+export const formatHotkeyForPlatform = (hotkey: string): string[] =>normalizeHotkeyString(hotkey).split('+').filter(Boolean)- .map((part) => (IS_MAC_OS ? part.replace('mod', 'cmd').replace('alt', 'option') : part.replace('mod', 'ctrl')));+ .map((part) => {+ const named = part.replace('mod', MOD_KEY_LABEL);++ return IS_MAC_OS ? named.replace('alt', 'option') : named;+ });/** Inputs that take no typed text: a switch or checkbox owning focus has no native undo/shortcut to protect. */const NON_TEXT_INPUT_TYPES = new Set([diff --git a/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteHotkey.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteHotkey.browser.test.tsxindex 8f45f622e9..59ccf1fccb 100644--- a/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteHotkey.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteHotkey.browser.test.tsx@@ -28,7 +28,11 @@ vi.mock('react-i18next', () => ({}),}));-vi.mock('./LaunchpadCommandPaletteDialog', () => ({ default: () => <div data-testid="launchpad-palette" /> }));+vi.mock('./LaunchpadCommandPaletteDialog', () => ({+ default: ({ modifierKeyLabel }: { modifierKeyLabel: string }) => (+ <div data-modifier-key-label={modifierKeyLabel} data-testid="launchpad-palette" />+ ),+}));import { LaunchpadCommandPalette } from './LaunchpadCommandPalette';import { PaletteButton } from './PaletteButton';@@ -90,6 +94,10 @@ describe('Launchpad command-palette hotkeys', () => {await press({ code: 'KeyK', ctrlKey: true, key: 'k' });expectPaletteState('open');+ // The lazy dialog's footer renders this as the Mod+Enter hint's first keycap.+ await expect+ .poll(() => document.querySelector('[data-testid="launchpad-palette"]')?.getAttribute('data-modifier-key-label'))+ .toBe(navigator.platform.toLowerCase().includes('mac') ? 'cmd' : 'ctrl');await press({ code: 'KeyK', ctrlKey: true, key: 'k' });expectPaletteState('closed');diff --git a/invokeai/frontend/webv2/src/workbench/palette/LaunchpadCommandPalette.tsx b/invokeai/frontend/webv2/src/workbench/palette/LaunchpadCommandPalette.tsxindex 90431b2dd6..4a050ef63f 100644--- a/invokeai/frontend/webv2/src/workbench/palette/LaunchpadCommandPalette.tsx+++ b/invokeai/frontend/webv2/src/workbench/palette/LaunchpadCommandPalette.tsx@@ -1,6 +1,6 @@import { useMountEffect } from '@platform/react/useMountEffect';import { OPEN_COMMAND_PALETTE_HOTKEY } from '@workbench/hotkeys/catalog';-import { formatHotkeyForPlatform, toTinykeysBinding } from '@workbench/hotkeys/keys';+import { MOD_KEY_LABEL, toTinykeysBinding } from '@workbench/hotkeys/keys';import { applyCustomHotkeys } from '@workbench/hotkeys/resolve';import { useWorkbenchPreferences, useWorkbenchPreferenceSelector } from '@workbench/settings/store';import { lazy, Suspense } from 'react';@@ -49,7 +49,7 @@ const OpenLaunchpadCommandPalette = () => {return (<Suspense fallback={null}><LazyLaunchpadCommandPaletteDialog- modifierKeyLabel={formatHotkeyForPlatform('mod')[0]!}+ modifierKeyLabel={MOD_KEY_LABEL}preferences={preferences}settingsEntryDeps={SETTINGS_ENTRY_DEPS}onClose={closeCommandPalette}diff --git a/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPalette.tsx b/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPalette.tsxindex 9225cc3eab..d848e0e51e 100644--- a/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPalette.tsx+++ b/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPalette.tsx@@ -1,7 +1,7 @@import { requestQueueItemReveal } from '@features/queue/reveal';import { useMountEffect } from '@platform/react/useMountEffect';import { firstPartyHotkeyCatalog } from '@workbench/hotkeys/catalog';-import { formatHotkeyForPlatform } from '@workbench/hotkeys/keys';+import { formatHotkeyForPlatform, MOD_KEY_LABEL } from '@workbench/hotkeys/keys';import { registerHotkeyModalLayer } from '@workbench/hotkeys/modalLayer';import { useWorkbenchPreferences } from '@workbench/settings/store';import { openWidgetPlacement } from '@workbench/widgetPlacementCommands';@@ -33,7 +33,7 @@ const OpenWorkbenchCommandPalette = () => {catalog={firstPartyHotkeyCatalog}formatHotkey={formatHotkeyForPlatform}getWidgetsForRegion={getWidgetsForRegion}- modifierKeyLabel={formatHotkeyForPlatform('mod')[0]!}+ modifierKeyLabel={MOD_KEY_LABEL}openWidgetPlacement={openWidgetPlacement}preferences={preferences}requestQueueItemReveal={requestQueueItemReveal}