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(webv2): key icons in shortcut hints

joshistoaste44fdeeb9c45
diff --git a/invokeai/frontend/webv2/src/workbench/hotkeys/keyGlyphs.test.ts b/invokeai/frontend/webv2/src/workbench/hotkeys/keyGlyphs.test.ts
new file mode 100644
index 0000000000..b451a7a1ca
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/hotkeys/keyGlyphs.test.ts
@@ -0,0 +1,28 @@
+import { ArrowRightToLineIcon, ChevronUpIcon, CommandIcon, CornerDownLeftIcon, OptionIcon } from 'lucide-react';
+import { describe, expect, it } from 'vitest';
+
+import { getShortcutKeyIcon } from './keyGlyphs';
+
+describe('getShortcutKeyIcon', () => {
+ it('gives universal keycap symbols an icon on every platform', () => {
+ expect(getShortcutKeyIcon('enter', true)).toBe(CornerDownLeftIcon);
+ expect(getShortcutKeyIcon('enter', false)).toBe(CornerDownLeftIcon);
+ expect(getShortcutKeyIcon('tab', false)).toBe(ArrowRightToLineIcon);
+ });
+
+ it('gives modifier symbols to macOS only', () => {
+ expect(getShortcutKeyIcon('cmd', true)).toBe(CommandIcon);
+ expect(getShortcutKeyIcon('meta', true)).toBe(CommandIcon);
+ expect(getShortcutKeyIcon('option', true)).toBe(OptionIcon);
+ expect(getShortcutKeyIcon('ctrl', true)).toBe(ChevronUpIcon);
+ expect(getShortcutKeyIcon('ctrl', false)).toBeNull();
+ expect(getShortcutKeyIcon('shift', false)).toBeNull();
+ expect(getShortcutKeyIcon('meta', false)).toBeNull();
+ });
+
+ it('leaves plain keys as text', () => {
+ expect(getShortcutKeyIcon('k', true)).toBeNull();
+ expect(getShortcutKeyIcon('esc', true)).toBeNull();
+ expect(getShortcutKeyIcon('space', false)).toBeNull();
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/hotkeys/keyGlyphs.tsx b/invokeai/frontend/webv2/src/workbench/hotkeys/keyGlyphs.tsx
new file mode 100644
index 0000000000..5ea83fefe4
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/hotkeys/keyGlyphs.tsx
@@ -0,0 +1,86 @@
+import type { ReactNode } from 'react';
+
+import { chakra, Icon } from '@chakra-ui/react';
+import {
+ ArrowBigUpIcon,
+ ArrowDownIcon,
+ ArrowLeftIcon,
+ ArrowRightIcon,
+ ArrowRightToLineIcon,
+ ArrowUpIcon,
+ ChevronUpIcon,
+ CommandIcon,
+ CornerDownLeftIcon,
+ DeleteIcon,
+ OptionIcon,
+ type LucideIcon,
+} from 'lucide-react';
+
+import { IS_MAC_OS } from './keys';
+
+/**
+ * Keys whose keycap symbol is universal get an icon on every platform; the
+ * platform-branded modifier symbols (⌘ ⌥ ⇧ ⌃) are macOS-only — printing them
+ * in a Windows/Linux hint would name keys those keyboards do not have, so
+ * there the modifiers keep their word labels ("Ctrl", "Alt", "Win").
+ */
+const UNIVERSAL_KEY_ICONS: Record<string, LucideIcon> = {
+ arrowdown: ArrowDownIcon,
+ arrowleft: ArrowLeftIcon,
+ arrowright: ArrowRightIcon,
+ arrowup: ArrowUpIcon,
+ backspace: DeleteIcon,
+ enter: CornerDownLeftIcon,
+ tab: ArrowRightToLineIcon,
+};
+
+const MAC_MODIFIER_ICONS: Record<string, LucideIcon> = {
+ alt: OptionIcon,
+ cmd: CommandIcon,
+ ctrl: ChevronUpIcon,
+ meta: CommandIcon,
+ option: OptionIcon,
+ shift: ArrowBigUpIcon,
+};
+
+/** The icon for a canonical hotkey part (`enter`, `cmd`, …), or null when the part reads better as text. */
+export const getShortcutKeyIcon = (part: string, isMacOs: boolean = IS_MAC_OS): LucideIcon | null =>
+ UNIVERSAL_KEY_ICONS[part] ?? (isMacOs ? (MAC_MODIFIER_ICONS[part] ?? null) : null);
+
+/** Spoken names for keys whose visual form is an icon. */
+export const SHORTCUT_KEY_ARIA_LABELS: Record<string, string> = {
+ alt: 'Alt',
+ arrowdown: 'Arrow down',
+ arrowleft: 'Arrow left',
+ arrowright: 'Arrow right',
+ arrowup: 'Arrow up',
+ backspace: 'Backspace',
+ cmd: 'Meta',
+ ctrl: 'Control',
+ enter: 'Enter',
+ meta: 'Meta',
+ option: 'Alt',
+ shift: 'Shift',
+ tab: 'Tab',
+};
+
+/**
+ * One key of a shortcut hint: the key's icon where it has one, otherwise the
+ * caller's text fallback (each render site keeps its own text casing). Icon
+ * renders carry a screen-reader-only spoken name, so an icon-only `Kbd` still
+ * announces the key.
+ */
+export const ShortcutKeyGlyph = ({ fallback, part }: { fallback?: ReactNode; part: string }) => {
+ const GlyphIcon = getShortcutKeyIcon(part);
+
+ if (!GlyphIcon) {
+ return fallback ?? part;
+ }
+
+ return (
+ <>
+ <Icon aria-hidden="true" as={GlyphIcon} boxSize="2.5" verticalAlign="middle" />
+ <chakra.span srOnly>{SHORTCUT_KEY_ARIA_LABELS[part] ?? part}</chakra.span>
+ </>
+ );
+};
diff --git a/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteRows.tsx b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteRows.tsx
index 324e0955f2..031baad6e6 100644
--- a/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteRows.tsx
+++ b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteRows.tsx
@@ -3,6 +3,7 @@ import type { ReactNode, Ref } from 'react';
import { Box, HStack, Icon, Kbd, ScrollArea, Spacer, Text, chakra } from '@chakra-ui/react';
import { useVirtualizer } from '@tanstack/react-virtual';
import { dropdownGroupLabel } from '@theme/recipes';
+import { ShortcutKeyGlyph } from '@workbench/hotkeys/keyGlyphs';
import { CheckIcon } from 'lucide-react';
import { useCallback, useImperativeHandle, useState } from 'react';
import { useTranslation } from 'react-i18next';
@@ -102,7 +103,7 @@ const EntryRow = ({
<HStack flexShrink={0} gap="0.5">
{entry.keys.map((part) => (
<Kbd key={part} size="sm" textTransform="lowercase">
- {part}
+ <ShortcutKeyGlyph fallback={part} part={part} />
</Kbd>
))}
</HStack>
@@ -169,7 +170,7 @@ const ScopeRow = ({
</Text>
<Spacer />
<Kbd size="sm" textTransform="lowercase">
- tab
+ <ShortcutKeyGlyph fallback="tab" part="tab" />
</Kbd>
</HStack>
);
diff --git a/invokeai/frontend/webv2/src/workbench/settings/HotkeysSettingsSection.tsx b/invokeai/frontend/webv2/src/workbench/settings/HotkeysSettingsSection.tsx
index da500e0a01..b215fae051 100644
--- a/invokeai/frontend/webv2/src/workbench/settings/HotkeysSettingsSection.tsx
+++ b/invokeai/frontend/webv2/src/workbench/settings/HotkeysSettingsSection.tsx
@@ -9,6 +9,7 @@ import {
eventToHotkeyString,
useExtensionHotkeyDefinitions,
} from '@workbench/hotkeys';
+import { ShortcutKeyGlyph } from '@workbench/hotkeys/keyGlyphs';
import { patchWorkbenchPreferences, useWorkbenchPreferences } from '@workbench/settings/store';
import { CheckIcon, PlusIcon, RotateCcwIcon, SearchIcon, Trash2Icon, XIcon } from 'lucide-react';
import { Fragment, useCallback, useDeferredValue, useEffect, useMemo, useRef, useState } from 'react';
@@ -557,7 +558,7 @@ const HotkeyChip = ({
{formatHotkeyForPlatform(hotkey).map((part, index, parts) => (
<Fragment key={`${part}:${index}`}>
<Kbd size="sm" textTransform="lowercase">
- {part}
+ <ShortcutKeyGlyph fallback={part} part={part} />
</Kbd>
{index < parts.length - 1 ? (
<Text color="fg.subtle" fontSize="2xs">
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/InvokeButton.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/InvokeButton.tsx
index 660df611fb..d0f50c4e9c 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/InvokeButton.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/InvokeButton.tsx
@@ -15,6 +15,7 @@ import type { InvocationState } from './useInvocationState';
import { getInvokeIconMode } from './invokeButtonModel';
import { HIDE_BELOW_HINT_WIDTH } from './topbarBreakpoints';
+import { TopbarShortcutKeys } from './TopbarShortcutKeys';
import { useTopbarShortcutBinding } from './useTopbarShortcut';
const TOOLTIP_CONTENT_PROPS = { p: '0' };
@@ -51,8 +52,11 @@ export const InvokeButton = ({ state }: { state: InvocationState }) => {
const { t } = useTranslation();
const { blockingReasons, invoke, isValid } = state;
const shortcutBinding = useTopbarShortcutBinding('app.invoke');
- const shortcut = shortcutBinding?.display ?? null;
- const tooltipContent = useMemo(() => <InvokeTooltipContent shortcut={shortcut} state={state} />, [shortcut, state]);
+ const shortcutParts = shortcutBinding?.parts ?? null;
+ const tooltipContent = useMemo(
+ () => <InvokeTooltipContent shortcutParts={shortcutParts} state={state} />,
+ [shortcutParts, state]
+ );
const queueItems = useActiveProjectSelector((project) => project.queue.items);
const baseSummary = getQueueSummary(queueItems);
@@ -105,9 +109,9 @@ export const InvokeButton = ({ state }: { state: InvocationState }) => {
)}
</Box>
{t('topbar.invoke.invoke')}
- {shortcut ? (
+ {shortcutParts ? (
<Kbd css={HIDE_BELOW_HINT_WIDTH} variant="outline" color="bg" size="sm">
- {shortcut}
+ <TopbarShortcutKeys parts={shortcutParts} />
</Kbd>
) : null}
</Button>
@@ -115,7 +119,7 @@ export const InvokeButton = ({ state }: { state: InvocationState }) => {
);
};
-const InvokeTooltipContent = ({ shortcut, state }: { shortcut: string | null; state: InvocationState }) => {
+const InvokeTooltipContent = ({ shortcutParts, state }: { shortcutParts: string[] | null; state: InvocationState }) => {
const { t } = useTranslation();
const { batchCount, blockingReasons, invocation, isValid, promptExpansion } = state;
const destination = getDestinationLabel(invocation.destination);
@@ -133,9 +137,9 @@ const InvokeTooltipContent = ({ shortcut, state }: { shortcut: string | null; st
<Text fontSize="xs" fontWeight="800">
{isValid ? t('topbar.invoke.addToQueue') : t('topbar.invoke.unableToQueue')}
</Text>
- {shortcut ? (
+ {shortcutParts ? (
<Kbd size="sm" variant="subtle">
- {shortcut}
+ <TopbarShortcutKeys parts={shortcutParts} />
</Kbd>
) : null}
</HStack>
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/TopbarShortcutKeys.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/TopbarShortcutKeys.tsx
new file mode 100644
index 0000000000..701bac0fff
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/TopbarShortcutKeys.tsx
@@ -0,0 +1,22 @@
+import { chakra } from '@chakra-ui/react';
+import { ShortcutKeyGlyph } from '@workbench/hotkeys/keyGlyphs';
+import { IS_MAC_OS } from '@workbench/hotkeys/keys';
+import { Fragment } from 'react';
+
+import { formatTopbarShortcutPart } from './useTopbarShortcut';
+
+/**
+ * The per-key body of a topbar shortcut hint, rendered inside a `Kbd`: icons
+ * where a key has a universal glyph, the platform's text label otherwise.
+ * macOS runs keys together like its menu hints; elsewhere keys join with `+`.
+ */
+export const TopbarShortcutKeys = ({ parts }: { parts: string[] }) => (
+ <chakra.span alignItems="center" display="inline-flex" gap="0.5">
+ {parts.map((part, index) => (
+ <Fragment key={`${part}:${index}`}>
+ {index > 0 && !IS_MAC_OS ? <chakra.span>+</chakra.span> : null}
+ <ShortcutKeyGlyph fallback={formatTopbarShortcutPart(part)} part={part} />
+ </Fragment>
+ ))}
+ </chakra.span>
+);
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/useTopbarShortcut.ts b/invokeai/frontend/webv2/src/workbench/shell/topbar/useTopbarShortcut.ts
index 7ce812652b..6f76dc6d83 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/useTopbarShortcut.ts
+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/useTopbarShortcut.ts
@@ -32,6 +32,9 @@ const OTHER_LABELS: Record<string, string> = {
const formatPart = (part: string): string =>
IS_MAC_OS ? (MAC_GLYPHS[part] ?? part.toUpperCase()) : (OTHER_LABELS[part] ?? part.toUpperCase());
+/** One key's text label, for render sites that draw icons for some keys and need the text for the rest. */
+export const formatTopbarShortcutPart = formatPart;
+
export const formatTopbarShortcut = (hotkey: string): string =>
formatHotkeyForPlatform(hotkey)
.map(formatPart)
@@ -68,6 +71,8 @@ export const useTopbarShortcut = (commandId: string): string | null => {
export interface TopbarShortcutBinding {
aria: string;
display: string;
+ /** Canonical per-key tokens (`cmd`, `enter`, `k`, …) for glyph rendering. */
+ parts: string[];
}
export const useTopbarShortcutBinding = (commandId: string): TopbarShortcutBinding | null => {
@@ -75,5 +80,11 @@ export const useTopbarShortcutBinding = (commandId: string): TopbarShortcutBindi
const definition = findDefinition(commandId);
const firstKey = definition ? applyCustomHotkeys(definition, customHotkeys).keys[0] : undefined;
- return firstKey ? { aria: formatTopbarShortcutForAria(firstKey), display: formatTopbarShortcut(firstKey) } : null;
+ return firstKey
+ ? {
+ aria: formatTopbarShortcutForAria(firstKey),
+ display: formatTopbarShortcut(firstKey),
+ parts: formatHotkeyForPlatform(firstKey),
+ }
+ : null;
};