Skip to content

Commit b548ac0

Browse files
hipsterusernamepsychedelicious
authored andcommitted
Add Star/Unstar Hotkey and fix hotkey translations
1 parent 2af2b8b commit b548ac0

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

invokeai/frontend/web/public/locales/en.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,11 @@
470470
"togglePanels": {
471471
"title": "Toggle Panels",
472472
"desc": "Show or hide both left and right panels at once."
473+
},
474+
"selectGenerateTab": {
475+
"title": "Select the Generate Tab",
476+
"desc": "Selects the Generate tab.",
477+
"key": "1"
473478
}
474479
},
475480
"canvas": {
@@ -607,6 +612,16 @@
607612
"fitBboxToMasks": {
608613
"title": "Fit Bbox To Masks",
609614
"desc": "Automatically adjust the generation bounding box to fit visible inpaint masks"
615+
},
616+
"applySegmentAnything": {
617+
"title": "Apply Segment Anything",
618+
"desc": "Apply the current Segment Anything mask.",
619+
"key": "enter"
620+
},
621+
"cancelSegmentAnything": {
622+
"title": "Cancel Segment Anything",
623+
"desc": "Cancel the current Segment Anything operation.",
624+
"key": "esc"
610625
}
611626
},
612627
"workflows": {
@@ -736,6 +751,10 @@
736751
"deleteSelection": {
737752
"title": "Delete",
738753
"desc": "Delete all selected images. By default, you will be prompted to confirm deletion. If the images are currently in use in the app, you will be warned."
754+
},
755+
"starImage": {
756+
"title": "Star/Unstar Image",
757+
"desc": "Star or unstar the selected image."
739758
}
740759
}
741760
},

invokeai/frontend/web/src/features/gallery/components/NewGallery.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import type {
2626
import { VirtuosoGrid } from 'react-virtuoso';
2727
import { imagesApi } from 'services/api/endpoints/images';
2828
import { useDebounce } from 'use-debounce';
29+
import { useImageDTO } from 'services/api/endpoints/images';
30+
import { useStarImagesMutation, useUnstarImagesMutation } from 'services/api/endpoints/images';
2931

3032
import { GalleryImage, GalleryImagePlaceholder } from './ImageGrid/GalleryImage';
3133
import { GallerySelectionCountTag } from './ImageGrid/GallerySelectionCountTag';
@@ -464,6 +466,30 @@ export const NewGallery = memo(() => {
464466
enabled: !isLoading,
465467
});
466468

469+
const lastSelectedImage = useAppSelector(selectLastSelectedImage);
470+
const selectionCount = useAppSelector((state) => state.gallery.selection.length);
471+
const isGalleryFocused = getFocusedRegion() === 'gallery';
472+
const imageDTO = useImageDTO(lastSelectedImage);
473+
const [starImages] = useStarImagesMutation();
474+
const [unstarImages] = useUnstarImagesMutation();
475+
476+
const handleStarHotkey = useCallback(() => {
477+
if (!imageDTO) return;
478+
if (imageDTO.starred) {
479+
unstarImages({ image_names: [imageDTO.image_name] });
480+
} else {
481+
starImages({ image_names: [imageDTO.image_name] });
482+
}
483+
}, [imageDTO, starImages, unstarImages]);
484+
485+
useRegisteredHotkeys({
486+
id: 'starImage',
487+
category: 'gallery',
488+
callback: handleStarHotkey,
489+
options: { enabled: !!imageDTO && selectionCount === 1 && isGalleryFocused },
490+
dependencies: [imageDTO, selectionCount, isGalleryFocused, handleStarHotkey],
491+
});
492+
467493
useKeepSelectedImageInView(imageNames, virtuosoRef, rootRef, rangeRef);
468494
useKeyboardNavigation(imageNames, virtuosoRef, rootRef);
469495
const scrollerRef = useScrollableGallery(rootRef);

invokeai/frontend/web/src/features/system/components/HotkeysModal/useHotkeyData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export const useHotkeyData = (): HotkeysData => {
160160
addHotkey('gallery', 'galleryNavDownAlt', ['alt+down']);
161161
addHotkey('gallery', 'galleryNavLeftAlt', ['alt+left']);
162162
addHotkey('gallery', 'deleteSelection', ['delete', 'backspace']);
163+
addHotkey('gallery', 'starImage', ['.']);
163164

164165
return data;
165166
}, [isMacOS, isModelManagerEnabled, t]);

0 commit comments

Comments
 (0)