aboutsummaryrefslogtreecommitdiff
path: root/internal/ui/static/js/keyboard_handler.js
diff options
context:
space:
mode:
authorGravatar jvoisin <julien.voisin@dustri.org> 2024-03-10 23:55:56 +0100
committerGravatar Frédéric Guillot <f@miniflux.net> 2024-03-10 19:41:13 -0700
commitd9d17f0d69d1dafb3bd9d81bf9fc27df3def4f4c (patch)
tree23c851789bb76460868d73e32e5c84af05ae6c22 /internal/ui/static/js/keyboard_handler.js
parenteaaeb68474ff194f682e9521a848d7ab2c89348e (diff)
downloadv2-d9d17f0d69d1dafb3bd9d81bf9fc27df3def4f4c.tar.gz
v2-d9d17f0d69d1dafb3bd9d81bf9fc27df3def4f4c.tar.zst
v2-d9d17f0d69d1dafb3bd9d81bf9fc27df3def4f4c.zip
Use a `Set` instead of an array in a KeyboardHandler's member
The variable `triggers` is only used to check if in contains a particular value. Given that the number of keyboard shortcuts is starting to be significant, let's future-proof the performances and use a `Set` instead of an `Array` instead.
Diffstat (limited to 'internal/ui/static/js/keyboard_handler.js')
-rw-r--r--internal/ui/static/js/keyboard_handler.js6
1 files changed, 3 insertions, 3 deletions
diff --git a/internal/ui/static/js/keyboard_handler.js b/internal/ui/static/js/keyboard_handler.js
index 55b72964..863309d9 100644
--- a/internal/ui/static/js/keyboard_handler.js
+++ b/internal/ui/static/js/keyboard_handler.js
@@ -2,12 +2,12 @@ class KeyboardHandler {
constructor() {
this.queue = [];
this.shortcuts = {};
- this.triggers = [];
+ this.triggers = new Set();
}
on(combination, callback) {
this.shortcuts[combination] = callback;
- this.triggers.push(combination.split(" ")[0]);
+ this.triggers.add(combination.split(" ")[0]);
}
listen() {
@@ -48,7 +48,7 @@ class KeyboardHandler {
isEventIgnored(event, key) {
return event.target.tagName === "INPUT" ||
event.target.tagName === "TEXTAREA" ||
- (this.queue.length < 1 && !this.triggers.includes(key));
+ (this.queue.length < 1 && !this.triggers.has(key));
}
isModifierKeyDown(event) {