Adds hotkey to reset canvas interaction state

If the canvas' interaction state (e.g. isMovingBoundingBox, isDrawing, etc) get stuck somehow, user can press Escape to reset the state.
This commit is contained in:
psychedelicious 2022-11-20 11:26:40 +11:00 committed by blessedcoolant
parent 9d34213b4c
commit d4376ed240
4 changed files with 31 additions and 4 deletions

View File

@ -3,6 +3,7 @@ import _ from 'lodash';
import { useHotkeys } from 'react-hotkeys-hook';
import { activeTabNameSelector } from 'features/options/store/optionsSelectors';
import {
resetCanvasInteractionState,
setShouldShowBoundingBox,
setTool,
} from 'features/canvas/store/canvasSlice';
@ -46,6 +47,17 @@ const useInpaintingCanvasHotkeys = () => {
const canvasStage = getCanvasStage();
useHotkeys(
'esc',
() => {
dispatch(resetCanvasInteractionState());
},
{
enabled: () => true,
preventDefault: true,
}
);
useHotkeys(
'shift+h',
() => {

View File

@ -675,6 +675,16 @@ export const canvasSlice = createSlice({
state.layerState.objects = [action.payload];
},
resetCanvasInteractionState: (state) => {
state.cursorPosition = null;
state.isDrawing = false;
state.isMouseOverBoundingBox = false;
state.isMoveBoundingBoxKeyHeld = false;
state.isMoveStageKeyHeld = false;
state.isMovingBoundingBox = false;
state.isMovingStage = false;
state.isTransformingBoundingBox = false;
},
},
});
@ -690,6 +700,7 @@ export const {
prevStagingAreaImage,
redo,
resetCanvas,
resetCanvasInteractionState,
resetCanvasView,
resizeAndScaleCanvas,
resizeCanvas,

View File

@ -192,9 +192,11 @@ export default function ImageGallery() {
useHotkeys(
'esc',
() => {
if (shouldPinGallery) return;
dispatch(setShouldShowGallery(false));
dispatch(setDoesCanvasNeedScaling(true));
},
{
enabled: () => !shouldPinGallery,
preventDefault: true,
},
[shouldPinGallery]
);

View File

@ -72,9 +72,11 @@ const InvokeOptionsPanel = (props: Props) => {
useHotkeys(
'esc',
() => {
if (shouldPinOptionsPanel) return;
dispatch(setShouldShowOptionsPanel(false));
dispatch(setDoesCanvasNeedScaling(true));
},
{
enabled: () => !shouldPinOptionsPanel,
preventDefault: true,
},
[shouldPinOptionsPanel]
);