refactor(shortcuts): replace eventToHotkeyString with eventToShortcutString

Migrate all imperative shortcut matching from @github/hotkey's
eventToHotkeyString to the new event.code-based eventToShortcutString.

Updated comparison strings:
- 'Meta+k'/'Control+k' -> 'Meta+KeyK'/'Control+KeyK'
- 'Control+s'/'Meta+s' -> 'Control+KeyS'/'Meta+KeyS'
- 'Control+.' -> 'Control+Period'
- '.' -> 'Period'
- 'Enter' stays 'Enter' (identical in event.code)
This commit is contained in:
kolaente
2026-02-26 23:41:40 +01:00
parent f2901deb00
commit e3fdaed94a
4 changed files with 19 additions and 19 deletions

View File

@@ -144,7 +144,7 @@
<script setup lang="ts"> <script setup lang="ts">
import {computed, nextTick, onBeforeUnmount, onMounted, ref, watch, watchEffect} from 'vue' import {computed, nextTick, onBeforeUnmount, onMounted, ref, watch, watchEffect} from 'vue'
import {useI18n} from 'vue-i18n' import {useI18n} from 'vue-i18n'
import {eventToHotkeyString} from '@github/hotkey' import {eventToShortcutString} from '@/helpers/shortcut'
import EditorToolbar from './EditorToolbar.vue' import EditorToolbar from './EditorToolbar.vue'
@@ -780,9 +780,9 @@ function setFocusToEditor(event: KeyboardEvent) {
return return
} }
const hotkeyString = eventToHotkeyString(event) const shortcutString = eventToShortcutString(event)
if (!hotkeyString) return if (!shortcutString) return
if (hotkeyString !== props.editShortcut || if (shortcutString !== props.editShortcut ||
event.target.tagName.toLowerCase() === 'input' || event.target.tagName.toLowerCase() === 'input' ||
event.target.tagName.toLowerCase() === 'textarea' || event.target.tagName.toLowerCase() === 'textarea' ||
event.target.contentEditable === 'true') { event.target.contentEditable === 'true') {

View File

@@ -2,19 +2,19 @@
import BaseButton from '@/components/base/BaseButton.vue' import BaseButton from '@/components/base/BaseButton.vue'
import {useBaseStore} from '@/stores/base' import {useBaseStore} from '@/stores/base'
import {onBeforeUnmount, onMounted} from 'vue' import {onBeforeUnmount, onMounted} from 'vue'
import {eventToHotkeyString} from '@github/hotkey' import {eventToShortcutString} from '@/helpers/shortcut'
import {isAppleDevice} from '@/helpers/isAppleDevice' import {isAppleDevice} from '@/helpers/isAppleDevice'
const baseStore = useBaseStore() const baseStore = useBaseStore()
// See https://github.com/github/hotkey/discussions/85#discussioncomment-5214660 // See https://github.com/github/hotkey/discussions/85#discussioncomment-5214660
function openQuickActionsViaHotkey(event) { function openQuickActionsViaHotkey(event) {
const hotkeyString = eventToHotkeyString(event) const shortcutString = eventToShortcutString(event)
if (!hotkeyString) return if (!shortcutString) return
// On macOS, use Cmd+K (Meta+K), on other platforms use Ctrl+K (Control+K) // On macOS, use Cmd+K (Meta+K), on other platforms use Ctrl+K (Control+K)
const expectedHotkey = isAppleDevice() ? 'Meta+k' : 'Control+k' const expectedShortcut = isAppleDevice() ? 'Meta+KeyK' : 'Control+KeyK'
if (hotkeyString !== expectedHotkey) return if (shortcutString !== expectedShortcut) return
event.preventDefault() event.preventDefault()

View File

@@ -1,5 +1,5 @@
import {ref, onMounted, onBeforeUnmount} from 'vue' import {ref, onMounted, onBeforeUnmount} from 'vue'
import {eventToHotkeyString} from '@github/hotkey' import {eventToShortcutString} from '@/helpers/shortcut'
import {getTaskIdentifier} from '@/models/task' import {getTaskIdentifier} from '@/models/task'
import type {ITask} from '@/modelTypes/ITask' import type {ITask} from '@/modelTypes/ITask'
@@ -39,10 +39,10 @@ export function useTaskDetailShortcuts({
// See https://github.com/github/hotkey/discussions/85#discussioncomment-5214660 // See https://github.com/github/hotkey/discussions/85#discussioncomment-5214660
async function handleTaskHotkey(event: KeyboardEvent) { async function handleTaskHotkey(event: KeyboardEvent) {
const hotkeyString = eventToHotkeyString(event) const shortcutString = eventToShortcutString(event)
if (!hotkeyString) return if (!shortcutString) return
if (hotkeyString === 'Control+s' || hotkeyString === 'Meta+s') { if (shortcutString === 'Control+KeyS' || shortcutString === 'Meta+KeyS') {
event.preventDefault() event.preventDefault()
onSave() onSave()
return return
@@ -58,12 +58,12 @@ export function useTaskDetailShortcuts({
return return
} }
if (hotkeyString === 'Control+.') { if (shortcutString === 'Control+Period') {
await copySavely(window.location.href) await copySavely(window.location.href)
return return
} }
if (hotkeyString === '.') { if (shortcutString === 'Period') {
dotKeyPressedTimes.value++ dotKeyPressedTimes.value++
if (dotKeyPressedTimeout !== null) { if (dotKeyPressedTimeout !== null) {
clearTimeout(dotKeyPressedTimeout) clearTimeout(dotKeyPressedTimeout)

View File

@@ -1,7 +1,7 @@
import {createRandomID} from '@/helpers/randomId' import {createRandomID} from '@/helpers/randomId'
import {computePosition, flip, shift, offset} from '@floating-ui/dom' import {computePosition, flip, shift, offset} from '@floating-ui/dom'
import {nextTick} from 'vue' import {nextTick} from 'vue'
import {eventToHotkeyString} from '@github/hotkey' import {eventToShortcutString} from '@/helpers/shortcut'
export default function inputPrompt(pos: ClientRect, oldValue: string = ''): Promise<string> { export default function inputPrompt(pos: ClientRect, oldValue: string = ''): Promise<string> {
return new Promise((resolve) => { return new Promise((resolve) => {
@@ -90,8 +90,8 @@ export default function inputPrompt(pos: ClientRect, oldValue: string = ''): Pro
} }
document.getElementById(id)?.addEventListener('keydown', event => { document.getElementById(id)?.addEventListener('keydown', event => {
const hotkeyString = eventToHotkeyString(event) const shortcutString = eventToShortcutString(event)
if (hotkeyString !== 'Enter') { if (shortcutString !== 'Enter') {
return return
} }