feat: use command on mac and ctrl on other platforms

This commit is contained in:
kolaente 2021-11-03 20:10:23 +01:00
parent f3f3713bc1
commit a90b863590
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 15 additions and 1 deletions

View File

@ -1,15 +1,22 @@
<template>
<span class="shortcuts">
<template v-for="(k, i) in keys" :key="i">
<kbd>{{ k }}</kbd>
<kbd>{{ isMac ? k.replace('ctrl', '⌘') : k }}</kbd>
<span v-if="i < keys.length - 1">{{ combination }}</span>
</template>
</span>
</template>
<script>
import {isMac} from '@/helpers/isMac'
export default {
name: 'shortcut',
data() {
return {
isMac: isMac(),
}
},
props: {
keys: {
type: Array,

View File

@ -1,8 +1,12 @@
import {Directive} from 'vue'
import {install, uninstall} from '@github/hotkey'
import {isMac} from '@/helpers/isMac'
const directive: Directive = {
mounted(el, {value}) {
if (isMac() && value.includes('Control')) {
value = value.replace('Control', 'Meta')
}
install(el, value)
},
beforeUnmount(el) {

3
src/helpers/isMac.ts Normal file
View File

@ -0,0 +1,3 @@
export const isMac = (): Boolean => {
return navigator.userAgent.includes('Mac')
}