Add hotkeys

This commit is contained in:
Kwaroran
2024-11-27 08:29:59 +09:00
parent e0de68cf9e
commit 096d2fe62c
5 changed files with 89 additions and 14 deletions

View File

@@ -165,7 +165,7 @@ export function alertMd(msg:string){
}
export function doingAlert(){
return get(alertStoreImported).type !== 'none' && get(alertStoreImported).type !== 'toast'
return get(alertStoreImported).type !== 'none' && get(alertStoreImported).type !== 'toast' && get(alertStoreImported).type !== 'wait'
}
export function alertToast(msg:string){

View File

@@ -1,13 +1,62 @@
import { get } from "svelte/store"
import { alertSelect, alertToast, doingAlert } from "./alert"
import { changeToPreset as changeToPreset2, getDatabase } from "./storage/database.svelte"
import { MobileGUIStack, MobileSideBar, openPersonaList, openPresetList, SafeModeStore, selectedCharID, settingsOpen } from "./stores.svelte"
import { alertStore, MobileGUIStack, MobileSideBar, openPersonaList, openPresetList, SafeModeStore, selectedCharID, settingsOpen } from "./stores.svelte"
import { language } from "src/lang"
import { updateTextThemeAndCSS } from "./gui/colorscheme"
export function initHotkey(){
document.addEventListener('keydown', (ev) => {
if(ev.ctrlKey){
if(ev.altKey){
switch(ev.key){
case "r":{
ev.preventDefault()
clickQuery('.button-icon-reroll')
return
}
case "f":{
ev.preventDefault()
clickQuery('.button-icon-unreroll')
return
}
case "t":{
ev.preventDefault()
clickQuery('.button-icon-translate')
return
}
case "r":{
ev.preventDefault()
clickQuery('.button-icon-remove')
return
}
case 'e':{
ev.preventDefault()
clickQuery('.button-icon-edit')
setTimeout(() => {
focusQuery('.message-edit-area')
}, 100)
return
}
case 'c':{
ev.preventDefault()
clickQuery('.button-icon-copy')
return
}
case 'i':{
ev.preventDefault()
focusQuery('.text-input-area')
return
}
case 'Enter':{
ev.preventDefault()
clickQuery('.button-icon-send')
return
}
}
}
switch (ev.key){
case "1":{
changeToPreset(0)
@@ -105,6 +154,15 @@ export function initHotkey(){
}
ev.preventDefault()
}
if(ev.key === 'Enter'){
const alertType = get(alertStore).type
if(alertType === 'ask' || alertType === 'normal' || alertType === 'error'){
alertStore.set({
type: 'none',
msg: 'yes'
})
}
}
})
@@ -143,6 +201,23 @@ export function initHotkey(){
})
}
function clickQuery(query:string){
let ele = document.querySelector(query) as HTMLElement
console.log(ele)
if(ele){
ele.click()
}
}
function focusQuery(query:string){
let ele = document.querySelector(query) as HTMLElement
if(ele){
ele.focus()
}
}
export function initMobileGesture(){
let pressingPointers = new Map<number, {x:number, y:number}>()