Skip to content

Commit 7153d84

Browse files
feat(ui): add hotkey to cycle compare modes
1 parent 9a0b77a commit 7153d84

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

invokeai/frontend/web/src/features/gallery/components/ImageViewer/CompareToolbar.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
comparedImagesSwapped,
55
comparisonFitChanged,
66
comparisonModeChanged,
7+
comparisonModeCycled,
78
imageToCompareChanged,
89
} from 'features/gallery/store/gallerySlice';
910
import { memo, useCallback } from 'react';
@@ -36,6 +37,10 @@ export const CompareToolbar = memo(() => {
3637
dispatch(imageToCompareChanged(null));
3738
}, [dispatch]);
3839
useHotkeys('esc', exitCompare, [exitCompare]);
40+
const nextMode = useCallback(() => {
41+
dispatch(comparisonModeCycled());
42+
}, [dispatch]);
43+
useHotkeys('m', nextMode, [nextMode]);
3944

4045
return (
4146
<Flex w="full" gap={2}>

invokeai/frontend/web/src/features/gallery/store/gallerySlice.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ export const gallerySlice = createSlice({
4646
comparisonModeChanged: (state, action: PayloadAction<ComparisonMode>) => {
4747
state.comparisonMode = action.payload;
4848
},
49+
comparisonModeCycled: (state) => {
50+
switch (state.comparisonMode) {
51+
case 'slider':
52+
state.comparisonMode = 'side-by-side';
53+
break;
54+
case 'side-by-side':
55+
state.comparisonMode = 'hover';
56+
break;
57+
case 'hover':
58+
state.comparisonMode = 'slider';
59+
break;
60+
}
61+
},
4962
shouldAutoSwitchChanged: (state, action: PayloadAction<boolean>) => {
5063
state.shouldAutoSwitch = action.payload;
5164
},
@@ -143,6 +156,7 @@ export const {
143156
comparisonModeChanged,
144157
comparedImagesSwapped,
145158
comparisonFitChanged,
159+
comparisonModeCycled,
146160
} = gallerySlice.actions;
147161

148162
const isAnyBoardDeleted = isAnyOf(

0 commit comments

Comments
 (0)