mirror of
https://github.com/pipipi-pikachu/PPTist.git
synced 2025-04-15 02:20:00 +08:00
refactor: 代码优化(#20)
This commit is contained in:
parent
65984c129a
commit
5150df46b1
@ -121,13 +121,14 @@ export default () => {
|
|||||||
|
|
||||||
const keydownListener = (e: KeyboardEvent) => {
|
const keydownListener = (e: KeyboardEvent) => {
|
||||||
const { ctrlKey, shiftKey, altKey, metaKey } = e
|
const { ctrlKey, shiftKey, altKey, metaKey } = e
|
||||||
|
const ctrlOrMetaKeyActive = ctrlKey || metaKey
|
||||||
|
|
||||||
const key = e.key.toUpperCase()
|
const key = e.key.toUpperCase()
|
||||||
|
|
||||||
if ((ctrlKey || metaKey) && !ctrlKeyActive.value) store.commit(MutationTypes.SET_CTRL_KEY_STATE, true)
|
if (ctrlOrMetaKeyActive && !ctrlKeyActive.value) store.commit(MutationTypes.SET_CTRL_KEY_STATE, true)
|
||||||
if (shiftKey && !shiftKeyActive.value) store.commit(MutationTypes.SET_SHIFT_KEY_STATE, true)
|
if (shiftKey && !shiftKeyActive.value) store.commit(MutationTypes.SET_SHIFT_KEY_STATE, true)
|
||||||
|
|
||||||
if ((ctrlKey || metaKey) && key === KEYS.F) {
|
if (ctrlOrMetaKeyActive && key === KEYS.F) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
enterScreening()
|
enterScreening()
|
||||||
store.commit(MutationTypes.SET_CTRL_KEY_STATE, false)
|
store.commit(MutationTypes.SET_CTRL_KEY_STATE, false)
|
||||||
@ -135,47 +136,47 @@ export default () => {
|
|||||||
|
|
||||||
if (!editorAreaFocus.value && !thumbnailsFocus.value) return
|
if (!editorAreaFocus.value && !thumbnailsFocus.value) return
|
||||||
|
|
||||||
if ((ctrlKey || metaKey) && key === KEYS.C) {
|
if (ctrlOrMetaKeyActive && key === KEYS.C) {
|
||||||
if (disableHotkeys.value) return
|
if (disableHotkeys.value) return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
copy()
|
copy()
|
||||||
}
|
}
|
||||||
if ((ctrlKey || metaKey) && key === KEYS.X) {
|
if (ctrlOrMetaKeyActive && key === KEYS.X) {
|
||||||
if (disableHotkeys.value) return
|
if (disableHotkeys.value) return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
cut()
|
cut()
|
||||||
}
|
}
|
||||||
if ((ctrlKey || metaKey) && key === KEYS.D) {
|
if (ctrlOrMetaKeyActive && key === KEYS.D) {
|
||||||
if (disableHotkeys.value) return
|
if (disableHotkeys.value) return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
quickCopy()
|
quickCopy()
|
||||||
}
|
}
|
||||||
if ((ctrlKey || metaKey) && key === KEYS.Z) {
|
if (ctrlOrMetaKeyActive && key === KEYS.Z) {
|
||||||
if (disableHotkeys.value) return
|
if (disableHotkeys.value) return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
undo()
|
undo()
|
||||||
}
|
}
|
||||||
if ((ctrlKey || metaKey) && key === KEYS.Y) {
|
if (ctrlOrMetaKeyActive && key === KEYS.Y) {
|
||||||
if (disableHotkeys.value) return
|
if (disableHotkeys.value) return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
redo()
|
redo()
|
||||||
}
|
}
|
||||||
if ((ctrlKey || metaKey) && key === KEYS.A) {
|
if (ctrlOrMetaKeyActive && key === KEYS.A) {
|
||||||
if (disableHotkeys.value) return
|
if (disableHotkeys.value) return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
selectAll()
|
selectAll()
|
||||||
}
|
}
|
||||||
if ((ctrlKey || metaKey) && key === KEYS.L) {
|
if (ctrlOrMetaKeyActive && key === KEYS.L) {
|
||||||
if (disableHotkeys.value) return
|
if (disableHotkeys.value) return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
lock()
|
lock()
|
||||||
}
|
}
|
||||||
if (!shiftKey && (ctrlKey || metaKey) && key === KEYS.G) {
|
if (!shiftKey && ctrlOrMetaKeyActive && key === KEYS.G) {
|
||||||
if (disableHotkeys.value) return
|
if (disableHotkeys.value) return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
combine()
|
combine()
|
||||||
}
|
}
|
||||||
if (shiftKey && (ctrlKey || metaKey) && key === KEYS.G) {
|
if (shiftKey && ctrlOrMetaKeyActive && key === KEYS.G) {
|
||||||
if (disableHotkeys.value) return
|
if (disableHotkeys.value) return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
uncombine()
|
uncombine()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user