From cc91171bca778114f0d1659de8cad619cb478e82 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Wed, 27 Jan 2021 10:32:27 +0100 Subject: [PATCH] storm button hotkeys --- ui/storm/src/ctrl.ts | 9 +++++++++ ui/storm/src/view/main.ts | 8 +++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ui/storm/src/ctrl.ts b/ui/storm/src/ctrl.ts index 3626243a44..67a6acf6d4 100644 --- a/ui/storm/src/ctrl.ts +++ b/ui/storm/src/ctrl.ts @@ -41,12 +41,14 @@ export default class StormCtrl { }; this.promotion = makePromotion(this.withGround, this.makeCgOpts, redraw); this.checkDupTab(); + setTimeout(this.hotkeys, 1000); } clockMillis = (): number | undefined => this.vm.run.startAt && Math.max(0, this.vm.run.startAt + this.vm.clock - getNow()); end = (): void => { + if (!this.vm.puzzleStartAt) return; this.vm.history.reverse(); this.vm.run.endAt = getNow(); this.ground(false); @@ -244,4 +246,11 @@ export default class StormCtrl { } }); } + + private hotkeys = () => { + window.Mousetrap + .bind('space', () => location.reload()) + .bind('return', this.end); + } + } diff --git a/ui/storm/src/view/main.ts b/ui/storm/src/view/main.ts index d6aa31509d..a5dfbc1d46 100644 --- a/ui/storm/src/view/main.ts +++ b/ui/storm/src/view/main.ts @@ -49,17 +49,15 @@ const renderControls = (ctrl: StormCtrl): VNode => attrs: { href: '/storm', 'data-icon': 'B', - title: 'New run' + title: 'New run (hotkey: Space)' } }), h('a.storm__control__end.button.button-empty', { attrs: { 'data-icon': 'b', - title: 'End run', + title: 'End run (hotkey: Enter)', }, - hook: onInsert(el => el.addEventListener('click', () => { - if (ctrl.vm.puzzleStartAt) ctrl.end() - })) + hook: onInsert(el => el.addEventListener('click', ctrl.end)) }) ]);