From 1c5275e72651ecf5a9ebb485a7a85c024d096df6 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Tue, 17 Oct 2023 20:07:57 +0530 Subject: [PATCH] add option to use enter for newline --- src/app/organisms/room/RoomInput.tsx | 5 +++-- src/app/organisms/room/message/MessageEditor.tsx | 5 +++-- src/app/organisms/settings/Settings.jsx | 11 +++++++++++ src/app/state/settings.ts | 2 ++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/app/organisms/room/RoomInput.tsx b/src/app/organisms/room/RoomInput.tsx index 6efbcfd188..3447a01e90 100644 --- a/src/app/organisms/room/RoomInput.tsx +++ b/src/app/organisms/room/RoomInput.tsx @@ -120,6 +120,7 @@ interface RoomInputProps { export const RoomInput = forwardRef( ({ editor, roomViewRef, roomId, room }, ref) => { const mx = useMatrixClient(); + const [enterForNewline] = useSetting(settingsAtom, 'enterForNewline'); const [isMarkdown] = useSetting(settingsAtom, 'isMarkdown'); const commands = useCommands(mx, room); @@ -323,7 +324,7 @@ export const RoomInput = forwardRef( const handleKeyDown: KeyboardEventHandler = useCallback( (evt) => { - if (isHotkey('enter', evt)) { + if (enterForNewline ? isHotkey('shift+enter', evt) : isHotkey('enter', evt)) { evt.preventDefault(); submit(); } @@ -332,7 +333,7 @@ export const RoomInput = forwardRef( setReplyDraft(); } }, - [submit, setReplyDraft] + [submit, setReplyDraft, enterForNewline] ); const handleKeyUp: KeyboardEventHandler = useCallback( diff --git a/src/app/organisms/room/message/MessageEditor.tsx b/src/app/organisms/room/message/MessageEditor.tsx index e0265c36fc..6d1c492863 100644 --- a/src/app/organisms/room/message/MessageEditor.tsx +++ b/src/app/organisms/room/message/MessageEditor.tsx @@ -45,6 +45,7 @@ export const MessageEditor = as<'div', MessageEditorProps>( ({ room, roomId, mEvent, imagePackRooms, onCancel, ...props }, ref) => { const mx = useMatrixClient(); const editor = useEditor(); + const [enterForNewline] = useSetting(settingsAtom, 'enterForNewline'); const [globalToolbar] = useSetting(settingsAtom, 'editorToolbar'); const [isMarkdown] = useSetting(settingsAtom, 'isMarkdown'); const [toolbar, setToolbar] = useState(globalToolbar); @@ -119,7 +120,7 @@ export const MessageEditor = as<'div', MessageEditorProps>( const handleKeyDown: KeyboardEventHandler = useCallback( (evt) => { - if (isHotkey('enter', evt)) { + if (enterForNewline ? isHotkey('shift+enter', evt) : isHotkey('enter', evt)) { evt.preventDefault(); handleSave(); } @@ -128,7 +129,7 @@ export const MessageEditor = as<'div', MessageEditorProps>( onCancel(); } }, - [onCancel, handleSave] + [onCancel, handleSave, enterForNewline] ); const handleKeyUp: KeyboardEventHandler = useCallback( diff --git a/src/app/organisms/settings/Settings.jsx b/src/app/organisms/settings/Settings.jsx index bd9ce0441c..962a80b663 100644 --- a/src/app/organisms/settings/Settings.jsx +++ b/src/app/organisms/settings/Settings.jsx @@ -49,6 +49,7 @@ import { settingsAtom } from '../../state/settings'; function AppearanceSection() { const [, updateState] = useState({}); + const [enterForNewline, setEnterForNewline] = useSetting(settingsAtom, 'enterForNewline'); const [messageLayout, setMessageLayout] = useSetting(settingsAtom, 'messageLayout'); const [messageSpacing, setMessageSpacing] = useSetting(settingsAtom, 'messageSpacing'); const [useSystemEmoji, setUseSystemEmoji] = useSetting(settingsAtom, 'useSystemEmoji'); @@ -138,6 +139,16 @@ function AppearanceSection() { /> } /> + setEnterForNewline(!enterForNewline) } + /> + )} + content={Use SHIFT + ENTER to send message and ENTER for newline.} + />