Skip to content

Commit

Permalink
feat: added the ability to remember the last shortcut key
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangweb committed Mar 16, 2023
1 parent f69235e commit 6749213
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const useSettingsStore = defineStore(
const apiKey = ref('')

// 全局快捷键
const prevShortcutKeys = ref<string[]>([])
const shortcutKeys = ref<string[]>([])
const isBinding = ref(false)

Expand Down Expand Up @@ -56,17 +57,23 @@ export const useSettingsStore = defineStore(
uuid.value = crypto.randomUUID()
})

// 监听快捷键
// 监听快捷键更换
watchEffect(() => {
if (isBinding.value || shortcutKeys.value.length) return

shortcutKeys.value = prevShortcutKeys.value.length
? prevShortcutKeys.value
: DEFAULT_SHORTCUT_KEY
})

// 监听快捷键绑定状态
watchEffect(() => {
if (isBinding.value) {
prevShortcutKeys.value = shortcutKeys.value
shortcutKeys.value = []

unregisterAll()
} else {
if (!shortcutKeys.value.length) {
shortcutKeys.value = DEFAULT_SHORTCUT_KEY
}

registerKey()
}
})
Expand Down

0 comments on commit 6749213

Please sign in to comment.