mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-02-16 07:35:24 -05:00
The shift key listener didn't catch pressed when focused in a textarea or input field, causing jank on slider number inputs. Add keydown and keyup listeners to all such fields, which ensures that the `shift` state is always correct. Also add the action tracking it to `actionsDenylist` to not clutter up devtools.
39 lines
1006 B
TypeScript
39 lines
1006 B
TypeScript
import { Textarea, TextareaProps, forwardRef } from '@chakra-ui/react';
|
|
import { useAppDispatch } from 'app/store/storeHooks';
|
|
import { stopPastePropagation } from 'common/util/stopPastePropagation';
|
|
import { shiftKeyPressed } from 'features/ui/store/hotkeysSlice';
|
|
import { KeyboardEvent, memo, useCallback } from 'react';
|
|
|
|
const IAITextarea = forwardRef((props: TextareaProps, ref) => {
|
|
const dispatch = useAppDispatch();
|
|
const handleKeyDown = useCallback(
|
|
(e: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
if (e.shiftKey) {
|
|
dispatch(shiftKeyPressed(true));
|
|
}
|
|
},
|
|
[dispatch]
|
|
);
|
|
|
|
const handleKeyUp = useCallback(
|
|
(e: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
if (!e.shiftKey) {
|
|
dispatch(shiftKeyPressed(false));
|
|
}
|
|
},
|
|
[dispatch]
|
|
);
|
|
|
|
return (
|
|
<Textarea
|
|
ref={ref}
|
|
onPaste={stopPastePropagation}
|
|
onKeyDown={handleKeyDown}
|
|
onKeyUp={handleKeyUp}
|
|
{...props}
|
|
/>
|
|
);
|
|
});
|
|
|
|
export default memo(IAITextarea);
|