Skip to content

Commit

Permalink
feat(send-message): add key binding for shift enter
Browse files Browse the repository at this point in the history
  • Loading branch information
koepferd committed Oct 2, 2024
1 parent 7783381 commit a35855a
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
convertToRaw,
DraftHandleValue,
EditorState,
getDefaultKeyBinding,
RichUtils
} from 'draft-js';
import { draftToMarkdown } from 'markdown-draft-js';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -1026,6 +1039,7 @@ export const MessageSubmitInterfaceComponent = ({
handleKeyCommand={
handleEditorKeyCommand
}
keyBindingFn={handleCustomKeyBinding}
placeholder={
hasRequestFeedbackCheckbox &&
requestFeedbackCheckboxChecked
Expand Down

0 comments on commit a35855a

Please sign in to comment.