MM-13178: ignore enter key within 500ms of switching channels (#2142)

In MM-12908, we changed the behaviour to disallow sending within 500ms of switching channels, but still funnelled the enter key into the textbox. With the theory as to the original cause now confirmed, we are updating this fix to suppress the enter key altogether in that window.
parent 5a841383
......@@ -551,7 +551,13 @@ export default class CreatePost extends React.Component {
postMsgKeyPress = (e) => {
const {ctrlSend, codeBlockOnCtrlEnter, currentChannel} = this.props;
const {allowSending, withClosedCodeBlock, message} = postMessageOnKeyPress(e, this.state.message, ctrlSend, codeBlockOnCtrlEnter, Date.now(), this.lastChannelSwitchAt);
const {allowSending, withClosedCodeBlock, ignoreKeyPress, message} = postMessageOnKeyPress(e, this.state.message, ctrlSend, codeBlockOnCtrlEnter, Date.now(), this.lastChannelSwitchAt);
if (ignoreKeyPress) {
e.preventDefault();
e.stopPropagation();
return;
}
if (allowSending) {
e.persist();
......
......@@ -212,7 +212,7 @@ export function postMessageOnKeyPress(event, message, sendMessageOnCtrlEnter, se
// Don't send if we just switched channels within a threshold.
if (lastChannelSwitchAt > 0 && now > 0 && now - lastChannelSwitchAt <= CHANNEL_SWITCH_IGNORE_ENTER_THRESHOLD_MS) {
return {allowSending: false};
return {allowSending: false, ignoreKeyPress: true};
}
if (
......
......@@ -494,11 +494,11 @@ describe('PostUtils.postMessageOnKeyPress', () => {
}, {
name: 'last channel switch within threshold',
input: {event: {keyCode: 13}, message: 'message', sendMessageOnCtrlEnter: false, sendCodeBlockOnCtrlEnter: true, now: 1541658920334, lastChannelSwitch: 1541658920334 - 250},
expected: {allowSending: false},
expected: {allowSending: false, ignoreKeyPress: true},
}, {
name: 'last channel switch at threshold',
input: {event: {keyCode: 13}, message: 'message', sendMessageOnCtrlEnter: false, sendCodeBlockOnCtrlEnter: true, now: 1541658920334, lastChannelSwitch: 1541658920334 - 500},
expected: {allowSending: false},
expected: {allowSending: false, ignoreKeyPress: true},
}, {
name: 'last channel switch outside threshold',
input: {event: {keyCode: 13}, message: 'message', sendMessageOnCtrlEnter: false, sendCodeBlockOnCtrlEnter: true, now: 1541658920334, lastChannelSwitch: 1541658920334 - 501},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment