Non latin keyboard layout support player shortcut (#5684)

* Non latin keyboard layout support player shortcut

* isNaked in charge of toUpperCase
pull/5692/head
Wicklow 2023-03-08 14:08:46 +00:00 committed by GitHub
parent 0e3026f315
commit 2c525a5466
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 1 deletions

View File

@ -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)