feat: Allow enter to break line in settings
https://github.com/oxen-io/session-desktop/issues/1486
This commit is contained in:
parent
83079a8b4c
commit
8f2a41bc13
|
@ -410,6 +410,10 @@
|
|||
"open": "Open",
|
||||
"audioMessageAutoplayTitle": "Autoplay Audio Messages",
|
||||
"audioMessageAutoplayDescription": "Autoplay consecutive audio messages.",
|
||||
"enterKeySettingTitle": "Enter Key",
|
||||
"enterKeySettingDescription": "Function of the enter key when typing in a conversation.",
|
||||
"enterSendNewMessageDescription": "ENTER sends a message, SHIFT + ENTER starts a new line",
|
||||
"enterNewLineDescription": "SHIFT + ENTER sends a message, ENTER starts a new line",
|
||||
"clickToTrustContact": "Click to download media",
|
||||
"trustThisContactDialogTitle": "Trust $name$?",
|
||||
"trustThisContactDialogDescription": "Are you sure you want to download media sent by $name$?",
|
||||
|
|
|
@ -832,8 +832,19 @@ class CompositionBoxInner extends React.Component<Props, State> {
|
|||
}
|
||||
|
||||
private async onKeyDown(event: any) {
|
||||
if (event.key === 'Enter' && !event.shiftKey && !event.nativeEvent.isComposing) {
|
||||
// If shift, newline. If in IME composing mode, leave it to IME. Else send message.
|
||||
const isEnter = event.key === 'Enter';
|
||||
const isShiftEnter = event.shiftKey && isEnter;
|
||||
const isEnterNewLineSetting = (window.getSettingValue(SettingsKey.settingsEnterKeyFunction) as string) === 'enterNewLine';
|
||||
const isNotComposing = !event.nativeEvent.isComposing;
|
||||
|
||||
if (isEnterNewLineSetting && isEnter && isNotComposing) {
|
||||
event.preventDefault();
|
||||
if (isShiftEnter) {
|
||||
await this.onSendMessage();
|
||||
} else {
|
||||
this.insertNewLine();
|
||||
}
|
||||
} else if (isEnter && !event.shiftKey && isNotComposing) {
|
||||
event.preventDefault();
|
||||
await this.onSendMessage();
|
||||
} else if (event.key === 'Escape' && this.state.showEmojiPanel) {
|
||||
|
@ -845,6 +856,32 @@ class CompositionBoxInner extends React.Component<Props, State> {
|
|||
}
|
||||
}
|
||||
|
||||
private insertNewLine() {
|
||||
const messageBox = this.textarea.current;
|
||||
if (!messageBox) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { draft } = this.state;
|
||||
const { selectedConversationKey } = this.props;
|
||||
|
||||
if (!selectedConversationKey) {
|
||||
return; // add this check to prevent undefined from being used
|
||||
}
|
||||
|
||||
const currentSelectionStart = Number(messageBox.selectionStart);
|
||||
const realSelectionStart = getSelectionBasedOnMentions(draft, currentSelectionStart);
|
||||
|
||||
const before = draft.slice(0, realSelectionStart);
|
||||
const after = draft.slice(realSelectionStart);
|
||||
|
||||
this.setState({ draft: `${before}\n${after}` });
|
||||
updateDraftForConversation({
|
||||
conversationKey: selectedConversationKey,
|
||||
draft: `${before}\n${after}`,
|
||||
});
|
||||
}
|
||||
|
||||
private async onKeyUp() {
|
||||
if (!this.props.selectedConversationKey) {
|
||||
throw new Error('selectedConversationKey is needed');
|
||||
|
|
|
@ -6,10 +6,9 @@ import { SettingsKey } from '../../../data/settings-key';
|
|||
import { ToastUtils } from '../../../session/utils';
|
||||
import { toggleAudioAutoplay } from '../../../state/ducks/userConfig';
|
||||
import { getAudioAutoplay } from '../../../state/selectors/userConfig';
|
||||
|
||||
import { SessionRadioGroup } from '../../basic/SessionRadioGroup';
|
||||
import { BlockedContactsList } from '../BlockedList';
|
||||
|
||||
import { SessionToggleWithDescription } from '../SessionSettingListItem';
|
||||
import { SessionSettingsItemWrapper, SessionToggleWithDescription } from '../SessionSettingListItem';
|
||||
|
||||
async function toggleCommunitiesPruning() {
|
||||
try {
|
||||
|
@ -81,13 +80,48 @@ const AudioMessageAutoPlaySetting = () => {
|
|||
);
|
||||
};
|
||||
|
||||
const EnterKeyFunctionSetting = () => {
|
||||
const forceUpdate = useUpdate();
|
||||
|
||||
const initialSetting = window.getSettingValue(SettingsKey.settingsEnterKeyFunction) || true;
|
||||
|
||||
const items = [
|
||||
{
|
||||
label: window.i18n('enterSendNewMessageDescription'),
|
||||
value: 'enterSend',
|
||||
},
|
||||
{
|
||||
label: window.i18n('enterNewLineDescription'),
|
||||
value: 'enterNewLine',
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<SessionSettingsItemWrapper
|
||||
title={window.i18n('enterKeySettingTitle')}
|
||||
description={window.i18n('enterKeySettingDescription')}
|
||||
inline={false}
|
||||
>
|
||||
<SessionRadioGroup
|
||||
initialItem={initialSetting}
|
||||
group={SettingsKey.settingsEnterKeyFunction} // make sure to define this key in your SettingsKey enum
|
||||
items={items}
|
||||
onClick={async (selectedRadioValue: string) => {
|
||||
await window.setSettingValue(SettingsKey.settingsEnterKeyFunction, selectedRadioValue);
|
||||
forceUpdate();
|
||||
}}
|
||||
/>
|
||||
</SessionSettingsItemWrapper>
|
||||
);
|
||||
};
|
||||
|
||||
export const CategoryConversations = () => {
|
||||
return (
|
||||
<>
|
||||
<CommunitiesPruningSetting />
|
||||
<SpellCheckSetting />
|
||||
<AudioMessageAutoPlaySetting />
|
||||
|
||||
<EnterKeyFunctionSetting />
|
||||
<BlockedContactsList />
|
||||
</>
|
||||
);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const settingsReadReceipt = 'read-receipt-setting';
|
||||
const settingsTypingIndicator = 'typing-indicators-setting';
|
||||
const settingsAutoUpdate = 'auto-update';
|
||||
|
||||
const settingsEnterKeyFunction = 'enter-key-function-setting';
|
||||
const settingsMenuBar = 'hide-menu-bar';
|
||||
const settingsSpellCheck = 'spell-check';
|
||||
const settingsLinkPreview = 'link-preview-setting';
|
||||
|
@ -24,6 +24,7 @@ export const SettingsKey = {
|
|||
settingsReadReceipt,
|
||||
settingsTypingIndicator,
|
||||
settingsAutoUpdate,
|
||||
settingsEnterKeyFunction,
|
||||
settingsMenuBar,
|
||||
settingsSpellCheck,
|
||||
settingsLinkPreview,
|
||||
|
|
|
@ -169,9 +169,13 @@ export type LocalizerKeys =
|
|||
| 'endCall'
|
||||
| 'enterAnOpenGroupURL'
|
||||
| 'enterDisplayName'
|
||||
| 'enterKeySettingDescription'
|
||||
| 'enterKeySettingTitle'
|
||||
| 'enterNewLineDescription'
|
||||
| 'enterNewPassword'
|
||||
| 'enterPassword'
|
||||
| 'enterRecoveryPhrase'
|
||||
| 'enterSendNewMessageDescription'
|
||||
| 'enterSessionID'
|
||||
| 'enterSessionIDOfRecipient'
|
||||
| 'enterSessionIDOrONSName'
|
||||
|
|
Loading…
Reference in New Issue