diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index 8efd2fa579..672279ef54 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -93,6 +93,7 @@ export default class MessageComposerInput extends React.Component { this.onEscape = this.onEscape.bind(this); this.setDisplayedCompletion = this.setDisplayedCompletion.bind(this); this.onMarkdownToggleClicked = this.onMarkdownToggleClicked.bind(this); + this.onPageUnload = this.onPageUnload.bind(this); const isRichtextEnabled = UserSettingsStore.getSyncedSetting('MessageComposerInput.isRichTextEnabled', false); @@ -233,11 +234,13 @@ export default class MessageComposerInput extends React.Component { this.refs.editor, this.props.room.roomId ); + window.addEventListener('beforeunload', this.onPageUnload); } componentWillUnmount() { dis.unregister(this.dispatcherRef); this.sentHistory.saveLastTextEntry(); + window.removeEventListener('beforeunload', this.onPageUnload); } componentWillUpdate(nextProps, nextState) { @@ -249,6 +252,13 @@ export default class MessageComposerInput extends React.Component { } } + onPageUnload(event) { + if (this.isTyping) { + return event.returnValue = + 'You seem to be typing a message, are you sure you want to quit?'; + } + } + onAction(payload) { let editor = this.refs.editor; let contentState = this.state.editorState.getCurrentContent(); diff --git a/src/components/views/rooms/MessageComposerInputOld.js b/src/components/views/rooms/MessageComposerInputOld.js index 378644478c..2a992cdf5f 100644 --- a/src/components/views/rooms/MessageComposerInputOld.js +++ b/src/components/views/rooms/MessageComposerInputOld.js @@ -177,11 +177,20 @@ export default React.createClass({ if (this.props.tabComplete) { this.props.tabComplete.setTextArea(this.refs.textarea); } + window.addEventListener('beforeunload', this.onPageUnload); }, componentWillUnmount: function() { dis.unregister(this.dispatcherRef); this.sentHistory.saveLastTextEntry(); + window.removeEventListener('beforeunload', this.onPageUnload); + }, + + onPageUnload(event) { + if (this.isTyping) { + return event.returnValue = + 'You seem to be typing a message, are you sure you want to quit?'; + } }, onAction: function(payload) {