From 2c525a5466c14a345b59f324e6e0874ae88fa3df Mon Sep 17 00:00:00 2001 From: Wicklow <123956049+wickloww@users.noreply.github.com> Date: Wed, 8 Mar 2023 14:08:46 +0000 Subject: Non latin keyboard layout support player shortcut (#5684) * Non latin keyboard layout support player shortcut * isNaked in charge of toUpperCase --- .../shared/hotkeys/peertube-hotkeys-plugin.ts | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'client/src') diff --git a/client/src/assets/player/shared/hotkeys/peertube-hotkeys-plugin.ts b/client/src/assets/player/shared/hotkeys/peertube-hotkeys-plugin.ts index f5b4b3919..2742b21a1 100644 --- a/client/src/assets/player/shared/hotkeys/peertube-hotkeys-plugin.ts +++ b/client/src/assets/player/shared/hotkeys/peertube-hotkeys-plugin.ts @@ -218,12 +218,37 @@ class PeerTubeHotkeysPlugin extends Plugin { } private isNaked (event: KeyboardEvent, key: string) { - return (!event.ctrlKey && !event.altKey && !event.metaKey && !event.shiftKey && event.key === key) + if (key.length === 1) key = key.toUpperCase() + + return (!event.ctrlKey && !event.altKey && !event.metaKey && !event.shiftKey && this.getLatinKey(event.key, event.code) === key) } private isNakedOrShift (event: KeyboardEvent, key: string) { return (!event.ctrlKey && !event.altKey && !event.metaKey && event.key === key) } + + // Thanks Maciej Krawczyk + // https://stackoverflow.com/questions/70211837/keyboard-shortcuts-commands-on-non-latin-alphabet-keyboards-javascript?rq=1 + private getLatinKey (key: string, code: string) { + if (key.length !== 1) { + return key + } + + const capitalHetaCode = 880 + const isNonLatin = key.charCodeAt(0) >= capitalHetaCode + + if (isNonLatin) { + if (code.indexOf('Key') === 0 && code.length === 4) { // i.e. 'KeyW' + return code.charAt(3) + } + + if (code.indexOf('Digit') === 0 && code.length === 6) { // i.e. 'Digit7' + return code.charAt(5) + } + } + + return key.toUpperCase() + } } videojs.registerPlugin('peerTubeHotkeysPlugin', PeerTubeHotkeysPlugin) -- cgit v1.2.3