From a35855a38a73e8252e2d4870417831ac326af3e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deborah=20K=C3=B6pfer?= Date: Wed, 2 Oct 2024 17:27:54 +0200 Subject: [PATCH] feat(send-message): add key binding for shift enter --- .../messageSubmitInterfaceComponent.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/components/messageSubmitInterface/messageSubmitInterfaceComponent.tsx b/src/components/messageSubmitInterface/messageSubmitInterfaceComponent.tsx index 3cde178c6..a87a56e68 100644 --- a/src/components/messageSubmitInterface/messageSubmitInterfaceComponent.tsx +++ b/src/components/messageSubmitInterface/messageSubmitInterfaceComponent.tsx @@ -44,6 +44,7 @@ import { convertToRaw, DraftHandleValue, EditorState, + getDefaultKeyBinding, RichUtils } from 'draft-js'; import { draftToMarkdown } from 'markdown-draft-js'; @@ -404,9 +405,21 @@ export const MessageSubmitInterfaceComponent = ({ ] ); + const handleCustomKeyBinding = (event) => { + if (event.key === 'Enter' && event.shiftKey) { + return 'shift-enter'; + } + return getDefaultKeyBinding(event); + }; + const handleEditorKeyCommand = useCallback( (command) => { const newState = RichUtils.handleKeyCommand(editorState, command); + if (command === 'shift-enter') { + handleButtonClick(); + return 'handled'; + } + if (newState) { handleEditorChange(newState); return 'handled'; @@ -1026,6 +1039,7 @@ export const MessageSubmitInterfaceComponent = ({ handleKeyCommand={ handleEditorKeyCommand } + keyBindingFn={handleCustomKeyBinding} placeholder={ hasRequestFeedbackCheckbox && requestFeedbackCheckboxChecked