key event 함수추가

This commit is contained in:
yjnoh 2024-10-31 09:19:18 +09:00
parent 5510878cc2
commit fd7d6ad63b
3 changed files with 26 additions and 24 deletions

View File

@ -12,8 +12,6 @@ import { currentMenuState, currentObjectState, modifiedPlanFlagState } from '@/s
import { useCanvasEvent } from '@/hooks/useCanvasEvent'
import QContextMenu from '@/components/common/context-menu/QContextMenu'
import { useCanvasConfigInitialize } from '@/hooks/common/useCanvasConfigInitialize'
import { useCommonUtils } from '@/hooks/common/useCommonUtils'
import { MENU } from '@/common/common'
import PanelBatchStatistics from '@/components/floor-plan/modal/panelBatch/PanelBatchStatistics'

View File

@ -37,6 +37,7 @@ export function useCommonUtils() {
const commonTextMode = () => {
let textbox
if (commonUtils.text) {
commonTextKeyEvent()
addCanvasMouseEventListener('mouse:down', (event) => {
const pointer = canvas?.getPointer(event.e)
textbox = new fabric.Textbox('', {
@ -472,30 +473,32 @@ export function useCommonUtils() {
}
}
//텍스트 모드일때 엔터 이벤트
addDocumentEventListener('keydown', document, (e) => {
if (e.key === 'Enter') {
const activeObject = canvas.getActiveObject()
if (activeObject && activeObject.name === 'commonText') {
if (activeObject && activeObject.isEditing) {
if (activeObject.text === '') {
canvas?.remove(activeObject)
} else {
activeObject.exitEditing()
}
//정책 협의
const texts = canvas.getObjects().filter((obj) => obj.name === 'commonText')
texts.forEach((text) => {
text.set({ editable: false })
})
const commonTextKeyEvent = () => {
//텍스트 모드일때 엔터 이벤트
addDocumentEventListener('keydown', document, (e) => {
if (e.key === 'Enter') {
const activeObject = canvas.getActiveObject()
if (activeObject && activeObject.name === 'commonText') {
if (activeObject && activeObject.isEditing) {
if (activeObject.text === '') {
canvas?.remove(activeObject)
} else {
activeObject.exitEditing()
}
//정책 협의
const texts = canvas.getObjects().filter((obj) => obj.name === 'commonText')
texts.forEach((text) => {
text.set({ editable: false })
})
canvas.renderAll()
if (setCommonUtilsState) setCommonUtilsState({ ...commonUtils, text: false })
canvas.renderAll()
if (setCommonUtilsState) setCommonUtilsState({ ...commonUtils, text: false })
}
}
initEvent()
}
initEvent()
}
})
})
}
const commonFunctions = (mode) => {
let tempStates = { ...commonUtils }
@ -591,6 +594,7 @@ export function useCommonUtils() {
const obj = canvas?.getActiveObject()
obj.set({ editable: true })
obj.enterEditing()
commonTextKeyEvent()
}
const deleteObject = () => {

View File

@ -43,7 +43,7 @@ export function useContextMenu() {
const { addPopup } = usePopup()
const [popupId, setPopupId] = useState(uuidv4())
const [gridColor, setGridColor] = useRecoilState(gridColorState)
const { deleteObject, moveObject, copyObject, editText, changeDimensionExtendLine } = useCommonUtils({})
const { deleteObject, moveObject, copyObject, editText, changeDimensionExtendLine } = useCommonUtils()
const [qContextMenu, setQContextMenu] = useRecoilState(contextMenuState)
const [cell, setCell] = useState(null)
const [column, setColumn] = useState(null)