Skip to content

Commit

Permalink
add option to use enter for newline
Browse files Browse the repository at this point in the history
  • Loading branch information
ajbura committed Oct 17, 2023
1 parent 320c202 commit 1c5275e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/app/organisms/room/RoomInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ interface RoomInputProps {
export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
({ editor, roomViewRef, roomId, room }, ref) => {
const mx = useMatrixClient();
const [enterForNewline] = useSetting(settingsAtom, 'enterForNewline');
const [isMarkdown] = useSetting(settingsAtom, 'isMarkdown');
const commands = useCommands(mx, room);

Expand Down Expand Up @@ -323,7 +324,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(

const handleKeyDown: KeyboardEventHandler = useCallback(
(evt) => {
if (isHotkey('enter', evt)) {
if (enterForNewline ? isHotkey('shift+enter', evt) : isHotkey('enter', evt)) {
evt.preventDefault();
submit();
}
Expand All @@ -332,7 +333,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
setReplyDraft();
}
},
[submit, setReplyDraft]
[submit, setReplyDraft, enterForNewline]
);

const handleKeyUp: KeyboardEventHandler = useCallback(
Expand Down
5 changes: 3 additions & 2 deletions src/app/organisms/room/message/MessageEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand All @@ -128,7 +129,7 @@ export const MessageEditor = as<'div', MessageEditorProps>(
onCancel();
}
},
[onCancel, handleSave]
[onCancel, handleSave, enterForNewline]
);

const handleKeyUp: KeyboardEventHandler = useCallback(
Expand Down
11 changes: 11 additions & 0 deletions src/app/organisms/settings/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -138,6 +139,16 @@ function AppearanceSection() {
/>
}
/>
<SettingTile
title="Use ENTER for Newline"
options={(
<Toggle
isActive={enterForNewline}
onToggle={() => setEnterForNewline(!enterForNewline) }
/>
)}
content={<Text variant="b3">Use SHIFT + ENTER to send message and ENTER for newline.</Text>}
/>
<SettingTile
title="Inline Markdown formatting"
options={(
Expand Down
2 changes: 2 additions & 0 deletions src/app/state/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface Settings {
isPeopleDrawer: boolean;
useSystemEmoji: boolean;

enterForNewline: boolean;
messageLayout: MessageLayout;
messageSpacing: MessageSpacing;
hideMembershipEvents: boolean;
Expand All @@ -30,6 +31,7 @@ const defaultSettings: Settings = {
isPeopleDrawer: true,
useSystemEmoji: false,

enterForNewline: false,
messageLayout: 0,
messageSpacing: '400',
hideMembershipEvents: false,
Expand Down

0 comments on commit 1c5275e

Please sign in to comment.