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(webv2): let Ctrl/Cmd+Enter reach the app from a gallery tile

Josh Corbett5bcce60d75bf
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx
index af2ae50f5f..605119792b 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx
@@ -864,6 +864,32 @@ describe('GalleryImageGrid mixed item cells', () => {
expect(onDragStart).not.toHaveBeenCalled();
});
+ it.each([
+ { chord: '{Control>}{Enter}{/Control}', modifier: 'ctrlKey' },
+ { chord: '{Meta>}{Enter}{/Meta}', modifier: 'metaKey' },
+ ])(
+ 'lets $modifier+Enter reach app hotkeys from a focused tile without activating it or starting a drag',
+ async ({ chord, modifier }) => {
+ const image = createItem('image', 'chord.png');
+ const reachedWindow = vi.fn();
+ window.addEventListener('keydown', reachedWindow);
+
+ try {
+ await renderGallery(createGallery({ items: [image] }));
+ const imageButton = getButton('Select chord.png for preview');
+
+ await interact(() => imageButton.focus());
+ await act(() => userEvent.keyboard(chord));
+
+ expect(reachedWindow).toHaveBeenCalledWith(expect.objectContaining({ key: 'Enter', [modifier]: true }));
+ expect(actionMocks.selectItem).not.toHaveBeenCalled();
+ expect(onDragStart).not.toHaveBeenCalled();
+ } finally {
+ window.removeEventListener('keydown', reachedWindow);
+ }
+ }
+ );
+
it('preserves the ordered full selection when an unloaded video is dragged from a loaded image', async () => {
await renderGallery(
createGallery({
@@ -1592,13 +1618,17 @@ describe('shared gallery progress section', () => {
createGallery({ items: [regular], selectedItemKey: 'image:starred.png', selectedItemKeys: ['image:starred.png'] })
);
registeredCommands.get('gallery.galleryNavDown')?.();
- expect(actionMocks.selectItem).toHaveBeenLastCalledWith(regular);
+ expect(followProgressSession).toHaveBeenLastCalledWith('run:1', { revealPreview: false });
registeredCommands.get('gallery.galleryNavRight')?.();
expect(followProgressSession).toHaveBeenLastCalledWith('run:1', { revealPreview: false });
+ registeredCommands.get('gallery.galleryNavUp')?.();
+ registeredCommands.get('gallery.galleryNavLeft')?.();
expect(followProgressSession).toHaveBeenCalledTimes(3);
+ expect(actionMocks.selectItem).toHaveBeenCalledTimes(2);
});
it('skips waiting tiles, which cannot be followed, and steps past a collapsed section', async () => {
const starred = createItem('image', 'starred.png', { starred: true });
+ const regular = createItem('image', 'regular.png');
currentProgressSessions = [
session,
{ ...session, id: 'run:2', itemIndex: 2, backendItemId: null, state: 'queued' },
@@ -1615,20 +1645,20 @@ describe('shared gallery progress section', () => {
currentLiveFollowEnabled = false;
await renderGallery(
createGallery({
+ items: [regular],
selectedItemKey: 'image:starred.png',
selectedItemKeys: ['image:starred.png'],
settings: { ...getGallerySettings({}), progressSectionCollapsed: true },
})
);
- registeredCommands.get('gallery.galleryNavLeft')?.();
+ registeredCommands.get('gallery.galleryNavDown')?.();
+ expect(actionMocks.selectItem).toHaveBeenLastCalledWith(regular);
expect(followProgressSession).not.toHaveBeenCalled();
expect(actionMocks.selectItem).toHaveBeenCalledTimes(2);
});
- expect(actionMocks.selectItem).toHaveBeenCalledTimes(2);
it('steps out of a starred selection the strip does not show instead of resetting', async () => {
const shown = Array.from({ length: 12 }, (_, index) =>
createItem('image', `starred-${index}.png`, { starred: true })
- const regular = createItem('image', 'regular.png');
);
const hidden = createItem('image', 'starred-hidden.png', { starred: true });
const regular = createItem('image', 'regular.png');
@@ -1645,12 +1675,8 @@ describe('shared gallery progress section', () => {
expect(shownCount).toBeLessThan(13);
registeredCommands.get('gallery.galleryNavRight')?.();
- items: [regular],
- expect(followProgressSession).toHaveBeenLastCalledWith('run:1', { revealPreview: false });
- registeredCommands.get('gallery.galleryNavUp')?.();
- registeredCommands.get('gallery.galleryNavLeft')?.();
- registeredCommands.get('gallery.galleryNavDown')?.();
expect(actionMocks.selectItem).toHaveBeenLastCalledWith(regular);
+ registeredCommands.get('gallery.galleryNavLeft')?.();
expect(actionMocks.selectItem).toHaveBeenLastCalledWith(shown[shownCount - 1]);
// Under a collapsed disclosure the whole strip is hidden; the selection still steps into the listing.
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryThumbnail.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryThumbnail.tsx
index 1756125c55..6404b4642a 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryThumbnail.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryThumbnail.tsx
@@ -18,6 +18,9 @@ import { GalleryTileFrame } from './GalleryTileFrame';
const THUMBNAIL_DRAG_CSS = { filter: 'saturate(0)' } as const;
const THUMBNAIL_ARMED_CSS = { '&[data-drag-armed=true]': { filter: 'saturate(0)' } } as const;
+/** Modified chords are app hotkeys (Mod+Enter invokes), never tile activation or a keyboard drag. */
+const isModifiedKey = (event: KeyboardEvent) => event.ctrlKey || event.metaKey || event.altKey || event.shiftKey;
+
const PREVIEW_IMAGE_STYLE = {
borderRadius: '0.375rem',
boxShadow: '0 8px 24px rgb(0 0 0 / 45%)',
@@ -85,6 +88,18 @@ const GalleryThumbnail = ({
data: getGalleryItemDragData(dragItems),
id: getGalleryItemDragId(toGalleryItemRef(item), 'gallery-grid', dragScope),
});
+ const dragListeners = useMemo(
+ () =>
+ listeners && {
+ ...listeners,
+ onKeyDown: (event: KeyboardEvent) => {
+ if (!isModifiedKey(event)) {
+ listeners.onKeyDown?.(event);
+ }
+ },
+ },
+ [listeners]
+ );
// Portal the drag preview to escape the grid's overflow clipping and transformed virtual rows.
const tileRef = useRef<HTMLDivElement | null>(null);
@@ -153,7 +168,7 @@ const GalleryThumbnail = ({
const handleClick = useCallback((event: MouseEvent) => onClick(item, event), [item, onClick]);
const handleActivationKeyDown = useCallback((event: KeyboardEvent<HTMLButtonElement>) => {
- if (event.key === 'Enter' || event.key === ' ') {
+ if (!isModifiedKey(event) && (event.key === 'Enter' || event.key === ' ')) {
event.stopPropagation();
}
}, []);
@@ -179,7 +194,7 @@ const GalleryThumbnail = ({
return (
<GalleryTileFrame
ref={setTileRef}
- {...listeners}
+ {...dragListeners}
alwaysShowDimensions={alwaysShowDimensions}
boxShadow={isCompared ? 'inset 0 0 0 1px {colors.accent.solid}' : undefined}
css={isDragging ? THUMBNAIL_DRAG_CSS : THUMBNAIL_ARMED_CSS}