diff --git a/src/components/floor-plan/CanvasFrame.jsx b/src/components/floor-plan/CanvasFrame.jsx index 7c9ece42..6a3a191c 100644 --- a/src/components/floor-plan/CanvasFrame.jsx +++ b/src/components/floor-plan/CanvasFrame.jsx @@ -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' diff --git a/src/hooks/common/useCommonUtils.js b/src/hooks/common/useCommonUtils.js index 84c4fdb0..b70ae0c8 100644 --- a/src/hooks/common/useCommonUtils.js +++ b/src/hooks/common/useCommonUtils.js @@ -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 = () => { diff --git a/src/hooks/useContextMenu.js b/src/hooks/useContextMenu.js index f43e9480..99fa585f 100644 --- a/src/hooks/useContextMenu.js +++ b/src/hooks/useContextMenu.js @@ -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)