fix: compatible with non-macOS when the shortcut key contains `metaKey`

This commit is contained in:
Lykin 2024-08-07 10:14:59 +08:00
parent a3cb09863a
commit 868b0c81b6
3 changed files with 9 additions and 5 deletions

View File

@ -125,9 +125,10 @@ onUnmounted(() => {
}) })
const onKeyShortcut = (e) => { const onKeyShortcut = (e) => {
const isCtrlOn = isMacOS() ? e.metaKey : e.ctrlKey
switch (e.key) { switch (e.key) {
case 'w': case 'w':
if (e.metaKey) { if (isCtrlOn) {
// close current tab // close current tab
const tabStore = useTabStore() const tabStore = useTabStore()
const currentTab = tabStore.currentTab const currentTab = tabStore.currentTab

View File

@ -16,6 +16,7 @@ import ContentToolbar from '@/components/content_value/ContentToolbar.vue'
import ContentValueJson from '@/components/content_value/ContentValueJson.vue' import ContentValueJson from '@/components/content_value/ContentValueJson.vue'
import usePreferencesStore from 'stores/preferences.js' import usePreferencesStore from 'stores/preferences.js'
import { TextAlignType } from '@/consts/text_align_type.js' import { TextAlignType } from '@/consts/text_align_type.js'
import { isMacOS } from '@/utils/platform.js'
const themeVars = useThemeVars() const themeVars = useThemeVars()
const browserStore = useBrowserStore() const browserStore = useBrowserStore()
@ -130,7 +131,7 @@ const onReload = async (selDecode, selFormat) => {
} }
const onKeyShortcut = (e) => { const onKeyShortcut = (e) => {
// console.log(e) const isCtrlOn = isMacOS() ? e.metaKey : e.ctrlKey
switch (e.key) { switch (e.key) {
case 'Delete': case 'Delete':
onDelete() onDelete()
@ -139,7 +140,7 @@ const onKeyShortcut = (e) => {
onReload() onReload()
return return
case 'r': case 'r':
if (e.metaKey) { if (isCtrlOn) {
onReload() onReload()
} }
return return

View File

@ -26,6 +26,7 @@ import usePreferencesStore from 'stores/preferences.js'
import { typesIconStyle } from '@/consts/support_redis_type.js' import { typesIconStyle } from '@/consts/support_redis_type.js'
import { nativeRedisKey } from '@/utils/key_convert.js' import { nativeRedisKey } from '@/utils/key_convert.js'
import copy from 'copy-text-to-clipboard' import copy from 'copy-text-to-clipboard'
import { isMacOS } from '@/utils/platform.js'
const props = defineProps({ const props = defineProps({
server: String, server: String,
@ -326,6 +327,7 @@ const handleKeyCopy = () => {
} }
const onKeyShortcut = (e) => { const onKeyShortcut = (e) => {
const isCtrlOn = isMacOS() ? e.metaKey : e.ctrlKey
switch (e.key) { switch (e.key) {
case 'ArrowUp': case 'ArrowUp':
handleKeyUp() handleKeyUp()
@ -340,7 +342,7 @@ const onKeyShortcut = (e) => {
handleKeyRight() handleKeyRight()
break break
case 'c': case 'c':
if (e.metaKey) { if (isCtrlOn) {
handleKeyCopy() handleKeyCopy()
} }
break break
@ -351,7 +353,7 @@ const onKeyShortcut = (e) => {
handleSelectContextMenu('value_reload') handleSelectContextMenu('value_reload')
break break
case 'r': case 'r':
if (e.metaKey) { if (isCtrlOn) {
handleSelectContextMenu('value_reload') handleSelectContextMenu('value_reload')
} }
break break