add ctrl+enter to reply and post form

This commit is contained in:
hzrd149 2023-12-07 10:08:15 -06:00
parent 3939443336
commit 4167406d42
2 changed files with 11 additions and 1 deletions

View File

@ -158,6 +158,8 @@ export default function PostModal({
</>
);
}
// TODO: wrap this in a form
return (
<>
{requireSubject && <Input {...register("subject", { required: true })} isRequired placeholder="Subject" />}
@ -170,6 +172,9 @@ export default function PostModal({
isRequired
instanceRef={(inst) => (textAreaRef.current = inst)}
onPaste={onPaste}
onKeyDown={(e) => {
if (e.ctrlKey && e.key === "Enter") submit();
}}
/>
{getValues().content.length > 0 && (
<Box>

View File

@ -95,8 +95,10 @@ export default function ReplyForm({ item, onCancel, onSubmitted, replyKind = Kin
}
});
const formRef = useRef<HTMLFormElement | null>(null);
return (
<Flex as="form" direction="column" gap="2" pb="4" onSubmit={submit}>
<Flex as="form" direction="column" gap="2" pb="4" onSubmit={submit} ref={formRef}>
<MagicTextArea
placeholder="Reply"
autoFocus
@ -110,6 +112,9 @@ export default function ReplyForm({ item, onCancel, onSubmitted, replyKind = Kin
const imageFile = Array.from(e.clipboardData.files).find((f) => f.type.includes("image"));
if (imageFile) uploadImage(imageFile);
}}
onKeyDown={(e) => {
if (e.ctrlKey && e.key === "Enter" && formRef.current) formRef.current.requestSubmit();
}}
/>
<Flex gap="2" alignItems="center">
<VisuallyHiddenInput