Add keyboard shortcut

Also fixes bug where pressing escape with another dialog open closes both at once
This commit is contained in:
Samuel Elliott 2018-01-20 16:15:55 +00:00
parent f9cd4e1a8a
commit f21aec5226
2 changed files with 25 additions and 7 deletions

View File

@ -10,17 +10,35 @@
const methods = { showSettings, hideSettings }; const methods = { showSettings, hideSettings };
let keydownEvent;
export default { export default {
components, components,
methods, methods,
data() { data() {
return { active: false } return {
active: false,
platform: global.process.platform
}
}, },
created: function() { created: function() {
window.addEventListener('keyup', e => { window.addEventListener('keydown', keydownEvent = e => {
if (e.which !== 27) return; if (this.active) {
if (e.which === 27)
this.hideSettings(); this.hideSettings();
} else {
if (global.process.platform == 'darwin' && e.metaKey && e.key == 'b')
this.showSettings();
else if (global.process.platform != 'darwin' && e.ctrlKey && e.key == 'b')
this.showSettings();
else return;
}
e.stopImmediatePropagation();
}); });
},
destroyed: function() {
window.removeEventListener('keydown', keydownEvent);
} }
} }
</script> </script>

View File

@ -1,4 +1,4 @@
<div class="bd-settings-wrapper" :class="{active: active}"> <div class="bd-settings-wrapper" :class="[{active: active}, 'platform-' + this.platform]">
<div class="bd-settings-button" :class="{active: active}" @click="showSettings"> <div class="bd-settings-button" :class="{active: active}" @click="showSettings">
<div class="bd-settings-button-btn"></div> <div class="bd-settings-button-btn"></div>
</div> </div>