Optimize hotkey registration (#1264)
This commit is contained in:
parent
14b4aee07d
commit
04d53e5642
@ -1880,9 +1880,7 @@ class Display extends EventDispatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_updateHotkeys(options) {
|
_updateHotkeys(options) {
|
||||||
const scope = this._pageType;
|
this._hotkeyHandler.setHotkeys(this._pageType, options.inputs.hotkeys);
|
||||||
this._hotkeyHandler.clearHotkeys(scope);
|
|
||||||
this._hotkeyHandler.registerHotkeys(scope, options.inputs.hotkeys);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async _closeTab() {
|
async _closeTab() {
|
||||||
|
@ -105,6 +105,23 @@ class HotkeyHandler extends EventDispatcher {
|
|||||||
this._updateHotkeyRegistrations();
|
this._updateHotkeyRegistrations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assigns a set of hotkeys for a given scope. This is an optimized shorthand for calling
|
||||||
|
* `clearHotkeys`, then calling `registerHotkeys`.
|
||||||
|
* @see registerHotkeys for argument information.
|
||||||
|
*/
|
||||||
|
setHotkeys(scope, hotkeys) {
|
||||||
|
let registrations = this._hotkeyRegistrations.get(scope);
|
||||||
|
if (typeof registrations === 'undefined') {
|
||||||
|
registrations = [];
|
||||||
|
this._hotkeyRegistrations.set(scope, registrations);
|
||||||
|
} else {
|
||||||
|
registrations.length = 0;
|
||||||
|
}
|
||||||
|
registrations.push(...hotkeys);
|
||||||
|
this._updateHotkeyRegistrations();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a single event listener to a specific event.
|
* Adds a single event listener to a specific event.
|
||||||
* @param eventName The string representing the event's name.
|
* @param eventName The string representing the event's name.
|
||||||
|
Loading…
Reference in New Issue
Block a user