aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets
diff options
context:
space:
mode:
authorWicklow <123956049+wickloww@users.noreply.github.com>2023-03-08 14:08:46 +0000
committerGitHub <noreply@github.com>2023-03-08 15:08:46 +0100
commit2c525a5466c14a345b59f324e6e0874ae88fa3df (patch)
tree01559189cc0776a54276ef841d28acedce71d0d0 /client/src/assets
parent0e3026f3159f2b766a73393219b10cbe49111141 (diff)
downloadPeerTube-2c525a5466c14a345b59f324e6e0874ae88fa3df.tar.gz
PeerTube-2c525a5466c14a345b59f324e6e0874ae88fa3df.tar.zst
PeerTube-2c525a5466c14a345b59f324e6e0874ae88fa3df.zip
Non latin keyboard layout support player shortcut (#5684)
* Non latin keyboard layout support player shortcut * isNaked in charge of toUpperCase
Diffstat (limited to 'client/src/assets')
-rw-r--r--client/src/assets/player/shared/hotkeys/peertube-hotkeys-plugin.ts27
1 files changed, 26 insertions, 1 deletions
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 {
218 } 218 }
219 219
220 private isNaked (event: KeyboardEvent, key: string) { 220 private isNaked (event: KeyboardEvent, key: string) {
221 return (!event.ctrlKey && !event.altKey && !event.metaKey && !event.shiftKey && event.key === key) 221 if (key.length === 1) key = key.toUpperCase()
222
223 return (!event.ctrlKey && !event.altKey && !event.metaKey && !event.shiftKey && this.getLatinKey(event.key, event.code) === key)
222 } 224 }
223 225
224 private isNakedOrShift (event: KeyboardEvent, key: string) { 226 private isNakedOrShift (event: KeyboardEvent, key: string) {
225 return (!event.ctrlKey && !event.altKey && !event.metaKey && event.key === key) 227 return (!event.ctrlKey && !event.altKey && !event.metaKey && event.key === key)
226 } 228 }
229
230 // Thanks Maciej Krawczyk
231 // https://stackoverflow.com/questions/70211837/keyboard-shortcuts-commands-on-non-latin-alphabet-keyboards-javascript?rq=1
232 private getLatinKey (key: string, code: string) {
233 if (key.length !== 1) {
234 return key
235 }
236
237 const capitalHetaCode = 880
238 const isNonLatin = key.charCodeAt(0) >= capitalHetaCode
239
240 if (isNonLatin) {
241 if (code.indexOf('Key') === 0 && code.length === 4) { // i.e. 'KeyW'
242 return code.charAt(3)
243 }
244
245 if (code.indexOf('Digit') === 0 && code.length === 6) { // i.e. 'Digit7'
246 return code.charAt(5)
247 }
248 }
249
250 return key.toUpperCase()
251 }
227} 252}
228 253
229videojs.registerPlugin('peerTubeHotkeysPlugin', PeerTubeHotkeysPlugin) 254videojs.registerPlugin('peerTubeHotkeysPlugin', PeerTubeHotkeysPlugin)