mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-17 02:01:45 +03:00
Improve composer keyboard trapping
This commit is contained in:
parent
c05eceef7f
commit
9e2974d84d
1 changed files with 9 additions and 9 deletions
|
@ -495,24 +495,24 @@ class LoggedInView extends React.Component<IProps, IState> {
|
||||||
if (handled) {
|
if (handled) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
} else if (!isModifier && !ev.altKey && !ev.ctrlKey && !ev.metaKey) {
|
} else if (!isModifier && !ev.ctrlKey && !ev.metaKey) {
|
||||||
// The above condition is crafted to _allow_ characters with Shift
|
// The above condition is crafted to _allow_ characters with Shift
|
||||||
// already pressed (but not the Shift key down itself).
|
// already pressed (but not the Shift key down itself).
|
||||||
|
|
||||||
const isClickShortcut = ev.target !== document.body &&
|
const isClickShortcut = ev.target !== document.body &&
|
||||||
(ev.key === Key.SPACE || ev.key === Key.ENTER);
|
(ev.key === Key.SPACE || ev.key === Key.ENTER);
|
||||||
|
|
||||||
// Do not capture the context menu key to improve keyboard accessibility
|
// We explicitly allow alt to be held due to it being a common accent modifier.
|
||||||
if (ev.key === Key.CONTEXT_MENU) {
|
// XXX: Forwarding Dead keys in this way does not work as intended but better to at least
|
||||||
return;
|
// move focus to the composer so the user can re-type the dead key correctly.
|
||||||
}
|
const isPrintable = ev.key.length === 1 || ev.key === "Dead";
|
||||||
|
|
||||||
if (!isClickShortcut && ev.key !== Key.TAB && !canElementReceiveInput(ev.target)) {
|
// If the user is entering a printable character outside of an input field
|
||||||
|
// redirect it to the composer for them.
|
||||||
|
if (!isClickShortcut && isPrintable && !canElementReceiveInput(ev.target)) {
|
||||||
// synchronous dispatch so we focus before key generates input
|
// synchronous dispatch so we focus before key generates input
|
||||||
dis.fire(Action.FocusComposer, true);
|
dis.fire(Action.FocusComposer, true);
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
// we should *not* preventDefault() here as
|
// we should *not* preventDefault() here as that would prevent typing in the now-focused composer
|
||||||
// that would prevent typing in the now-focussed composer
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue