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
feat(settings): fill the dialog with the hotkeys editor and focus search on /
Josh Corbett2bed60dfc1f3
diff --git a/invokeai/frontend/webv2/src/platform/ui/Scrollable.tsx b/invokeai/frontend/webv2/src/platform/ui/Scrollable.tsxindex fefd507125..3d184180d2 100644--- a/invokeai/frontend/webv2/src/platform/ui/Scrollable.tsx+++ b/invokeai/frontend/webv2/src/platform/ui/Scrollable.tsx@@ -1,8 +1,8 @@-import type { ComponentProps, ReactNode, RefObject } from 'react';+import type { ComponentProps, ReactNode, Ref } from 'react';-import { ScrollArea } from '@chakra-ui/react';+import { mergeRefs, ScrollArea } from '@chakra-ui/react';import { usePreservedScrollOffset } from '@platform/react/usePreservedScrollOffset';-import { useRef } from 'react';+import { useCallback, useRef } from 'react';import { useScrollAreaPhantomHeal } from './useScrollAreaPhantomHeal';@@ -45,13 +45,24 @@ export const Scrollable = ({orientation?: 'horizontal' | 'vertical';/** Extra props for the scrolling viewport itself, e.g. scroll/focus handlers. */viewportProps?: ScrollAreaViewportProps;- /** The scrolling element itself — what a virtualizer needs to observe. */- viewportRef?: RefObject<HTMLDivElement | null>;+ /**+ * The scrolling element itself — what a virtualizer needs to observe. A+ * callback ref is attached alongside the internal one, for mount-time work+ * such as restoring a remembered offset.+ */+ viewportRef?: Ref<HTMLDivElement | null>;}) => {const fallbackViewportRef = useRef<HTMLDivElement | null>(null);- // One ref, shared with the caller when it wants one, so nothing has to merge- // or reassign refs during render.- const resolvedViewportRef = viewportRef ?? fallbackViewportRef;+ // One object ref, shared with the caller when it hands one in, so nothing+ // has to merge or reassign refs during render.+ const resolvedViewportRef = viewportRef && typeof viewportRef !== 'function' ? viewportRef : fallbackViewportRef;+ const viewportCallback = typeof viewportRef === 'function' ? viewportRef : undefined;+ // A callback ref is composed with the object ref the hooks observe; the+ // composition only runs when React attaches the element, never in render.+ const attachViewport = useCallback(+ (element: HTMLDivElement | null) => mergeRefs(fallbackViewportRef, viewportCallback)(element),+ [viewportCallback]+ );// The shell keeps widgets mounted across layout switches, and a scroll// container that stops being rendered loses its offset outright.@@ -67,7 +78,7 @@ export const Scrollable = ({role={label ? 'region' : undefined}w="full"{...viewportProps}- ref={resolvedViewportRef}+ ref={viewportCallback ? attachViewport : resolvedViewportRef}><ScrollArea.Contentstyle={orientation === 'horizontal' ? undefined : VERTICAL_CONTENT_STYLE}diff --git a/invokeai/frontend/webv2/src/platform/ui/settings/contracts.ts b/invokeai/frontend/webv2/src/platform/ui/settings/contracts.tsindex 7d226d71ab..24b7578c16 100644--- a/invokeai/frontend/webv2/src/platform/ui/settings/contracts.ts+++ b/invokeai/frontend/webv2/src/platform/ui/settings/contracts.ts@@ -19,7 +19,8 @@ export type SettingDefinition = SettingBase &| { kind: 'boolean' }| { kind: 'select'; options: readonly { label: SettingsText; value: string }[] }| { kind: 'number' | 'slider'; min: number; max: number; step?: number }- | { kind: 'custom' }+ /** `fill`: the editor owns its scrolling and takes the dialog body's full height. */+ | { kind: 'custom'; fill?: boolean });export interface SettingsTarget {diff --git a/invokeai/frontend/webv2/src/workbench/settings/CustomSettingsEditors.tsx b/invokeai/frontend/webv2/src/workbench/settings/CustomSettingsEditors.tsxindex 4f70443e76..dfb7e1fd70 100644--- a/invokeai/frontend/webv2/src/workbench/settings/CustomSettingsEditors.tsx+++ b/invokeai/frontend/webv2/src/workbench/settings/CustomSettingsEditors.tsx@@ -240,9 +240,10 @@ const CustomSettingField = ({ field }: SettingFieldProps) => {editor = <GenerationDevicesSettings />;break;case 'hotkeys':- // The hotkey editor owns its heading and needs a bounded viewport for its virtual list.+ // The hotkey editor owns its heading; its virtual list takes the height+ // the dialog hands a `fill` entry (see `isFillSettingsEntry`).return (- <Box h="32rem" maxH="calc(100dvh - 15rem)" minH="16rem">+ <Box display="flex" flex="1" flexDirection="column" minH="0"><HotkeysSettingsSection /></Box>);diff --git a/invokeai/frontend/webv2/src/workbench/settings/SettingsDialog.tsx b/invokeai/frontend/webv2/src/workbench/settings/SettingsDialog.tsxindex ae1748ffab..f818353915 100644--- a/invokeai/frontend/webv2/src/workbench/settings/SettingsDialog.tsx+++ b/invokeai/frontend/webv2/src/workbench/settings/SettingsDialog.tsx@@ -1,10 +1,24 @@import type { ChangeEvent, UIEvent } from 'react';-import { Box, Dialog, Flex, HStack, Icon, Input, NativeSelect, Stack, Text, VisuallyHidden } from '@chakra-ui/react';+import {+ Box,+ Dialog,+ Flex,+ HStack,+ Icon,+ Input,+ InputGroup,+ Kbd,+ NativeSelect,+ Stack,+ Text,+ VisuallyHidden,+} from '@chakra-ui/react';import { useCapabilities } from '@features/identity';import { useMountEffect } from '@platform/react/useMountEffect';import { Button } from '@platform/ui/Button';import { PanelHeader } from '@platform/ui/PanelHeader';+import { Scrollable } from '@platform/ui/Scrollable';import { resolveSettingsText } from '@platform/ui/settings/contracts';import {useActiveProjectId,@@ -13,7 +27,7 @@ import {useWorkbenchSubscription,} from '@workbench/WorkbenchContext';import { SearchIcon, XIcon } from 'lucide-react';-import { useCallback } from 'react';+import { useCallback, useMemo } from 'react';import { useTranslation } from 'react-i18next';import type { SettingsSection } from './catalog';@@ -27,7 +41,7 @@ import {setWorkbenchSettingsSection,settingsDialogStore,} from './settingsDialogStore';-import { SettingsEntryView } from './SettingsEntryView';+import { isFillSettingsEntry, SettingsEntryView } from './SettingsEntryView';import { SettingsScopeLabel } from './SettingsScopeLabel';import { patchWorkbenchPreferences, useWorkbenchSettingsSelector } from './store';@@ -49,13 +63,24 @@ const SEARCH_PADDING = { base: '12', sm: '3' };const MOBILE_DISPLAY = { base: 'block', sm: 'none' };const DESKTOP_DISPLAY = { base: 'none', sm: 'block' };const CONTENT_PADDING = { base: '4', md: '6' };-const clearSearch = () => setSettingsQuery('');const rememberScroll = (event: UIEvent<HTMLDivElement>) => {const current = settingsDialogStore.getSnapshot();if (!current.query.trim()) {rememberSettingsSectionScroll(current.sectionId, event.currentTarget.scrollTop);}};+const SEARCH_START_ELEMENT = <Icon as={SearchIcon} boxSize="3.5" color="fg.muted" />;+/** The `/` shortcut the dialog content handles (see `SettingsDialogHost`). */+const SEARCH_HOTKEY_HINT = (+ <Kbd aria-hidden pointerEvents="none" size="sm" variant="outline">+ /+ </Kbd>+);+const FILL_SECTION_PROPS = { display: 'flex', flex: '1', flexDirection: 'column', minH: '0' } as const;+const FILL_BODY_PROPS = { ...FILL_SECTION_PROPS, pb: '4' } as const;+const BODY_VIEWPORT_PROPS = { onScroll: rememberScroll };+const BODY_CONTENT_PROPS = { px: CONTENT_PADDING, pb: '4' } as const;+const clearSearch = () => setSettingsQuery('');const retrySave = () => {void patchWorkbenchPreferences({});};@@ -104,12 +129,28 @@ const SettingsDialog = () => {[selectSection]);const changeQuery = useCallback((event: ChangeEvent<HTMLInputElement>) => setSettingsQuery(event.target.value), []);+ // The end slot is a clear control while there is a query, and the `/` hint otherwise.+ const searchEndElement = useMemo(+ () =>+ state.query ? (+ <Button aria-label={t('settingsDialog.clearSearch')} me="-2" size="2xs" variant="ghost" onClick={clearSearch}>+ <XIcon />+ </Button>+ ) : (+ SEARCH_HOTKEY_HINT+ ),+ [state.query, t]+ );const attachBody = useCallback((element: HTMLDivElement | null) => {const current = settingsDialogStore.getSnapshot();if (element && !current.query.trim() && !current.entryId) {element.scrollTop = getSettingsSectionScroll(current.sectionId);}}, []);+ // A filling editor (the hotkeys table) scrolls itself: the body hands it the+ // height instead of wrapping it in a second scroll container.+ const fills =+ !searching && displayed.length === 1 && displayed[0].entries.some((entry) => isFillSettingsEntry(entry, 'dialog'));return (<Flex h="full" minH="0" direction={DIRECTION}>{hasWorkbench ? <ProjectLifetime /> : null}@@ -125,30 +166,16 @@ const SettingsDialog = () => {minH="0"><Box p="3" pe={SEARCH_PADDING}>- <HStack position="relative">- <Icon as={SearchIcon} position="absolute" left="2.5" boxSize="3.5" color="fg.muted" pointerEvents="none" />+ <InputGroup endElement={searchEndElement} startElement={SEARCH_START_ELEMENT}><Input+ data-settings-searcharia-label={t('settingsDialog.search')}placeholder={t('settingsDialog.search')}value={state.query}- ps="8"- pe="8"size="sm"onChange={changeQuery}/>- {state.query ? (- <Button- aria-label={t('settingsDialog.clearSearch')}- position="absolute"- right="0"- size="2xs"- variant="ghost"- onClick={clearSearch}- >- <XIcon />- </Button>- ) : null}- </HStack>+ </InputGroup></Box><Box display={MOBILE_DISPLAY} px="3" pb="3"><NativeSelect.Root size="sm">@@ -167,16 +194,7 @@ const SettingsDialog = () => {<NativeSelect.Indicator /></NativeSelect.Root></Box>- <Box- as="nav"- aria-label={t('settings.title')}- display={DESKTOP_DISPLAY}- overflowY="auto"- flex="1"- minH="0"- px="2"- pb="3"- >+ <Scrollable as="nav" aria-label={t('settings.title')} display={DESKTOP_DISPLAY} flex="1" minH="0" px="2" pb="3">{searching ? (<Buttonw="full"@@ -211,7 +229,7 @@ const SettingsDialog = () => {</Stack>);})}- </Box>+ </Scrollable></Flex><Flex direction="column" flex="1" minW="0" minH="0"><Dialog.Header asChild>@@ -236,33 +254,45 @@ const SettingsDialog = () => {</HStack>) : null}<VisuallyHidden role="status">{searching ? t('settingsDialog.resultCount', { count }) : ''}</VisuallyHidden>- <Box- key={searching ? `search:${state.searchSection ?? ''}` : active.id}- ref={attachBody}- onScroll={rememberScroll}- overflowY="auto"- flex="1"- minH="0"- px={CONTENT_PADDING}- pb="4"- >- {displayed.map((section) => (- <SettingsSectionContent- key={section.id}- section={section}- search={searching}- onReveal={setWorkbenchSettingsSection}- />- ))}- {searching && !displayed.length ? (- <Stack align="center" py="12" gap="3">- <Text color="fg.muted">{t('settingsDialog.noResults')}</Text>- <Button size="sm" variant="outline" onClick={clearSearch}>- {t('settingsDialog.clearSearch')}- </Button>- </Stack>- ) : null}- </Box>+ {fills ? (+ <Box key={active.id} px={CONTENT_PADDING} {...FILL_BODY_PROPS}>+ {displayed.map((section) => (+ <SettingsSectionContent+ key={section.id}+ fill+ section={section}+ search={false}+ onReveal={setWorkbenchSettingsSection}+ />+ ))}+ </Box>+ ) : (+ <Scrollable+ key={searching ? `search:${state.searchSection ?? ''}` : active.id}+ contentProps={BODY_CONTENT_PROPS}+ flex="1"+ minH="0"+ viewportProps={BODY_VIEWPORT_PROPS}+ viewportRef={attachBody}+ >+ {displayed.map((section) => (+ <SettingsSectionContent+ key={section.id}+ section={section}+ search={searching}+ onReveal={setWorkbenchSettingsSection}+ />+ ))}+ {searching && !displayed.length ? (+ <Stack align="center" py="12" gap="3">+ <Text color="fg.muted">{t('settingsDialog.noResults')}</Text>+ <Button size="sm" variant="outline" onClick={clearSearch}>+ {t('settingsDialog.clearSearch')}+ </Button>+ </Stack>+ ) : null}+ </Scrollable>+ )}</Flex></Flex>);@@ -300,10 +330,12 @@ const SettingsNavigationItem = ({};const SettingsSectionContent = ({+ fill = false,section,search,onReveal,}: {+ fill?: boolean;section: SettingsSection;search: boolean;onReveal: (sectionId: string, entryId?: string) => void;@@ -313,7 +345,7 @@ const SettingsSectionContent = ({snapshot.sectionId === section.id ? snapshot.target : undefined);return (- <Box>+ <Box {...(fill ? FILL_SECTION_PROPS : undefined)}>{!search && section.entries[0] ? (<Box pt="3"><SettingsScopeLabel scope={section.entries[0].field.scope} />diff --git a/invokeai/frontend/webv2/src/workbench/settings/SettingsDialogHost.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/settings/SettingsDialogHost.browser.test.tsxindex 244fd02e26..0cd4247feb 100644--- a/invokeai/frontend/webv2/src/workbench/settings/SettingsDialogHost.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/settings/SettingsDialogHost.browser.test.tsx@@ -7,7 +7,7 @@ import { act } from 'react';import { createRoot, type Root } from 'react-dom/client';import { I18nextProvider, initReactI18next } from 'react-i18next';import { afterEach, expect, it, vi } from 'vitest';-import { page } from 'vitest/browser';+import { page, userEvent } from 'vitest/browser';import { SettingsDialogHost } from './SettingsDialogHost';import { openWorkbenchSettings, settingsDialogStore } from './settingsDialogStore';@@ -37,7 +37,8 @@ vi.mock('./dialogResource', async () => {default: () => (<Dialog.Body><Dialog.Title>Settings: Behavior</Dialog.Title>- <input aria-label="Search settings" />+ <input aria-label="Search settings" data-settings-search />+ <button type="button">Reset all</button></Dialog.Body>),}));@@ -106,8 +107,12 @@ it('keeps a named modal through loading, failure, retry, and closing before restawait expect.element(page.getByRole('dialog', { name: 'Settings: Behavior', exact: true })).toBeVisible();await expect.element(page.getByRole('alert')).not.toBeInTheDocument();expect(isHotkeyModalLayerActive()).toBe(true);- await page.getByRole('textbox', { name: 'Search settings', exact: true }).click();+ // `/` from a control inside the dialog jumps to search; inside the search it types.+ await page.getByRole('button', { name: 'Reset all', exact: true }).click();+ await userEvent.keyboard('/');await expect.element(page.getByRole('textbox', { name: 'Search settings', exact: true })).toHaveFocus();+ await userEvent.keyboard('/');+ await expect.element(page.getByRole('textbox', { name: 'Search settings', exact: true })).toHaveValue('/');await act(() =>document.querySelector<HTMLButtonElement>('[data-scope="dialog"][data-part="close-trigger"]')!.click());diff --git a/invokeai/frontend/webv2/src/workbench/settings/SettingsDialogHost.tsx b/invokeai/frontend/webv2/src/workbench/settings/SettingsDialogHost.tsxindex 8f2e4048d4..88347f35f9 100644--- a/invokeai/frontend/webv2/src/workbench/settings/SettingsDialogHost.tsx+++ b/invokeai/frontend/webv2/src/workbench/settings/SettingsDialogHost.tsx@@ -3,11 +3,30 @@ import { useMountEffect } from '@platform/react/useMountEffect';import { CloseButton } from '@platform/ui';import { RetryBoundary } from '@platform/ui/RetryBoundary';import { registerHotkeyModalLayer } from '@workbench/hotkeys/modalLayer';-import { Suspense, use, useMemo } from 'react';+import { Suspense, use, useMemo, type KeyboardEvent } from 'react';import { useTranslation } from 'react-i18next';import { settingsDialogResource as dialogResource } from './dialogResource';import { closeWorkbenchSettings, settingsDialogStore } from './settingsDialogStore';+const isEditingTarget = (target: EventTarget | null): boolean =>+ target instanceof HTMLElement &&+ (target.isContentEditable || ['INPUT', 'SELECT', 'TEXTAREA'].includes(target.tagName));++/** `/` from anywhere in the dialog jumps to its search, unless a field is being edited. */+const focusSearchOnSlash = (event: KeyboardEvent<HTMLDivElement>) => {+ if (event.key !== '/' || event.ctrlKey || event.metaKey || event.altKey || isEditingTarget(event.target)) {+ return;+ }++ const search = event.currentTarget.querySelector<HTMLInputElement>('[data-settings-search]');++ if (search) {+ event.preventDefault();+ search.focus();+ search.select();+ }+};+const LoadedDialog = () => {const { default: SettingsDialog } = use(dialogResource.load());return <SettingsDialog />;@@ -60,6 +79,7 @@ export const SettingsDialogHost = () => {<Dialog.Contentaria-label={t('settings.title')}h="min(48rem, calc(100dvh - 2rem))"+ onKeyDown={focusSearchOnSlash}maxW="64rem"w="calc(100dvw - 2rem)"overflow="hidden"diff --git a/invokeai/frontend/webv2/src/workbench/settings/SettingsEntryView.tsx b/invokeai/frontend/webv2/src/workbench/settings/SettingsEntryView.tsxindex 4913d62111..c75f249647 100644--- a/invokeai/frontend/webv2/src/workbench/settings/SettingsEntryView.tsx+++ b/invokeai/frontend/webv2/src/workbench/settings/SettingsEntryView.tsx@@ -14,12 +14,16 @@ import type { SettingsEntry, SettingsSection } from './catalog';import { settingsDialogStore } from './settingsDialogStore';import { SettingsScopeLabel } from './SettingsScopeLabel';+const FILL_PROPS = { display: 'flex', flex: '1', flexDirection: 'column', minH: '0' } as const;+const LoadedSetting = ({entry,+ fill,target,surface,}: {entry: SettingsEntry;+ fill: boolean;target?: SettingsTarget;surface: 'quick' | 'dialog';}) => {@@ -37,12 +41,16 @@ const LoadedSetting = ({[entry.field.id, surface]);return (- <Box ref={attach}>+ <Box ref={attach} {...(fill ? FILL_PROPS : undefined)}><Field field={entry.field} surface={surface} target={target} /></Box>);};+/** A custom editor that owns its scrolling fills the dialog body instead of stacking in it. */+export const isFillSettingsEntry = (entry: SettingsEntry, surface: 'quick' | 'dialog'): boolean =>+ surface === 'dialog' && entry.field.kind === 'custom' && entry.field.fill === true;+export const SettingsEntryView = ({entry,section,@@ -88,6 +96,7 @@ export const SettingsEntryView = ({const unavailable = (entry.field.scope === 'instance' || entry.field.scope === 'project') && !target;const scope = entry.field.scope;const isDestination = search && entry.field.kind === 'custom';+ const fill = !search && !unavailable && isFillSettingsEntry(entry, surface);return (<>{showGroup && entry.field.group ? (@@ -105,8 +114,9 @@ export const SettingsEntryView = ({<Boxdata-setting-id={entry.field.id}py={surface === 'quick' ? '1.5' : '4'}- borderBottomWidth="1px"+ borderBottomWidth={fill ? '0' : '1px'}borderColor="border.subtle"+ {...(fill ? FILL_PROPS : undefined)}>{unavailable || isDestination ? (<Stack gap="2">@@ -136,7 +146,7 @@ export const SettingsEntryView = ({retryLabel={t('common.retry')}><Suspense fallback={loading}>- <LoadedSetting entry={entry} target={target ?? undefined} surface={surface} />+ <LoadedSetting entry={entry} fill={fill} target={target ?? undefined} surface={surface} /></Suspense></RetryBoundary>)}diff --git a/invokeai/frontend/webv2/src/workbench/settings/applicationContributions.ts b/invokeai/frontend/webv2/src/workbench/settings/applicationContributions.tsindex 3a9a545b06..6c88cd5db7 100644--- a/invokeai/frontend/webv2/src/workbench/settings/applicationContributions.ts+++ b/invokeai/frontend/webv2/src/workbench/settings/applicationContributions.ts@@ -14,12 +14,18 @@ const preference = (id: string, label: string, keywords?: string): SettingDefinikind: 'boolean',scope: 'preference',});-const custom = (id: string, label: string, scope: SettingDefinition['scope'] = 'preference'): SettingDefinition => ({+const custom = (+ id: string,+ label: string,+ scope: SettingDefinition['scope'] = 'preference',+ options: { fill?: boolean } = {}+): SettingDefinition => ({id,label: text(`${id}.label`, label),description: text(`${id}.description`),kind: 'custom',scope,+ ...options,});const section = (id: string, label: string, fields: readonly SettingDefinition[]): SettingsContribution => ({id,@@ -49,7 +55,9 @@ export const behaviorSettings = section('behavior', 'Behavior', [preference('preferNumericAttentionStyle', 'Prefer numeric attention style', 'generate prompt editor'),preference('showPromptSyntaxHighlighting', 'Highlight prompt syntax', 'generate prompt editor'),]);-export const hotkeysSettings = section('hotkeys', 'Keyboard shortcuts', [custom('hotkeys', 'Keyboard shortcuts')]);+export const hotkeysSettings = section('hotkeys', 'Keyboard shortcuts', [+ custom('hotkeys', 'Keyboard shortcuts', 'preference', { fill: true }),+]);export const projectSettings = section('project', 'Project', [{...preference('useCpuNoise', 'Use CPU noise'),