mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-03-09 07:13:35 -05:00
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:
@@ -144,7 +144,7 @@
|
||||
<script setup lang="ts">
|
||||
import {computed, nextTick, onBeforeUnmount, onMounted, ref, watch, watchEffect} from 'vue'
|
||||
import {useI18n} from 'vue-i18n'
|
||||
import {eventToHotkeyString} from '@github/hotkey'
|
||||
import {eventToShortcutString} from '@/helpers/shortcut'
|
||||
|
||||
import EditorToolbar from './EditorToolbar.vue'
|
||||
|
||||
@@ -780,9 +780,9 @@ function setFocusToEditor(event: KeyboardEvent) {
|
||||
return
|
||||
}
|
||||
|
||||
const hotkeyString = eventToHotkeyString(event)
|
||||
if (!hotkeyString) return
|
||||
if (hotkeyString !== props.editShortcut ||
|
||||
const shortcutString = eventToShortcutString(event)
|
||||
if (!shortcutString) return
|
||||
if (shortcutString !== props.editShortcut ||
|
||||
event.target.tagName.toLowerCase() === 'input' ||
|
||||
event.target.tagName.toLowerCase() === 'textarea' ||
|
||||
event.target.contentEditable === 'true') {
|
||||
|
||||
@@ -2,19 +2,19 @@
|
||||
import BaseButton from '@/components/base/BaseButton.vue'
|
||||
import {useBaseStore} from '@/stores/base'
|
||||
import {onBeforeUnmount, onMounted} from 'vue'
|
||||
import {eventToHotkeyString} from '@github/hotkey'
|
||||
import {eventToShortcutString} from '@/helpers/shortcut'
|
||||
import {isAppleDevice} from '@/helpers/isAppleDevice'
|
||||
|
||||
const baseStore = useBaseStore()
|
||||
|
||||
// See https://github.com/github/hotkey/discussions/85#discussioncomment-5214660
|
||||
function openQuickActionsViaHotkey(event) {
|
||||
const hotkeyString = eventToHotkeyString(event)
|
||||
if (!hotkeyString) return
|
||||
|
||||
const shortcutString = eventToShortcutString(event)
|
||||
if (!shortcutString) return
|
||||
|
||||
// On macOS, use Cmd+K (Meta+K), on other platforms use Ctrl+K (Control+K)
|
||||
const expectedHotkey = isAppleDevice() ? 'Meta+k' : 'Control+k'
|
||||
if (hotkeyString !== expectedHotkey) return
|
||||
const expectedShortcut = isAppleDevice() ? 'Meta+KeyK' : 'Control+KeyK'
|
||||
if (shortcutString !== expectedShortcut) return
|
||||
|
||||
event.preventDefault()
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {ref, onMounted, onBeforeUnmount} from 'vue'
|
||||
import {eventToHotkeyString} from '@github/hotkey'
|
||||
import {eventToShortcutString} from '@/helpers/shortcut'
|
||||
|
||||
import {getTaskIdentifier} from '@/models/task'
|
||||
import type {ITask} from '@/modelTypes/ITask'
|
||||
@@ -39,10 +39,10 @@ export function useTaskDetailShortcuts({
|
||||
|
||||
// See https://github.com/github/hotkey/discussions/85#discussioncomment-5214660
|
||||
async function handleTaskHotkey(event: KeyboardEvent) {
|
||||
const hotkeyString = eventToHotkeyString(event)
|
||||
if (!hotkeyString) return
|
||||
const shortcutString = eventToShortcutString(event)
|
||||
if (!shortcutString) return
|
||||
|
||||
if (hotkeyString === 'Control+s' || hotkeyString === 'Meta+s') {
|
||||
if (shortcutString === 'Control+KeyS' || shortcutString === 'Meta+KeyS') {
|
||||
event.preventDefault()
|
||||
onSave()
|
||||
return
|
||||
@@ -58,12 +58,12 @@ export function useTaskDetailShortcuts({
|
||||
return
|
||||
}
|
||||
|
||||
if (hotkeyString === 'Control+.') {
|
||||
if (shortcutString === 'Control+Period') {
|
||||
await copySavely(window.location.href)
|
||||
return
|
||||
}
|
||||
|
||||
if (hotkeyString === '.') {
|
||||
if (shortcutString === 'Period') {
|
||||
dotKeyPressedTimes.value++
|
||||
if (dotKeyPressedTimeout !== null) {
|
||||
clearTimeout(dotKeyPressedTimeout)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {createRandomID} from '@/helpers/randomId'
|
||||
import {computePosition, flip, shift, offset} from '@floating-ui/dom'
|
||||
import {nextTick} from 'vue'
|
||||
import {eventToHotkeyString} from '@github/hotkey'
|
||||
import {eventToShortcutString} from '@/helpers/shortcut'
|
||||
|
||||
export default function inputPrompt(pos: ClientRect, oldValue: string = ''): Promise<string> {
|
||||
return new Promise((resolve) => {
|
||||
@@ -90,8 +90,8 @@ export default function inputPrompt(pos: ClientRect, oldValue: string = ''): Pro
|
||||
}
|
||||
|
||||
document.getElementById(id)?.addEventListener('keydown', event => {
|
||||
const hotkeyString = eventToHotkeyString(event)
|
||||
if (hotkeyString !== 'Enter') {
|
||||
const shortcutString = eventToShortcutString(event)
|
||||
if (shortcutString !== 'Enter') {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user