diff --git a/src/lib/keyboard.ts b/src/lib/keyboard.ts index bf2df568..c14c1064 100644 --- a/src/lib/keyboard.ts +++ b/src/lib/keyboard.ts @@ -85,6 +85,9 @@ export default class KeyboardHandler { } } + /** + * Writes the map to `localStorage` + */ save = (): void => { window.localStorage.setItem("keyMap", JSON.stringify(this.keyMap)); }; @@ -96,9 +99,13 @@ export default class KeyboardHandler { window.localStorage.removeItem("keyMap"); }; - bindAll = (): void => { + /** + * Wrapper to bind every binding defined in `this.keyMap`, + * writing to `localStorage` if {@param save} + */ + bindAll = (save = false): void => { for (const [key, value] of Object.entries(this.keyMap)) { - this.bind(key, value); + this.bind(key, value, save); } this.updateState(); }; @@ -110,11 +117,16 @@ export default class KeyboardHandler { this.save(); }; - bind = (key: string, action: Action): void => { + /** + * Creates a keyboard.js binding from the key combination {@param key} to the action {@param action}, + * writing to `localStorage` if {@param save} + */ + bind = (key: string, action: Action, save = true): void => { this.keyMap[key] = action; keyboardJS.bind(key, () => this.doAction(this.keyMap[key])); this.updateState(); - this.save(); + + if (save) this.save(); }; reset = (): void => {