Add Star/Unstar Hotkey and fix hotkey translations

This commit is contained in:
Kent Keirsey
2025-07-21 15:07:32 -04:00
committed by psychedelicious
parent 2af2b8b6c4
commit b548ac0ccf
3 changed files with 46 additions and 0 deletions

View File

@@ -470,6 +470,11 @@
"togglePanels": {
"title": "Toggle Panels",
"desc": "Show or hide both left and right panels at once."
},
"selectGenerateTab": {
"title": "Select the Generate Tab",
"desc": "Selects the Generate tab.",
"key": "1"
}
},
"canvas": {
@@ -607,6 +612,16 @@
"fitBboxToMasks": {
"title": "Fit Bbox To Masks",
"desc": "Automatically adjust the generation bounding box to fit visible inpaint masks"
},
"applySegmentAnything": {
"title": "Apply Segment Anything",
"desc": "Apply the current Segment Anything mask.",
"key": "enter"
},
"cancelSegmentAnything": {
"title": "Cancel Segment Anything",
"desc": "Cancel the current Segment Anything operation.",
"key": "esc"
}
},
"workflows": {
@@ -736,6 +751,10 @@
"deleteSelection": {
"title": "Delete",
"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."
},
"starImage": {
"title": "Star/Unstar Image",
"desc": "Star or unstar the selected image."
}
}
},

View File

@@ -26,6 +26,8 @@ import type {
import { VirtuosoGrid } from 'react-virtuoso';
import { imagesApi } from 'services/api/endpoints/images';
import { useDebounce } from 'use-debounce';
import { useImageDTO } from 'services/api/endpoints/images';
import { useStarImagesMutation, useUnstarImagesMutation } from 'services/api/endpoints/images';
import { GalleryImage, GalleryImagePlaceholder } from './ImageGrid/GalleryImage';
import { GallerySelectionCountTag } from './ImageGrid/GallerySelectionCountTag';
@@ -464,6 +466,30 @@ export const NewGallery = memo(() => {
enabled: !isLoading,
});
const lastSelectedImage = useAppSelector(selectLastSelectedImage);
const selectionCount = useAppSelector((state) => state.gallery.selection.length);
const isGalleryFocused = getFocusedRegion() === 'gallery';
const imageDTO = useImageDTO(lastSelectedImage);
const [starImages] = useStarImagesMutation();
const [unstarImages] = useUnstarImagesMutation();
const handleStarHotkey = useCallback(() => {
if (!imageDTO) return;
if (imageDTO.starred) {
unstarImages({ image_names: [imageDTO.image_name] });
} else {
starImages({ image_names: [imageDTO.image_name] });
}
}, [imageDTO, starImages, unstarImages]);
useRegisteredHotkeys({
id: 'starImage',
category: 'gallery',
callback: handleStarHotkey,
options: { enabled: !!imageDTO && selectionCount === 1 && isGalleryFocused },
dependencies: [imageDTO, selectionCount, isGalleryFocused, handleStarHotkey],
});
useKeepSelectedImageInView(imageNames, virtuosoRef, rootRef, rangeRef);
useKeyboardNavigation(imageNames, virtuosoRef, rootRef);
const scrollerRef = useScrollableGallery(rootRef);

View File

@@ -160,6 +160,7 @@ export const useHotkeyData = (): HotkeysData => {
addHotkey('gallery', 'galleryNavDownAlt', ['alt+down']);
addHotkey('gallery', 'galleryNavLeftAlt', ['alt+left']);
addHotkey('gallery', 'deleteSelection', ['delete', 'backspace']);
addHotkey('gallery', 'starImage', ['.']);
return data;
}, [isMacOS, isModelManagerEnabled, t]);