From 143762fbee8d4b02db11c35e26a35192e248c9a7 Mon Sep 17 00:00:00 2001 From: Jing Hua Date: Sat, 4 Mar 2023 13:54:28 +0800 Subject: [PATCH] feat: ctrl/shift + enter to save and submit --- .../Chat/ChatContent/Message/MessageContent.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/Chat/ChatContent/Message/MessageContent.tsx b/src/components/Chat/ChatContent/Message/MessageContent.tsx index 67c2d81..93e76bb 100644 --- a/src/components/Chat/ChatContent/Message/MessageContent.tsx +++ b/src/components/Chat/ChatContent/Message/MessageContent.tsx @@ -292,6 +292,14 @@ const EditView = ({ } }; + const handleKeyDown = (e: React.KeyboardEvent) => { + 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} >