Fix leaks in keybind settings
This commit is contained in:
parent
da627f71e5
commit
df471161a7
|
@ -8,10 +8,12 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import Setting from './basesetting';
|
||||
import { IterableWeakSet } from 'common';
|
||||
import Combokeys from 'combokeys';
|
||||
import CombokeysGlobalBind from 'combokeys/plugins/global-bind';
|
||||
import Setting from './basesetting';
|
||||
|
||||
const instances = new IterableWeakSet();
|
||||
let keybindsPaused = false;
|
||||
|
||||
export default class KeybindSetting extends Setting {
|
||||
|
@ -19,9 +21,11 @@ export default class KeybindSetting extends Setting {
|
|||
constructor(args, ...merge) {
|
||||
super(args, ...merge);
|
||||
|
||||
instances.add(this);
|
||||
|
||||
this.__keybind_activated = this.__keybind_activated.bind(this);
|
||||
|
||||
this.combokeys = new Combokeys(document);
|
||||
this.combokeys = new Combokeys(this);
|
||||
CombokeysGlobalBind(this.combokeys);
|
||||
this.combokeys.bindGlobal(this.value, this.__keybind_activated);
|
||||
}
|
||||
|
@ -43,6 +47,22 @@ export default class KeybindSetting extends Setting {
|
|||
this.emit('keybind-activated', event);
|
||||
}
|
||||
|
||||
// Event function aliases for Combokeys
|
||||
get addEventListener() { return this.on }
|
||||
get removeEventListener() { return this.removeListener }
|
||||
|
||||
static _setup() {
|
||||
document.addEventListener('keydown', this.__event_handler.bind(this, 'keydown'));
|
||||
document.addEventListener('keyup', this.__event_handler.bind(this, 'keyup'));
|
||||
document.addEventListener('keypress', this.__event_handler.bind(this, 'keypress'));
|
||||
}
|
||||
|
||||
static __event_handler(event, data) {
|
||||
for (let keybindSetting of instances) {
|
||||
keybindSetting.emit(event, data);
|
||||
}
|
||||
}
|
||||
|
||||
static get paused() {
|
||||
return keybindsPaused;
|
||||
}
|
||||
|
@ -52,3 +72,5 @@ export default class KeybindSetting extends Setting {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
KeybindSetting._setup();
|
||||
|
|
Loading…
Reference in New Issue