From 4adea67eb3bfca997d9665db72dae77a9f409265 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 15 Jul 2019 18:12:45 +0200 Subject: [PATCH] focus the composer in the body keydown handler if not other shortcuts apply this allows the user to start typing a message even if the composer is not focused. --- src/components/structures/LoggedInView.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/components/structures/LoggedInView.js b/src/components/structures/LoggedInView.js index cd752fc2ce..146af704c0 100644 --- a/src/components/structures/LoggedInView.js +++ b/src/components/structures/LoggedInView.js @@ -333,6 +333,22 @@ const LoggedInView = React.createClass({ if (handled) { ev.stopPropagation(); ev.preventDefault(); + } else { + const targetTag = ev.target.tagName; + const focusedOnInputControl = targetTag === "INPUT" || + targetTag === "TEXTAREA" || + targetTag === "SELECT" || + ev.target.getAttribute("contenteditable"); + // we don't check for buttons that have focus here, + // because they should be using AccessibleButton which + // calls stopPropagation on space or enter keydown, so + // that keydown event would never get here. + if (!focusedOnInputControl) { + dis.dispatch({action: 'focus_composer'}, true); + ev.stopPropagation(); + // we should *not* preventDefault() here as + // that would prevent typing in the now-focussed composer + } } },