feat: 新增剪切

This commit is contained in:
MTrun
2022-02-04 12:17:50 +08:00
parent ad8cc8a003
commit 71e13c83e6
11 changed files with 224 additions and 45 deletions
@@ -1,26 +1,49 @@
import { isMac, addEventListener, removeEventListener } from '@/utils'
import { getChartEditStore } from './useStore.hook'
import { MenuEnum } from '@/views/chart/hooks/useContextMenu.hook'
const chartEditStore = getChartEditStore()
export const keyboardValue = {
[MenuEnum.COPY]: 'c',
[MenuEnum.CUT]: 'x',
[MenuEnum.PARSE]: 'v',
[MenuEnum.DELETE]: 'delete',
back: 'z',
}
const KeyboardHandle = (e: KeyboardEvent) => {
const ismacRes = isMac()
// 暂不支持mac,因为我没有😤👻
if(ismacRes) return
if (ismacRes) return
const key = e.key.toLowerCase()
if (key === 'delete') {
// 删除
if (key === keyboardValue.delete) {
chartEditStore.removeComponentList()
return
}
// 前进
if (e.ctrlKey && e.shiftKey && key == keyboardValue.back) {
chartEditStore.setForward()
return
}
if (e.ctrlKey) {
switch (key) {
// 复制
case 'c': chartEditStore.setCopy()
case keyboardValue.copy: chartEditStore.setCopy()
break;
// 剪切
case keyboardValue.cut: chartEditStore.setCut()
break;
// 粘贴
case 'v': chartEditStore.setParse()
case keyboardValue.parse: chartEditStore.setParse()
break;
// 撤回
case keyboardValue.back: chartEditStore.setBack()
break;
}
e.preventDefault()