From 3c42d0a9f6e618f845e61ba3991dc96c97335bcc Mon Sep 17 00:00:00 2001 From: Anders Haglund Date: Thu, 24 Nov 2022 19:00:24 -0800 Subject: [PATCH] Update SidePanel.tsx Add shortcut to trigger inpainting from negative prompt text box by pressing ctrl/meta+enter --- .../src/components/SidePanel/SidePanel.tsx | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lama_cleaner/app/src/components/SidePanel/SidePanel.tsx b/lama_cleaner/app/src/components/SidePanel/SidePanel.tsx index ca6dc43..30cc13e 100644 --- a/lama_cleaner/app/src/components/SidePanel/SidePanel.tsx +++ b/lama_cleaner/app/src/components/SidePanel/SidePanel.tsx @@ -1,13 +1,20 @@ import React, { FormEvent, useState } from 'react' -import { useRecoilState } from 'recoil' +import { useRecoilState, useRecoilValue } from 'recoil' import * as PopoverPrimitive from '@radix-ui/react-popover' import { useToggle } from 'react-use' -import { negativePropmtState, SDSampler, settingState } from '../../store/Atoms' +import { + isInpaintingState, + negativePropmtState, + propmtState, + SDSampler, + settingState, +} from '../../store/Atoms' import NumberInputSetting from '../Settings/NumberInputSetting' import SettingBlock from '../Settings/SettingBlock' import Selector from '../shared/Selector' import { Switch, SwitchThumb } from '../shared/Switch' import TextAreaInput from '../shared/Textarea' +import emitter, { EVENT_PROMPT } from '../../event' const INPUT_WIDTH = 30 @@ -17,6 +24,8 @@ const SidePanel = () => { const [setting, setSettingState] = useRecoilState(settingState) const [negativePrompt, setNegativePrompt] = useRecoilState(negativePropmtState) + const isInpainting = useRecoilValue(isInpaintingState) + const prompt = useRecoilValue(propmtState) const handleOnInput = (evt: FormEvent) => { evt.preventDefault() @@ -25,6 +34,17 @@ const SidePanel = () => { setNegativePrompt(target.value) } + const onKeyUp = (e: React.KeyboardEvent) => { + if ( + e.key === 'Enter' && + (e.ctrlKey || e.metaKey) && + prompt.length !== 0 && + !isInpainting + ) { + emitter.emit(EVENT_PROMPT) + } + } + return (
@@ -203,6 +223,7 @@ const SidePanel = () => { className="negative-prompt" value={negativePrompt} onInput={handleOnInput} + onKeyUp={onKeyUp} placeholder="" /> }