diff options
Diffstat (limited to 'client/src/assets')
-rw-r--r-- | client/src/assets/player/shared/hotkeys/peertube-hotkeys-plugin.ts | 27 |
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 | ||
229 | videojs.registerPlugin('peerTubeHotkeysPlugin', PeerTubeHotkeysPlugin) | 254 | videojs.registerPlugin('peerTubeHotkeysPlugin', PeerTubeHotkeysPlugin) |