mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-05-16 09:01:57 +00:00
fix: guard shortcuts against interfering
This commit is contained in:
parent
e8d77595ed
commit
c91b33fddd
2 changed files with 7 additions and 4 deletions
|
|
@ -25,7 +25,7 @@ const ShortcutsProvider = ({ children, onShortcut }: Props) => {
|
||||||
const listeners = useRef<Map<ShortcutName, Set<ShortcutListener>>>(new Map());
|
const listeners = useRef<Map<ShortcutName, Set<ShortcutListener>>>(new Map());
|
||||||
const lastRepeatTime = useRef<Map<string, number>>(new Map());
|
const lastRepeatTime = useRef<Map<string, number>>(new Map());
|
||||||
|
|
||||||
const onKeyDown = useCallback(({ ctrlKey, shiftKey, code, key, repeat }: KeyboardEvent) => {
|
const onKeyDown = useCallback(({ ctrlKey, shiftKey, altKey, metaKey, code, key, repeat }: KeyboardEvent) => {
|
||||||
if (repeat) {
|
if (repeat) {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const last = lastRepeatTime.current.get(code) ?? 0;
|
const last = lastRepeatTime.current.get(code) ?? 0;
|
||||||
|
|
@ -34,8 +34,10 @@ const ShortcutsProvider = ({ children, onShortcut }: Props) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
SHORTCUTS.forEach(({ name, combos }) => combos.forEach((keys) => {
|
SHORTCUTS.forEach(({ name, combos }) => combos.forEach((keys) => {
|
||||||
const modifers = (keys.includes('Ctrl') ? ctrlKey : true)
|
const modifers = (keys.includes('Ctrl') === ctrlKey)
|
||||||
&& (keys.includes('Shift') ? shiftKey : true);
|
&& (keys.includes('Shift') === shiftKey)
|
||||||
|
&& !altKey
|
||||||
|
&& !metaKey;
|
||||||
|
|
||||||
if (modifers && (keys.includes(code) || keys.includes(key.toUpperCase()))) {
|
if (modifers && (keys.includes(code) || keys.includes(key.toUpperCase()))) {
|
||||||
const combo = combos.indexOf(keys);
|
const combo = combos.indexOf(keys);
|
||||||
|
|
|
||||||
|
|
@ -658,7 +658,7 @@ const Player = ({ urlParams, queryParams }) => {
|
||||||
|
|
||||||
const onKeyDown = (e) => {
|
const onKeyDown = (e) => {
|
||||||
if (e.code !== 'Space' || e.repeat) return;
|
if (e.code !== 'Space' || e.repeat) return;
|
||||||
if (menusOpen) return;
|
if (menusOpen || e.ctrlKey || e.metaKey || e.altKey) return;
|
||||||
|
|
||||||
longPress.current = false;
|
longPress.current = false;
|
||||||
|
|
||||||
|
|
@ -670,6 +670,7 @@ const Player = ({ urlParams, queryParams }) => {
|
||||||
|
|
||||||
const onKeyUp = (e) => {
|
const onKeyUp = (e) => {
|
||||||
if (e.code !== 'Space' && e.code !== 'ArrowRight' && e.code !== 'ArrowLeft') return;
|
if (e.code !== 'Space' && e.code !== 'ArrowRight' && e.code !== 'ArrowLeft') return;
|
||||||
|
if (e.ctrlKey || e.metaKey || e.altKey) return;
|
||||||
|
|
||||||
if (e.code === 'ArrowRight' || e.code === 'ArrowLeft') {
|
if (e.code === 'ArrowRight' || e.code === 'ArrowLeft') {
|
||||||
setSeeking(false);
|
setSeeking(false);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue