Merge pull request #24 from samuelthomas2774/master

Add keyboard shortcut
This commit is contained in:
Alexei Stukov 2018-01-20 19:35:01 +02:00 committed by GitHub
commit 1f46323dc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 8 deletions

View File

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

View File

@ -1,6 +1,6 @@
<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-btn"></div>
</div>
<BdSettings :active="active" :close="hideSettings"/>
</div>
</div>