Merge pull request #1257 from Stremio/fix/shortcuts-guard-against-combos
Some checks are pending
Build / build (push) Waiting to run

Shortcuts: Prevent shortcuts from firing when another key is pressed
This commit is contained in:
Timothy Z. 2026-05-04 14:44:18 +03:00 committed by GitHub
commit de2b9d9378
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View file

@ -25,7 +25,7 @@ const ShortcutsProvider = ({ children, onShortcut }: Props) => {
const listeners = useRef<Map<ShortcutName, Set<ShortcutListener>>>(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) {
const now = Date.now();
const last = lastRepeatTime.current.get(code) ?? 0;
@ -34,8 +34,10 @@ const ShortcutsProvider = ({ children, onShortcut }: Props) => {
}
SHORTCUTS.forEach(({ name, combos }) => combos.forEach((keys) => {
const modifers = (keys.includes('Ctrl') ? ctrlKey : true)
&& (keys.includes('Shift') ? shiftKey : true);
const modifers = (keys.includes('Ctrl') === ctrlKey)
&& (keys.includes('Shift') === shiftKey)
&& !altKey
&& !metaKey;
if (modifers && (keys.includes(code) || keys.includes(key.toUpperCase()))) {
const combo = combos.indexOf(keys);

View file

@ -658,7 +658,7 @@ const Player = ({ urlParams, queryParams }) => {
const onKeyDown = (e) => {
if (e.code !== 'Space' || e.repeat) return;
if (menusOpen) return;
if (menusOpen || e.ctrlKey || e.metaKey || e.altKey) return;
longPress.current = false;
@ -670,6 +670,7 @@ const Player = ({ urlParams, queryParams }) => {
const onKeyUp = (e) => {
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') {
setSeeking(false);