UNPKG

js-draw

Version:

Draw pictures using a pen, touchscreen, or mouse! JS-draw is a drawing library for JavaScript and TypeScript.

35 lines (34 loc) 1.25 kB
"use strict"; // Allows the toolbar to register keyboard events. // @packageDocumentation var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const BaseTool_1 = __importDefault(require("./BaseTool")); class ToolbarShortcutHandler extends BaseTool_1.default { constructor(editor) { super(editor.notifier, editor.localization.changeTool); this.listeners = new Set([]); } registerListener(listener) { this.listeners.add(listener); } removeListener(listener) { this.listeners.delete(listener); } onKeyPress(event) { // TypeScript seems to automatically convert for of loops into for(init;check;update) // loops (even with target set to es6). Thus, we cannot iterate directly through the // set here. // See https://stackoverflow.com/q/48886500 const listeners = Array.from(this.listeners.values()); for (const listener of listeners) { if (listener(event)) { return true; } } return false; } } exports.default = ToolbarShortcutHandler;