Skip to content

Commit

Permalink
Add enable shortcut method
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Dec 22, 2023
1 parent 99d8f7e commit 4936b93
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/app/toolboxController.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,24 @@ export class ToolboxController {
for (const key in this.#toolList) {
this.#toolList[key].init();
}
// keydown listener
window.addEventListener('keydown',
this.#getCallback('window', 'keydown'), true);
// enable shortcuts
this.enableShortcuts(true);
}

/**
* Enable or disable shortcuts. The 'init' methods enables shortcuts
* by default. Call this method after init to disable shortcuts.
*
* @param {boolean} flag True to enable shortcuts.
*/
enableShortcuts(flag) {
if (flag) {
window.addEventListener('keydown',
this.#getCallback('window', 'keydown'), true);
} else {
window.removeEventListener('keydown',
this.#getCallback('window', 'keydown'), true);
}
}

/**
Expand Down

0 comments on commit 4936b93

Please sign in to comment.