From 32a78840a9683e7bdb2c7567f07d313c40ac9e6e Mon Sep 17 00:00:00 2001 From: Nevermore <15972699417@163.com> Date: Wed, 23 Oct 2024 09:17:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=85=83=E7=B4=A0=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=9D=90=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useHandleActive.ts | 56 +++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/src/hooks/useHandleActive.ts b/src/hooks/useHandleActive.ts index 626f98bf..6f46d82a 100644 --- a/src/hooks/useHandleActive.ts +++ b/src/hooks/useHandleActive.ts @@ -101,6 +101,7 @@ export default () => { break default: + // @ts-ignore value = activeObject[key] break } @@ -125,7 +126,10 @@ export default () => { const activeObject = canvas.activeObject.value as FabricObject & Textbox if (lockChange || !isDefined(activeObject)) return if (['width', 'height', 'left', 'top', 'angle'].includes(key)) { + const currentObject = activeObject + activeObject.canvas?.discardActiveObject() activeObject.set(key, Number(newValue)) + activeObject.canvas?.setActiveObject(currentObject) if (type === 'change' && activeObject.group?.updateLayout) { activeObject.group.updateLayout() } @@ -153,18 +157,48 @@ export default () => { canvas.requestRenderAll() } - return computed(() => ({ - disabled: !isDefined(canvas.activeObject.value), - modelValue: modelValue.value as T, - onSwipe: (value: T) => { - changeValue(value, 'swipe') - }, - onChange: (value: T) => { - changeValue(value, 'change') - if (!isDefined(canvas.activeObject)) return - canvas.fire('object:modified', { target: canvas.activeObject.value }) + // return computed(() => ({ + // disabled: !isDefined(canvas.activeObject.value), + // modelValue: modelValue.value as T, + // onSwipe: (value: T) => { + // changeValue(value, 'swipe') + // }, + // onChange: (value: T) => { + // changeValue(value, 'change') + // if (!isDefined(canvas.activeObject)) return + // canvas.fire('object:modified', { target: canvas.activeObject.value }) + // }, + // })) + return computed({ + get() { + return { + disabled: !isDefined(canvas.activeObject.value), + modelValue: modelValue.value as T, + onSwipe: (value: T) => { + changeValue(value, 'swipe') + }, + onChange: (value: T) => { + changeValue(value, 'change') + if (!isDefined(canvas.activeObject)) return + canvas.fire('object:modified', { target: canvas.activeObject.value }) + } + } }, - })) + set() { + return { + disabled: !isDefined(canvas.activeObject.value), + modelValue: modelValue.value as T, + onSwipe: (value: T) => { + changeValue(value, 'swipe') + }, + onChange: (value: T) => { + changeValue(value, 'change') + if (!isDefined(canvas.activeObject)) return + canvas.fire('object:modified', { target: canvas.activeObject.value }) + } + } + } + }) } return {