Files
Hermes-ui/packages/client/src/composables/useKeyboard.ts
T

40 lines
981 B
TypeScript
Raw Normal View History

2026-04-11 15:59:14 +08:00
import { onMounted, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'
import { useChatStore } from '@/stores/hermes/chat'
2026-04-11 15:59:14 +08:00
export function useKeyboard() {
const router = useRouter()
const chatStore = useChatStore()
function handleKeydown(e: KeyboardEvent) {
const mod = e.ctrlKey || e.metaKey
if (mod && e.key === 'n') {
e.preventDefault()
chatStore.newChat()
}
if (mod && e.key === 'j') {
e.preventDefault()
router.push({ name: 'hermes.jobs' })
2026-04-11 15:59:14 +08:00
}
if (e.key === 'Escape') {
// Close any open modals — naive-ui handles this internally
const modal = document.querySelector('.n-modal-mask')
if (modal) {
const closeBtn = modal.querySelector('.n-base-close') as HTMLElement
closeBtn?.click()
}
}
}
onMounted(() => {
window.addEventListener('keydown', handleKeydown)
})
onUnmounted(() => {
window.removeEventListener('keydown', handleKeydown)
})
}