Merge pull request #5160 from czeidler/ctrl-enter-send
Add option to send/edit a message with Ctrl + Enter / Command + Enter
This commit is contained in:
commit
5ee21d448b
5 changed files with 22 additions and 4 deletions
|
@ -29,9 +29,10 @@ import EditorStateTransfer from '../../../utils/EditorStateTransfer';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import {EventStatus} from 'matrix-js-sdk';
|
import {EventStatus} from 'matrix-js-sdk';
|
||||||
import BasicMessageComposer from "./BasicMessageComposer";
|
import BasicMessageComposer from "./BasicMessageComposer";
|
||||||
import {Key} from "../../../Keyboard";
|
import {Key, isOnlyCtrlOrCmdKeyEvent} from "../../../Keyboard";
|
||||||
import MatrixClientContext from "../../../contexts/MatrixClientContext";
|
import MatrixClientContext from "../../../contexts/MatrixClientContext";
|
||||||
import {Action} from "../../../dispatcher/actions";
|
import {Action} from "../../../dispatcher/actions";
|
||||||
|
import SettingsStore from "../../../settings/SettingsStore";
|
||||||
import CountlyAnalytics from "../../../CountlyAnalytics";
|
import CountlyAnalytics from "../../../CountlyAnalytics";
|
||||||
|
|
||||||
function _isReply(mxEvent) {
|
function _isReply(mxEvent) {
|
||||||
|
@ -136,7 +137,10 @@ export default class EditMessageComposer extends React.Component {
|
||||||
if (event.metaKey || event.altKey || event.shiftKey) {
|
if (event.metaKey || event.altKey || event.shiftKey) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.key === Key.ENTER) {
|
const ctrlEnterToSend = !!SettingsStore.getValue('MessageComposerInput.ctrlEnterToSend');
|
||||||
|
const send = ctrlEnterToSend ? event.key === Key.ENTER && isOnlyCtrlOrCmdKeyEvent(event)
|
||||||
|
: event.key === Key.ENTER;
|
||||||
|
if (send) {
|
||||||
this._sendEdit();
|
this._sendEdit();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
} else if (event.key === Key.ESCAPE) {
|
} else if (event.key === Key.ESCAPE) {
|
||||||
|
|
|
@ -38,10 +38,11 @@ import * as sdk from '../../../index';
|
||||||
import Modal from '../../../Modal';
|
import Modal from '../../../Modal';
|
||||||
import {_t, _td} from '../../../languageHandler';
|
import {_t, _td} from '../../../languageHandler';
|
||||||
import ContentMessages from '../../../ContentMessages';
|
import ContentMessages from '../../../ContentMessages';
|
||||||
import {Key} from "../../../Keyboard";
|
import {Key, isOnlyCtrlOrCmdKeyEvent} from "../../../Keyboard";
|
||||||
import MatrixClientContext from "../../../contexts/MatrixClientContext";
|
import MatrixClientContext from "../../../contexts/MatrixClientContext";
|
||||||
import RateLimitedFunc from '../../../ratelimitedfunc';
|
import RateLimitedFunc from '../../../ratelimitedfunc';
|
||||||
import {Action} from "../../../dispatcher/actions";
|
import {Action} from "../../../dispatcher/actions";
|
||||||
|
import SettingsStore from "../../../settings/SettingsStore";
|
||||||
import CountlyAnalytics from "../../../CountlyAnalytics";
|
import CountlyAnalytics from "../../../CountlyAnalytics";
|
||||||
|
|
||||||
function addReplyToMessageContent(content, repliedToEvent, permalinkCreator) {
|
function addReplyToMessageContent(content, repliedToEvent, permalinkCreator) {
|
||||||
|
@ -122,7 +123,11 @@ export default class SendMessageComposer extends React.Component {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const hasModifier = event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
|
const hasModifier = event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
|
||||||
if (event.key === Key.ENTER && !hasModifier) {
|
const ctrlEnterToSend = !!SettingsStore.getValue('MessageComposerInput.ctrlEnterToSend');
|
||||||
|
const send = ctrlEnterToSend
|
||||||
|
? event.key === Key.ENTER && isOnlyCtrlOrCmdKeyEvent(event)
|
||||||
|
: event.key === Key.ENTER && !hasModifier;
|
||||||
|
if (send) {
|
||||||
this._sendMessage();
|
this._sendMessage();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
} else if (event.key === Key.ARROW_UP) {
|
} else if (event.key === Key.ARROW_UP) {
|
||||||
|
|
|
@ -33,6 +33,7 @@ export default class PreferencesUserSettingsTab extends React.Component {
|
||||||
'MessageComposerInput.autoReplaceEmoji',
|
'MessageComposerInput.autoReplaceEmoji',
|
||||||
'MessageComposerInput.suggestEmoji',
|
'MessageComposerInput.suggestEmoji',
|
||||||
'sendTypingNotifications',
|
'sendTypingNotifications',
|
||||||
|
'MessageComposerInput.ctrlEnterToSend',
|
||||||
];
|
];
|
||||||
|
|
||||||
static TIMELINE_SETTINGS = [
|
static TIMELINE_SETTINGS = [
|
||||||
|
|
|
@ -730,6 +730,8 @@
|
||||||
"Enable big emoji in chat": "Enable big emoji in chat",
|
"Enable big emoji in chat": "Enable big emoji in chat",
|
||||||
"Send typing notifications": "Send typing notifications",
|
"Send typing notifications": "Send typing notifications",
|
||||||
"Show typing notifications": "Show typing notifications",
|
"Show typing notifications": "Show typing notifications",
|
||||||
|
"Use Command + Enter to send a message": "Use Command + Enter to send a message",
|
||||||
|
"Use Ctrl + Enter to send a message": "Use Ctrl + Enter to send a message",
|
||||||
"Automatically replace plain text Emoji": "Automatically replace plain text Emoji",
|
"Automatically replace plain text Emoji": "Automatically replace plain text Emoji",
|
||||||
"Mirror local video feed": "Mirror local video feed",
|
"Mirror local video feed": "Mirror local video feed",
|
||||||
"Enable Community Filter Panel": "Enable Community Filter Panel",
|
"Enable Community Filter Panel": "Enable Community Filter Panel",
|
||||||
|
|
|
@ -32,6 +32,7 @@ import UseSystemFontController from './controllers/UseSystemFontController';
|
||||||
import { SettingLevel } from "./SettingLevel";
|
import { SettingLevel } from "./SettingLevel";
|
||||||
import SettingController from "./controllers/SettingController";
|
import SettingController from "./controllers/SettingController";
|
||||||
import { RightPanelPhases } from "../stores/RightPanelStorePhases";
|
import { RightPanelPhases } from "../stores/RightPanelStorePhases";
|
||||||
|
import { isMac } from '../Keyboard';
|
||||||
import UIFeatureController from "./controllers/UIFeatureController";
|
import UIFeatureController from "./controllers/UIFeatureController";
|
||||||
import { UIFeature } from "./UIFeature";
|
import { UIFeature } from "./UIFeature";
|
||||||
import { OrderedMultiController } from "./controllers/OrderedMultiController";
|
import { OrderedMultiController } from "./controllers/OrderedMultiController";
|
||||||
|
@ -324,6 +325,11 @@ export const SETTINGS: {[setting: string]: ISetting} = {
|
||||||
displayName: _td("Show typing notifications"),
|
displayName: _td("Show typing notifications"),
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
|
"MessageComposerInput.ctrlEnterToSend": {
|
||||||
|
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
|
||||||
|
displayName: isMac ? _td("Use Command + Enter to send a message") : _td("Use Ctrl + Enter to send a message"),
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
"MessageComposerInput.autoReplaceEmoji": {
|
"MessageComposerInput.autoReplaceEmoji": {
|
||||||
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
|
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
|
||||||
displayName: _td('Automatically replace plain text Emoji'),
|
displayName: _td('Automatically replace plain text Emoji'),
|
||||||
|
|
Loading…
Reference in a new issue