1 import {Component} from "./component";
4 * Keys to ignore when recording shortcuts.
7 const ignoreKeys = ['Control', 'Alt', 'Shift', 'Meta', 'Super', ' ', '+', 'Tab', 'Escape'];
9 export class ShortcutInput extends Component {
12 this.input = this.$el;
14 this.setupListeners();
18 this.listenerRecordKey = this.listenerRecordKey.bind(this);
20 this.input.addEventListener('focus', () => {
21 this.startListeningForInput();
24 this.input.addEventListener('blur', () => {
25 this.stopListeningForInput();
29 startListeningForInput() {
30 this.input.addEventListener('keydown', this.listenerRecordKey)
34 * @param {KeyboardEvent} event
36 listenerRecordKey(event) {
37 if (ignoreKeys.includes(event.key)) {
42 event.ctrlKey ? 'Ctrl' : '',
43 event.metaKey ? 'Cmd' : '',
47 this.input.value = keys.filter(s => Boolean(s)).join(' + ');
50 stopListeningForInput() {
51 this.input.removeEventListener('keydown', this.listenerRecordKey);