From 0e5612a7db9f4205485b0c4bfcd8d2ab35727d01 Mon Sep 17 00:00:00 2001 From: Florian Orben Date: Mon, 26 Oct 2015 22:05:26 +0100 Subject: allow messages to be send on ctrl+enter --- web/react/components/create_comment.jsx | 31 ++++++-- web/react/components/create_post.jsx | 31 ++++++-- .../user_settings/user_settings_general.jsx | 89 +++++++++++++++++++++- 3 files changed, 134 insertions(+), 17 deletions(-) (limited to 'web/react') diff --git a/web/react/components/create_comment.jsx b/web/react/components/create_comment.jsx index 18936e808..7b199f5d6 100644 --- a/web/react/components/create_comment.jsx +++ b/web/react/components/create_comment.jsx @@ -27,7 +27,7 @@ export default class CreateComment extends React.Component { this.handleSubmit = this.handleSubmit.bind(this); this.commentMsgKeyPress = this.commentMsgKeyPress.bind(this); this.handleUserInput = this.handleUserInput.bind(this); - this.handleArrowUp = this.handleArrowUp.bind(this); + this.handleKeyDown = this.handleKeyDown.bind(this); this.handleUploadStart = this.handleUploadStart.bind(this); this.handleFileUploadComplete = this.handleFileUploadComplete.bind(this); this.handleUploadError = this.handleUploadError.bind(this); @@ -36,6 +36,7 @@ export default class CreateComment extends React.Component { this.handleSubmit = this.handleSubmit.bind(this); this.getFileCount = this.getFileCount.bind(this); this.handleResize = this.handleResize.bind(this); + this.onUserChange = this.onUserChange.bind(this); PostStore.clearCommentDraftUploads(); @@ -45,8 +46,11 @@ export default class CreateComment extends React.Component { uploadsInProgress: draft.uploadsInProgress, previews: draft.previews, submitting: false, - windowWidth: Utils.windowWidth() + windowWidth: Utils.windowWidth(), + ctrlSend: UserStore.getCurrentUser().props.ctrlSend }; + + UserStore.addChangeListener(this.onUserChange); } componentDidMount() { window.addEventListener('resize', this.handleResize); @@ -54,6 +58,10 @@ export default class CreateComment extends React.Component { componentWillUnmount() { window.removeEventListener('resize', this.handleResize); } + onUserChange() { + const ctrlSend = UserStore.getCurrentUser().props.ctrlSend || 'false'; + this.setState({ctrlSend}); + } handleResize() { this.setState({windowWidth: Utils.windowWidth()}); } @@ -140,10 +148,12 @@ export default class CreateComment extends React.Component { this.setState({messageText: '', submitting: false, postError: null, previews: [], serverError: null}); } commentMsgKeyPress(e) { - if (e.which === 13 && !e.shiftKey && !e.altKey) { - e.preventDefault(); - ReactDOM.findDOMNode(this.refs.textbox).blur(); - this.handleSubmit(e); + if (this.state.ctrlSend === 'true' && e.ctrlKey || this.state.ctrlSend === 'false') { + if (e.which === KeyCodes.ENTER && !e.shiftKey && !e.altKey) { + e.preventDefault(); + ReactDOM.findDOMNode(this.refs.textbox).blur(); + this.handleSubmit(e); + } } const t = Date.now(); @@ -161,7 +171,12 @@ export default class CreateComment extends React.Component { $('.post-right__scroll').perfectScrollbar('update'); this.setState({messageText: messageText}); } - handleArrowUp(e) { + handleKeyDown(e) { + if (this.state.ctrlSend === 'true' && e.keyCode === KeyCodes.ENTER && e.ctrlKey === true) { + this.commentMsgKeyPress(e); + return; + } + if (e.keyCode === KeyCodes.UP && this.state.messageText === '') { e.preventDefault(); @@ -313,7 +328,7 @@ export default class CreateComment extends React.Component { ); } + + var miscellaneousSection; + var describeCtrlSend = this.state.props.ctrlSend === 'true' ? 'On' : 'Off'; + if (this.props.activeSection === 'ctrlSend') { + var ctrlSendActive = [false, false]; + if (this.state.props.ctrlSend === 'true') { + ctrlSendActive[0] = true; + } else { + ctrlSendActive[1] = true; + } + + let ctrlSendInputs = []; + ctrlSendInputs.push( +
+
+
+ +
+
+
+ +
+
+

{'If enabled \'Enter\' inserts a new line and ctrl + enter submits the message.'}
+
+
+ ); + + miscellaneousSection = ( + + ); + } else { + miscellaneousSection = ( + + ); + } + return (
@@ -601,6 +686,8 @@ export default class UserSettingsGeneralTab extends React.Component { {emailSection}
{pictureSection} +
+ {miscellaneousSection}
-- cgit v1.2.3-1-g7c22