mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): fix canvas space hotkey
Need to do some checks to ensure we aren't taking over input elements, and are focused on the canvas. Closes #5478
This commit is contained in:
parent
a24e63d440
commit
ad7139829c
7
invokeai/frontend/web/src/common/util/isInputElement.ts
Normal file
7
invokeai/frontend/web/src/common/util/isInputElement.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export const isInputElement = (el: HTMLElement) => {
|
||||||
|
return (
|
||||||
|
el.tagName.toLowerCase() === 'input' ||
|
||||||
|
el.tagName.toLowerCase() === 'textarea' ||
|
||||||
|
el.tagName.toLowerCase() === 'select'
|
||||||
|
);
|
||||||
|
};
|
@ -1,4 +1,5 @@
|
|||||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
|
import { isInputElement } from 'common/util/isInputElement';
|
||||||
import {
|
import {
|
||||||
$canvasStage,
|
$canvasStage,
|
||||||
$tool,
|
$tool,
|
||||||
@ -13,6 +14,7 @@ import {
|
|||||||
setShouldShowBoundingBox,
|
setShouldShowBoundingBox,
|
||||||
setShouldSnapToGrid,
|
setShouldSnapToGrid,
|
||||||
} from 'features/canvas/store/canvasSlice';
|
} from 'features/canvas/store/canvasSlice';
|
||||||
|
import { isElChildOfCanvasTab } from 'features/canvas/util/isElChildOfCanvasTab';
|
||||||
import { activeTabNameSelector } from 'features/ui/store/uiSelectors';
|
import { activeTabNameSelector } from 'features/ui/store/uiSelectors';
|
||||||
import { useCallback, useEffect } from 'react';
|
import { useCallback, useEffect } from 'react';
|
||||||
import { useHotkeys } from 'react-hotkeys-hook';
|
import { useHotkeys } from 'react-hotkeys-hook';
|
||||||
@ -93,16 +95,13 @@ const useInpaintingCanvasHotkeys = () => {
|
|||||||
[activeTabName, shouldShowBoundingBox]
|
[activeTabName, shouldShowBoundingBox]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
window.addEventListener('keydown', (e) => {
|
|
||||||
if (e.key === ' ' && !e.repeat) {
|
|
||||||
console.log('spaceeee');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const onKeyDown = useCallback((e: KeyboardEvent) => {
|
const onKeyDown = useCallback((e: KeyboardEvent) => {
|
||||||
if (e.repeat || e.key !== ' ') {
|
if (
|
||||||
|
e.repeat ||
|
||||||
|
e.key !== ' ' ||
|
||||||
|
isInputElement(e.target as HTMLElement) ||
|
||||||
|
!isElChildOfCanvasTab(e.target as HTMLElement)
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($toolStash.get() || $tool.get() === 'move') {
|
if ($toolStash.get() || $tool.get() === 'move') {
|
||||||
@ -114,7 +113,12 @@ const useInpaintingCanvasHotkeys = () => {
|
|||||||
resetToolInteractionState();
|
resetToolInteractionState();
|
||||||
}, []);
|
}, []);
|
||||||
const onKeyUp = useCallback((e: KeyboardEvent) => {
|
const onKeyUp = useCallback((e: KeyboardEvent) => {
|
||||||
if (e.repeat || e.key !== ' ') {
|
if (
|
||||||
|
e.repeat ||
|
||||||
|
e.key !== ' ' ||
|
||||||
|
isInputElement(e.target as HTMLElement) ||
|
||||||
|
!isElChildOfCanvasTab(e.target as HTMLElement)
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!$toolStash.get() || $tool.get() !== 'move') {
|
if (!$toolStash.get() || $tool.get() !== 'move') {
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
export const CANVAS_GRID_SIZE_COARSE = 64;
|
export const CANVAS_GRID_SIZE_COARSE = 64;
|
||||||
export const CANVAS_GRID_SIZE_FINE = 8;
|
export const CANVAS_GRID_SIZE_FINE = 8;
|
||||||
|
export const CANVAS_TAB_TESTID = 'unified-canvas-tab';
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
import { CANVAS_TAB_TESTID } from 'features/canvas/store/constants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if an element is a child of the canvas tab. Uses the canvas data-testid,
|
||||||
|
* actually checking against the *parent* of that element, which is the canvas's
|
||||||
|
* panel from `react-resizable-panels`. This panel element has dynamic children, so
|
||||||
|
* it's safer to check the canvas tab and grab its parent.
|
||||||
|
*/
|
||||||
|
export const isElChildOfCanvasTab = (el: HTMLElement) => {
|
||||||
|
const canvasContainerEl = document.querySelector(
|
||||||
|
`[data-testid="${CANVAS_TAB_TESTID}"]`
|
||||||
|
);
|
||||||
|
return Boolean(canvasContainerEl?.parentElement?.contains(el));
|
||||||
|
};
|
@ -2,6 +2,7 @@ import { Flex } from '@chakra-ui/react';
|
|||||||
import IAIDropOverlay from 'common/components/IAIDropOverlay';
|
import IAIDropOverlay from 'common/components/IAIDropOverlay';
|
||||||
import IAICanvas from 'features/canvas/components/IAICanvas';
|
import IAICanvas from 'features/canvas/components/IAICanvas';
|
||||||
import IAICanvasToolbar from 'features/canvas/components/IAICanvasToolbar/IAICanvasToolbar';
|
import IAICanvasToolbar from 'features/canvas/components/IAICanvasToolbar/IAICanvasToolbar';
|
||||||
|
import { CANVAS_TAB_TESTID } from 'features/canvas/store/constants';
|
||||||
import { useDroppableTypesafe } from 'features/dnd/hooks/typesafeHooks';
|
import { useDroppableTypesafe } from 'features/dnd/hooks/typesafeHooks';
|
||||||
import type { CanvasInitialImageDropData } from 'features/dnd/types';
|
import type { CanvasInitialImageDropData } from 'features/dnd/types';
|
||||||
import { isValidDrop } from 'features/dnd/util/isValidDrop';
|
import { isValidDrop } from 'features/dnd/util/isValidDrop';
|
||||||
@ -28,7 +29,6 @@ const UnifiedCanvasTab = () => {
|
|||||||
<Flex
|
<Flex
|
||||||
layerStyle="first"
|
layerStyle="first"
|
||||||
ref={setDroppableRef}
|
ref={setDroppableRef}
|
||||||
tabIndex={-1}
|
|
||||||
flexDirection="column"
|
flexDirection="column"
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
gap={4}
|
gap={4}
|
||||||
@ -36,6 +36,7 @@ const UnifiedCanvasTab = () => {
|
|||||||
borderRadius="base"
|
borderRadius="base"
|
||||||
w="full"
|
w="full"
|
||||||
h="full"
|
h="full"
|
||||||
|
data-testid={CANVAS_TAB_TESTID}
|
||||||
>
|
>
|
||||||
<IAICanvasToolbar />
|
<IAICanvasToolbar />
|
||||||
<IAICanvas />
|
<IAICanvas />
|
||||||
|
Loading…
Reference in New Issue
Block a user