mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
focus on prompt textarea when exiting view mode by clicking
This commit is contained in:
parent
4952eada87
commit
587f59b25b
@ -24,18 +24,25 @@ export const ParamNegativePrompt = memo(() => {
|
|||||||
},
|
},
|
||||||
[dispatch]
|
[dispatch]
|
||||||
);
|
);
|
||||||
const { onChange, isOpen, onClose, onOpen, onSelect, onKeyDown } = usePrompt({
|
const { onChange, isOpen, onClose, onOpen, onSelect, onKeyDown, onFocusCursorAtEnd } = usePrompt({
|
||||||
prompt,
|
prompt,
|
||||||
textareaRef,
|
textareaRef,
|
||||||
onChange: _onChange,
|
onChange: _onChange,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleFocus = useCallback(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
onFocusCursorAtEnd();
|
||||||
|
}, 500);
|
||||||
|
}, [onFocusCursorAtEnd]);
|
||||||
|
|
||||||
if (viewMode) {
|
if (viewMode) {
|
||||||
return (
|
return (
|
||||||
<ViewModePrompt
|
<ViewModePrompt
|
||||||
prompt={prompt}
|
prompt={prompt}
|
||||||
presetPrompt={activeStylePreset?.preset_data.negative_prompt || ''}
|
presetPrompt={activeStylePreset?.preset_data.negative_prompt || ''}
|
||||||
height={DEFAULT_HEIGHT}
|
height={DEFAULT_HEIGHT}
|
||||||
|
onExit={handleFocus}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -30,12 +30,18 @@ export const ParamPositivePrompt = memo(() => {
|
|||||||
},
|
},
|
||||||
[dispatch]
|
[dispatch]
|
||||||
);
|
);
|
||||||
const { onChange, isOpen, onClose, onOpen, onSelect, onKeyDown, onFocus } = usePrompt({
|
const { onChange, isOpen, onClose, onOpen, onSelect, onKeyDown, onFocus, onFocusCursorAtEnd } = usePrompt({
|
||||||
prompt,
|
prompt,
|
||||||
textareaRef: textareaRef,
|
textareaRef: textareaRef,
|
||||||
onChange: handleChange,
|
onChange: handleChange,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleFocus = useCallback(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
onFocusCursorAtEnd();
|
||||||
|
}, 500);
|
||||||
|
}, [onFocusCursorAtEnd]);
|
||||||
|
|
||||||
const focus: HotkeyCallback = useCallback(
|
const focus: HotkeyCallback = useCallback(
|
||||||
(e) => {
|
(e) => {
|
||||||
onFocus();
|
onFocus();
|
||||||
@ -52,6 +58,7 @@ export const ParamPositivePrompt = memo(() => {
|
|||||||
prompt={prompt}
|
prompt={prompt}
|
||||||
presetPrompt={activeStylePreset?.preset_data.positive_prompt || ''}
|
presetPrompt={activeStylePreset?.preset_data.positive_prompt || ''}
|
||||||
height={DEFAULT_HEIGHT}
|
height={DEFAULT_HEIGHT}
|
||||||
|
onExit={handleFocus}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,12 @@ export const ViewModePrompt = ({
|
|||||||
presetPrompt,
|
presetPrompt,
|
||||||
prompt,
|
prompt,
|
||||||
height,
|
height,
|
||||||
|
onExit,
|
||||||
}: {
|
}: {
|
||||||
presetPrompt: string;
|
presetPrompt: string;
|
||||||
prompt: string;
|
prompt: string;
|
||||||
height: number;
|
height: number;
|
||||||
|
onExit: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@ -24,7 +26,8 @@ export const ViewModePrompt = ({
|
|||||||
|
|
||||||
const handleExitViewMode = useCallback(() => {
|
const handleExitViewMode = useCallback(() => {
|
||||||
dispatch(viewModeChanged(false));
|
dispatch(viewModeChanged(false));
|
||||||
}, [dispatch]);
|
onExit();
|
||||||
|
}, [dispatch, onExit]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
@ -42,7 +45,7 @@ export const ViewModePrompt = ({
|
|||||||
{presetChunks.map((chunk, index) => {
|
{presetChunks.map((chunk, index) => {
|
||||||
return (
|
return (
|
||||||
chunk && (
|
chunk && (
|
||||||
<Text as="span" color={index === 1 ? 'white' : 'base.300'}>
|
<Text as="span" color={index === 1 ? 'white' : 'base.300'} key={index}>
|
||||||
{chunk.trim()}{' '}
|
{chunk.trim()}{' '}
|
||||||
</Text>
|
</Text>
|
||||||
)
|
)
|
||||||
|
@ -58,6 +58,13 @@ export const usePrompt = ({ prompt, textareaRef, onChange: _onChange }: UseInser
|
|||||||
textareaRef.current?.focus();
|
textareaRef.current?.focus();
|
||||||
}, [textareaRef]);
|
}, [textareaRef]);
|
||||||
|
|
||||||
|
const onFocusCursorAtEnd = useCallback(() => {
|
||||||
|
onFocus();
|
||||||
|
if (textareaRef.current) {
|
||||||
|
textareaRef.current.setSelectionRange(prompt.length, prompt.length);
|
||||||
|
}
|
||||||
|
}, [onFocus, textareaRef, prompt]);
|
||||||
|
|
||||||
const handleClosePopover = useCallback(() => {
|
const handleClosePopover = useCallback(() => {
|
||||||
onClose();
|
onClose();
|
||||||
onFocus();
|
onFocus();
|
||||||
@ -89,5 +96,6 @@ export const usePrompt = ({ prompt, textareaRef, onChange: _onChange }: UseInser
|
|||||||
onSelect,
|
onSelect,
|
||||||
onKeyDown,
|
onKeyDown,
|
||||||
onFocus,
|
onFocus,
|
||||||
|
onFocusCursorAtEnd,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user