diff --git a/src/components/structures/LoggedInView.js b/src/components/structures/LoggedInView.js index f6443deec3..cfa39af92a 100644 --- a/src/components/structures/LoggedInView.js +++ b/src/components/structures/LoggedInView.js @@ -42,6 +42,13 @@ import {Resizer, CollapseDistributor} from '../../resizer'; // NB. this is just for server notices rather than pinned messages in general. const MAX_PINNED_NOTICES_PER_ROOM = 2; +function canElementReceiveInput(el) { + return el.tagName === "INPUT" || + el.tagName === "TEXTAREA" || + el.tagName === "SELECT" || + !!el.getAttribute("contenteditable"); +} + /** * This is what our MatrixChat shows when we are logged in. The precise view is * determined by the page_type property. @@ -272,6 +279,19 @@ const LoggedInView = React.createClass({ }); }, + _onPaste: function(ev) { + let canReceiveInput = false; + let element = ev.target; + // test for all parents because the target can be a child of a contenteditable element + while (!canReceiveInput && element) { + canReceiveInput = canElementReceiveInput(element); + element = element.parentElement; + } + if (!canReceiveInput) { + dis.dispatch({action: 'focus_composer'}, true); + } + }, + /* SOME HACKERY BELOW: React optimizes event handlers, by always attaching only 1 handler to the document for a given type. @@ -371,15 +391,10 @@ const LoggedInView = React.createClass({ ev.stopPropagation(); ev.preventDefault(); } else if (!hasModifier) { - const targetTag = ev.target.tagName; - const focusedOnInputControl = targetTag === "INPUT" || - targetTag === "TEXTAREA" || - targetTag === "SELECT" || - !!ev.target.getAttribute("contenteditable"); const isClickShortcut = ev.target !== document.body && (ev.key === "Space" || ev.key === "Enter"); - if (!focusedOnInputControl && !isClickShortcut) { + if (!isClickShortcut && !canElementReceiveInput(ev.target)) { dis.dispatch({action: 'focus_composer'}, true); ev.stopPropagation(); // we should *not* preventDefault() here as @@ -596,7 +611,7 @@ const LoggedInView = React.createClass({ } return ( -
+
{ topBar }