From 09d1ab7191440aeebfcc35469e6365be09067a1e Mon Sep 17 00:00:00 2001 From: MissLixf <1090474924@qq.com> Date: Tue, 2 Jul 2024 15:26:32 +0800 Subject: [PATCH] fix(draw): fix resize geometry without text error #WIK-15876 --- packages/draw/src/plugins/with-draw-resize.ts | 16 ++++++++++++---- .../draw/src/plugins/with-geometry-resize.ts | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/draw/src/plugins/with-draw-resize.ts b/packages/draw/src/plugins/with-draw-resize.ts index 200d7c845..08c53b6d1 100644 --- a/packages/draw/src/plugins/with-draw-resize.ts +++ b/packages/draw/src/plugins/with-draw-resize.ts @@ -9,7 +9,8 @@ import { getSymmetricHandleIndex, isCornerHandle, withResize, - resetPointsAfterResize + resetPointsAfterResize, + normalizeShapePoints } from '@plait/common'; import { PlaitBoard, @@ -28,12 +29,14 @@ import { isAxisChangedByAngle, drawRectangle, ACTIVE_STROKE_WIDTH, - SELECTION_BORDER_COLOR + SELECTION_BORDER_COLOR, + Path } from '@plait/core'; import { PlaitDrawElement } from '../interfaces'; import { DrawTransforms } from '../transforms'; import { getHitRectangleResizeHandleRef } from '../utils/position/geometry'; import { getSnapResizingRefOptions, getSnapResizingRef } from '../utils/snap-resizing'; +import { isGeometryIncludeText } from '../utils'; const debugKey = 'debug:plait:resize-for-rotation'; const debugGenerator = createDebugGenerator(debugKey); @@ -176,8 +179,13 @@ export function withDrawResize(board: PlaitBoard) { } if (PlaitDrawElement.isGeometry(target)) { - const textHeight = getFirstTextManage(target)?.getSize()?.height || 0; - DrawTransforms.resizeGeometry(board, points as [Point, Point], textHeight, path); + if (isGeometryIncludeText(target)) { + const { height: textHeight } = getFirstTextManage(target).getSize(); + DrawTransforms.resizeGeometry(board, points as [Point, Point], textHeight, path); + } else { + points = normalizeShapePoints(points as [Point, Point]); + Transforms.setNode(board, { points }, path); + } } else if (PlaitDrawElement.isArrowLine(target)) { Transforms.setNode(board, { points }, path); } else if (PlaitDrawElement.isImage(target)) { diff --git a/packages/draw/src/plugins/with-geometry-resize.ts b/packages/draw/src/plugins/with-geometry-resize.ts index 096501810..f4cae11ab 100644 --- a/packages/draw/src/plugins/with-geometry-resize.ts +++ b/packages/draw/src/plugins/with-geometry-resize.ts @@ -72,7 +72,7 @@ export const withGeometryResize = (board: PlaitBoard) => { PlaitBoard.getElementActiveHost(board).append(snapG); let points = resizeSnapRef.activePoints as [Point, Point]; if (PlaitDrawElement.isGeometry(resizeRef.element) && isGeometryIncludeText(resizeRef.element)) { - const textHeight = getFirstTextManage(resizeRef.element)?.getSize()?.height || 0; + const { height: textHeight } = getFirstTextManage(resizeRef.element).getSize(); DrawTransforms.resizeGeometry(board, points, textHeight, resizeRef.path as Path); } else { points = normalizeShapePoints(points);