From cc4d23e27669ce85285b514a0606b4ea8c27d6e7 Mon Sep 17 00:00:00 2001
From: David Lu <david.lu@hotmail.com>
Date: Sat, 4 Jun 2016 23:23:07 -0700
Subject: added ctrlSend checking (#3196)

---
 webapp/components/edit_channel_purpose_modal.jsx | 35 +++++++++++++++++++++---
 1 file changed, 31 insertions(+), 4 deletions(-)

(limited to 'webapp/components/edit_channel_purpose_modal.jsx')

diff --git a/webapp/components/edit_channel_purpose_modal.jsx b/webapp/components/edit_channel_purpose_modal.jsx
index a4779d022..0d5fb90ac 100644
--- a/webapp/components/edit_channel_purpose_modal.jsx
+++ b/webapp/components/edit_channel_purpose_modal.jsx
@@ -6,9 +6,8 @@ import ReactDOM from 'react-dom';
 import * as AsyncClient from 'utils/async_client.jsx';
 import Client from 'utils/web_client.jsx';
 import Constants from 'utils/constants.jsx';
-
 import {intlShape, injectIntl, defineMessages, FormattedMessage} from 'react-intl';
-
+import PreferenceStore from 'stores/preference_store.jsx';
 import {Modal} from 'react-bootstrap';
 
 const holders = defineMessages({
@@ -26,8 +25,22 @@ export default class EditChannelPurposeModal extends React.Component {
 
         this.handleHide = this.handleHide.bind(this);
         this.handleSave = this.handleSave.bind(this);
+        this.handleKeyDown = this.handleKeyDown.bind(this);
+        this.onPreferenceChange = this.onPreferenceChange.bind(this);
+
+        this.ctrlSend = PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter');
+
+        this.state = {
+            serverError: ''
+        };
+    }
+
+    componentDidMount() {
+        PreferenceStore.addChangeListener(this.onPreferenceChange);
+    }
 
-        this.state = {serverError: ''};
+    componentWillUnmount() {
+        PreferenceStore.removeChangeListener(this.onPreferenceChange);
     }
 
     componentDidUpdate() {
@@ -44,11 +57,24 @@ export default class EditChannelPurposeModal extends React.Component {
         }
     }
 
+    onPreferenceChange() {
+        this.ctrlSend = PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter');
+    }
+
+    handleKeyDown(e) {
+        if (this.ctrlSend && e.keyCode === Constants.KeyCodes.ENTER && e.ctrlKey) {
+            e.preventDefault();
+            this.handleSave(e);
+        } else if (!this.ctrlSend && e.keyCode === Constants.KeyCodes.ENTER && !e.shiftKey && !e.altKey) {
+            e.preventDefault();
+            this.handleSave(e);
+        }
+    }
+
     handleSave() {
         if (!this.props.channel) {
             return;
         }
-
         Client.updateChannelPurpose(
             this.props.channel.id,
             ReactDOM.findDOMNode(this.refs.purpose).value.trim(),
@@ -145,6 +171,7 @@ export default class EditChannelPurposeModal extends React.Component {
                         rows='6'
                         maxLength='128'
                         defaultValue={this.props.channel.purpose}
+                        onKeyDown={this.handleKeyDown}
                     />
                     {serverError}
                 </Modal.Body>
-- 
cgit v1.2.3-1-g7c22

