提问优化

This commit is contained in:
IndieKKY
2024-05-27 09:42:04 +08:00
parent be97b1d51a
commit 64059f71e5
3 changed files with 51 additions and 6 deletions

View File

@@ -1,14 +1,39 @@
import {useEffect} from 'react'
import {useMemoizedFn} from 'ahooks/es'
import {useAppSelector} from './redux'
import {useAppDispatch, useAppSelector} from './redux'
import useSubtitle from './useSubtitle'
import {setInputting} from '../redux/envReducer'
const useKeyService = () => {
const dispatch = useAppDispatch()
const inputting = useAppSelector(state => state.env.inputting)
const curIdx = useAppSelector(state => state.env.curIdx)
const data = useAppSelector(state => state.env.data)
const {move} = useSubtitle()
// 输入中
useEffect(() => {
const onInputtingStart = (e: CompositionEvent) => {
dispatch(setInputting(true))
}
const onInputtingEnd = (e: CompositionEvent) => {
dispatch(setInputting(false))
}
document.addEventListener('compositionstart', onInputtingStart)
document.addEventListener('compositionend', onInputtingEnd)
return () => {
document.removeEventListener('compositionstart', onInputtingStart)
document.removeEventListener('compositionend', onInputtingEnd)
}
}, [dispatch])
const onKeyDown = useMemoizedFn((e: KeyboardEvent) => {
// 当前在输入中(如中文输入法)
if (inputting) {
return
}
// 有按其他控制键时,不触发
if (e.ctrlKey || e.metaKey || e.shiftKey) {
return