mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-29 10:44:00 +01:00
feat: ctrl/shift + enter to save and submit
This commit is contained in:
parent
fb910d0a52
commit
143762fbee
|
@ -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 = () => {
|
||||
if (_content === '') return;
|
||||
const updatedMessages: MessageInterface[] = JSON.parse(
|
||||
|
@ -310,6 +318,7 @@ const EditView = ({
|
|||
// only for sticky forms
|
||||
const { handleSubmit } = useSubmit();
|
||||
const handleSaveAndSubmit = () => {
|
||||
if (!sticky) return;
|
||||
if (_content == '') return;
|
||||
const updatedMessages: MessageInterface[] = JSON.parse(
|
||||
JSON.stringify(messages)
|
||||
|
@ -339,6 +348,7 @@ const EditView = ({
|
|||
}}
|
||||
value={_content}
|
||||
onInput={handleInput}
|
||||
onKeyDown={handleKeyDown}
|
||||
rows={1}
|
||||
></textarea>
|
||||
<div className='text-center mt-2 flex justify-center'>
|
||||
|
|
Loading…
Reference in a new issue