feat: ctrl/shift + enter to save and submit

This commit is contained in:
Jing Hua 2023-03-04 13:54:28 +08:00
parent fb910d0a52
commit 143762fbee

View file

@ -292,6 +292,14 @@ const EditView = ({
} }
}; };
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if ((e.ctrlKey || e.shiftKey) && e.key === 'Enter') {
e.preventDefault();
if (sticky) handleSaveAndSubmit();
else handleSave();
}
};
const handleSave = () => { const handleSave = () => {
if (_content === '') return; if (_content === '') return;
const updatedMessages: MessageInterface[] = JSON.parse( const updatedMessages: MessageInterface[] = JSON.parse(
@ -310,6 +318,7 @@ const EditView = ({
// only for sticky forms // only for sticky forms
const { handleSubmit } = useSubmit(); const { handleSubmit } = useSubmit();
const handleSaveAndSubmit = () => { const handleSaveAndSubmit = () => {
if (!sticky) return;
if (_content == '') return; if (_content == '') return;
const updatedMessages: MessageInterface[] = JSON.parse( const updatedMessages: MessageInterface[] = JSON.parse(
JSON.stringify(messages) JSON.stringify(messages)
@ -339,6 +348,7 @@ const EditView = ({
}} }}
value={_content} value={_content}
onInput={handleInput} onInput={handleInput}
onKeyDown={handleKeyDown}
rows={1} rows={1}
></textarea> ></textarea>
<div className='text-center mt-2 flex justify-center'> <div className='text-center mt-2 flex justify-center'>