mirror of
https://github.com/WenPai-org/wpmind.git
synced 2025-08-07 14:35:18 +08:00
added support for Enter key to insert the response
This commit is contained in:
parent
ce3c6c3184
commit
b08b333ab4
1 changed files with 38 additions and 35 deletions
|
@ -170,12 +170,23 @@ export default function Popup(props) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onInsert() {
|
||||||
|
insertResponse();
|
||||||
|
|
||||||
|
reset();
|
||||||
|
close();
|
||||||
|
|
||||||
|
if (onClose) {
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set focus on Input.
|
// Set focus on Input.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isOpen && ref?.current) {
|
if (isOpen && !loading && ref?.current) {
|
||||||
focusInput();
|
focusInput();
|
||||||
}
|
}
|
||||||
}, [isOpen, ref]);
|
}, [isOpen, loading, ref]);
|
||||||
|
|
||||||
// Open request page if something is in input.
|
// Open request page if something is in input.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -184,6 +195,25 @@ export default function Popup(props) {
|
||||||
}
|
}
|
||||||
}, [screen, input, setScreen]);
|
}, [screen, input, setScreen]);
|
||||||
|
|
||||||
|
function onKeyDown(e) {
|
||||||
|
// Go back to starter screen.
|
||||||
|
if (screen !== '' && e.key === 'Backspace' && !e.target.value) {
|
||||||
|
reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert request to post.
|
||||||
|
if (response && e.key === 'Enter') {
|
||||||
|
onInsert();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send request to AI.
|
||||||
|
if (screen === 'request' && e.key === 'Enter') {
|
||||||
|
requestAI();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -214,22 +244,7 @@ export default function Popup(props) {
|
||||||
onChange={(val) => {
|
onChange={(val) => {
|
||||||
setInput(val);
|
setInput(val);
|
||||||
}}
|
}}
|
||||||
onKeyDown={(e) => {
|
onKeyDown={onKeyDown}
|
||||||
// Go back to starter screen.
|
|
||||||
if (
|
|
||||||
screen !== '' &&
|
|
||||||
e.key === 'Backspace' &&
|
|
||||||
!e.target.value
|
|
||||||
) {
|
|
||||||
reset();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send request to AI.
|
|
||||||
if (screen === 'request' && e.key === 'Enter') {
|
|
||||||
requestAI();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
/>
|
/>
|
||||||
{contextLabel ? (
|
{contextLabel ? (
|
||||||
|
@ -263,7 +278,6 @@ export default function Popup(props) {
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setInput(data.request);
|
setInput(data.request);
|
||||||
setScreen('request');
|
setScreen('request');
|
||||||
focusInput();
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{data.icon || ''}
|
{data.icon || ''}
|
||||||
|
@ -304,17 +318,11 @@ export default function Popup(props) {
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
insertResponse();
|
setError('');
|
||||||
|
requestAI();
|
||||||
reset();
|
|
||||||
close();
|
|
||||||
|
|
||||||
if (onClose) {
|
|
||||||
onClose();
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{__('Insert', 'mind')} <kbd>⏎</kbd>
|
{__('Regenerate', 'mind')} <kbd>↻</kbd>
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
@ -330,13 +338,8 @@ export default function Popup(props) {
|
||||||
>
|
>
|
||||||
{__('Copy', 'mind')}
|
{__('Copy', 'mind')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button onClick={onInsert}>
|
||||||
onClick={() => {
|
{__('Insert', 'mind')} <kbd>⏎</kbd>
|
||||||
setError('');
|
|
||||||
requestAI();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{__('Regenerate', 'mind')} <kbd>↻</kbd>
|
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue