@readium/navigator-html-injectables 2.4.2-beta.2 → 2.4.2-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -19,19 +19,30 @@ export class KeyCombinationManager {
|
|
|
19
19
|
*/
|
|
20
20
|
public match(event: KeyboardEvent, combos: KeyCombo[]): boolean {
|
|
21
21
|
for (const combo of combos) {
|
|
22
|
-
|
|
23
|
-
const ctrlMatch = combo.ctrl === undefined || event.ctrlKey === combo.ctrl;
|
|
24
|
-
const shiftMatch = combo.shift === undefined || event.shiftKey === combo.shift;
|
|
25
|
-
const altMatch = combo.alt === undefined || event.altKey === combo.alt;
|
|
26
|
-
const metaMatch = combo.meta === undefined || event.metaKey === combo.meta;
|
|
27
|
-
|
|
28
|
-
if (keyMatch && ctrlMatch && shiftMatch && altMatch && metaMatch) {
|
|
22
|
+
if (this.matchesCombo(event, combo)) {
|
|
29
23
|
return true;
|
|
30
24
|
}
|
|
31
25
|
}
|
|
32
26
|
return false;
|
|
33
27
|
}
|
|
34
28
|
|
|
29
|
+
private matchesCombo(event: KeyboardEvent, combo: KeyCombo): boolean {
|
|
30
|
+
return event.keyCode === combo.keyCode &&
|
|
31
|
+
this.matchesModifier(event.ctrlKey, combo.ctrl) &&
|
|
32
|
+
this.matchesModifier(event.shiftKey, combo.shift) &&
|
|
33
|
+
this.matchesModifier(event.altKey, combo.alt) &&
|
|
34
|
+
this.matchesModifier(event.metaKey, combo.meta);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private matchesModifier(eventModifier: boolean, comboModifier?: boolean): boolean {
|
|
38
|
+
if (comboModifier === undefined) {
|
|
39
|
+
// Modifier not specified: must NOT be pressed
|
|
40
|
+
return !eventModifier;
|
|
41
|
+
}
|
|
42
|
+
// Modifier specified: must match exactly
|
|
43
|
+
return eventModifier === comboModifier;
|
|
44
|
+
}
|
|
45
|
+
|
|
35
46
|
/**
|
|
36
47
|
* Creates an event handler that will call the provided handler when any of the key combinations match
|
|
37
48
|
*/
|
|
@@ -14,6 +14,8 @@ export declare class KeyCombinationManager {
|
|
|
14
14
|
* Checks if the given keyboard event matches any of the provided key combinations
|
|
15
15
|
*/
|
|
16
16
|
match(event: KeyboardEvent, combos: KeyCombo[]): boolean;
|
|
17
|
+
private matchesCombo;
|
|
18
|
+
private matchesModifier;
|
|
17
19
|
/**
|
|
18
20
|
* Creates an event handler that will call the provided handler when any of the key combinations match
|
|
19
21
|
*/
|